Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring existing unit tests #7687

Merged
merged 12 commits into from
May 6, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,13 @@ public void setUp() {
formatter = new CapitalizeFormatter();
}

@Test
public void test() {
assertEquals("Upper Each First", formatter.format("upper each First"));
assertEquals("Upper Each First {NOT} {this}", formatter.format("upper each first {NOT} {this}"));
assertEquals("Upper Each First {N}ot {t}his", formatter.format("upper each first {N}OT {t}his"));
}

@Test
public void formatExample() {
assertEquals("I Have {a} Dream", formatter.format(formatter.getExampleInput()));
}

@ParameterizedTest(name = "input={0}, formattedStr={1}")
@CsvSource({
@CsvSource(value = {
"{}, {}", // {}
"{upper, {upper", // unmatched braces
"upper, Upper", // single word lower case
Expand All @@ -41,13 +34,15 @@ public void formatExample() {
"upper each first, Upper Each First", // multiple words lower case
"Upper Each First, Upper Each First", // multiple words correct
"UPPER EACH FIRST, Upper Each First", // multiple words upper case
"upper each First, Upper Each First", // multiple words in lower and upper case
"{u}pp{e}r, {u}pp{e}r", // single word lower case with {}
"{U}pp{e}r, {U}pp{e}r", // single word correct with {}
"{U}PP{E}R, {U}pp{E}r", // single word upper case with {}
"upper each {NOT} first, Upper Each {NOT} First", // multiple words lower case with {}
"Upper {E}ach {NOT} First, Upper {E}ach {NOT} First", // multiple words correct with {}
"UPPER {E}ACH {NOT} FIRST, Upper {E}ach {NOT} First", // multiple words upper case with {}

"upper each first {NOT} {this}, Upper Each First {NOT} {this}", // multiple words in lower and upper case with {}
"upper each first {N}OT {t}his, Upper Each First {N}ot {t}his", // multiple words in lower and upper case with {} part 2
})
public void testInputs(String input, String expectedResult) {
String formattedStr = formatter.format(input);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.jabref.logic.formatter.minifier;

import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -17,21 +21,20 @@ public void setUp() {
formatter = new MinifyNameListFormatter();
}

@Test
public void minifyAuthorNames() {
expectCorrect("Simon Harrer", "Simon Harrer");
expectCorrect("Simon Harrer and others", "Simon Harrer and others");
expectCorrect("Simon Harrer and Jörg Lenhard", "Simon Harrer and Jörg Lenhard");
expectCorrect("Simon Harrer and Jörg Lenhard and Guido Wirtz", "Simon Harrer and others");
expectCorrect("Simon Harrer and Jörg Lenhard and Guido Wirtz and others", "Simon Harrer and others");
}

@Test
public void formatExample() {
expectCorrect(formatter.getExampleInput(), "Stefan Kolb and others");
@ParameterizedTest
@MethodSource("provideAuthorNames")
void minifyAuthorNames(String expectedAuthorNames, String originalAuthorNames) {
assertEquals(expectedAuthorNames, formatter.format(originalAuthorNames));
}

private void expectCorrect(String input, String expected) {
assertEquals(expected, formatter.format(input));
private static Stream<Arguments> provideAuthorNames() {
return Stream.of(
Arguments.of("Simon Harrer", "Simon Harrer"),
Arguments.of("Simon Harrer and others", "Simon Harrer and others"),
Arguments.of("Simon Harrer and Jörg Lenhard", "Simon Harrer and Jörg Lenhard"),
Arguments.of("Simon Harrer and others", "Simon Harrer and Jörg Lenhard and Guido Wirtz"),
Arguments.of("Simon Harrer and others", "Simon Harrer and Jörg Lenhard and Guido Wirtz and others"),
Arguments.of("Stefan Kolb and others", new MinifyNameListFormatter().getExampleInput())
);
}
}
113 changes: 46 additions & 67 deletions src/test/java/org/jabref/logic/layout/format/AuthorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,151 +10,134 @@

public class AuthorsTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please convert the whole class to paramterized tests


private ParamLayoutFormatter authorsLayoutFormatter = new Authors();

@Test
public void testStandardUsage() {
ParamLayoutFormatter a = new Authors();
assertEquals("B. C. Bruce, C. Manson and J. Jumper",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
}

@Test
public void testStandardUsageOne() {
ParamLayoutFormatter a = new Authors();
a.setArgument("fullname, LastFirst, Comma, Comma");
assertEquals("Bruce, Bob Croydon, Jumper, Jolly", a.format("Bob Croydon Bruce and Jolly Jumper"));
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, Comma");
assertEquals("Bruce, Bob Croydon, Jumper, Jolly", authorsLayoutFormatter.format("Bob Croydon Bruce and Jolly Jumper"));
}

@Test
public void testStandardUsageTwo() {
ParamLayoutFormatter a = new Authors();
a.setArgument("initials");
assertEquals("B. C. Bruce and J. Jumper", a.format("Bob Croydon Bruce and Jolly Jumper"));
authorsLayoutFormatter.setArgument("initials");
assertEquals("B. C. Bruce and J. Jumper", authorsLayoutFormatter.format("Bob Croydon Bruce and Jolly Jumper"));
}

@Test
public void testStandardUsageThree() {
ParamLayoutFormatter a = new Authors();
a.setArgument("fullname, LastFirst, Comma");
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma");
assertEquals("Bruce, Bob Croydon, Manson, Charles and Jumper, Jolly",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
}

@Test
public void testStandardUsageFour() {
ParamLayoutFormatter a = new Authors();
a.setArgument("fullname, LastFirst, Comma, 2");
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 2");
assertEquals("Bruce, Bob Croydon et al.",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
}

@Test
public void testStandardUsageFive() {
ParamLayoutFormatter a = new Authors();
a.setArgument("fullname, LastFirst, Comma, 3");
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3");
assertEquals("Bruce, Bob Croydon et al.",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
}

@Test
public void testStandardUsageSix() {
ParamLayoutFormatter a = new Authors();
a.setArgument("fullname, LastFirst, Comma, 3, 2");
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3, 2");
assertEquals("Bruce, Bob Croydon, Manson, Charles et al.",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
}

@Test
public void testSpecialEtAl() {
ParamLayoutFormatter a = new Authors();
a.setArgument("fullname, LastFirst, Comma, 3, etal= and a few more");
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3, etal= and a few more");
assertEquals("Bruce, Bob Croydon and a few more",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
}

@Test
public void testStandardUsageNull() {
ParamLayoutFormatter a = new Authors();
assertEquals("", a.format(null));
assertEquals("", authorsLayoutFormatter.format(null));
}

@Test
public void testStandardOxford() {
ParamLayoutFormatter a = new Authors();
a.setArgument("Oxford");
authorsLayoutFormatter.setArgument("Oxford");
assertEquals("B. C. Bruce, C. Manson, and J. Jumper",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper"));
}

@Test
public void testStandardOxfordFullName() {
ParamLayoutFormatter a = new Authors();
a.setArgument("FullName,Oxford");
authorsLayoutFormatter.setArgument("FullName,Oxford");
assertEquals("Bob Croydon Bruce, Charles Manson, and Jolly Jumper",
a.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
}

@Test
public void testStandardCommaFullName() {
ParamLayoutFormatter a = new Authors();
a.setArgument("FullName,Comma,Comma");
authorsLayoutFormatter.setArgument("FullName,Comma,Comma");
assertEquals("Bob Croydon Bruce, Charles Manson, Jolly Jumper",
a.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
}

@Test
public void testStandardAmpFullName() {
ParamLayoutFormatter a = new Authors();
a.setArgument("FullName,Amp");
authorsLayoutFormatter.setArgument("FullName,Amp");
assertEquals("Bob Croydon Bruce, Charles Manson & Jolly Jumper",
a.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Manson and Jolly Jumper"));
}

@Test
public void testLastName() {
ParamLayoutFormatter a = new Authors();
a.setArgument("LastName");
authorsLayoutFormatter.setArgument("LastName");
assertEquals("Bruce, von Manson and Jumper",
a.format("Bruce, Bob Croydon and Charles von Manson and Jolly Jumper"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles von Manson and Jolly Jumper"));
}

@Test
public void testMiddleInitial() {
ParamLayoutFormatter a = new Authors();
a.setArgument("MiddleInitial");
authorsLayoutFormatter.setArgument("MiddleInitial");
assertEquals("Bob C. Bruce, Charles K. von Manson and Jolly Jumper",
a.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
}

@Test
public void testNoPeriod() {
ParamLayoutFormatter a = new Authors();
a.setArgument("NoPeriod");
authorsLayoutFormatter.setArgument("NoPeriod");
assertEquals("B C Bruce, C K von Manson and J Jumper",
a.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
}

@Test
public void testEtAl() {
ParamLayoutFormatter a = new Authors();
a.setArgument("2,1");
authorsLayoutFormatter.setArgument("2,1");
assertEquals("B. C. Bruce et al.",
a.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson and Jumper, Jolly"));
}

@Test
public void testEtAlNotEnoughAuthors() {
ParamLayoutFormatter a = new Authors();
a.setArgument("2,1");
authorsLayoutFormatter.setArgument("2,1");
assertEquals("B. C. Bruce and C. K. von Manson",
a.format("Bruce, Bob Croydon and Charles Kermit von Manson"));
authorsLayoutFormatter.format("Bruce, Bob Croydon and Charles Kermit von Manson"));
}

@Test
public void testEmptyEtAl() {
ParamLayoutFormatter a = new Authors();
a.setArgument("fullname, LastFirst, Comma, 3, etal=");
authorsLayoutFormatter.setArgument("fullname, LastFirst, Comma, 3, etal=");
assertEquals("Bruce, Bob Croydon",
a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles"));
}

@ParameterizedTest(name = "arg={0}, formattedStr={1}")
Expand All @@ -164,9 +147,8 @@ public void testEmptyEtAl() {
"LastFirstFirstFirst, 'Bruce, B. C., C. Manson, J. Jumper and C. Chuckles'" // LastFirstFirstFirst
})
public void testAuthorOrder(String arg, String expectedResult) {
ParamLayoutFormatter a = new Authors();
a.setArgument(arg);
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
authorsLayoutFormatter.setArgument(arg);
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
assertEquals(expectedResult, formattedStr);
}

Expand All @@ -180,9 +162,8 @@ public void testAuthorOrder(String arg, String expectedResult) {
"InitialsNoSpace, 'B.C. Bruce, C. Manson, J. Jumper and C. Chuckles'" // InitialsNoSpace
})
public void testAuthorABRV(String arg, String expectedResult) {
ParamLayoutFormatter a = new Authors();
a.setArgument(arg);
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
authorsLayoutFormatter.setArgument(arg);
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
assertEquals(expectedResult, formattedStr);
}

Expand All @@ -194,9 +175,8 @@ public void testAuthorABRV(String arg, String expectedResult) {
"NoPeriod, 'B C Bruce, C Manson, J Jumper and C Chuckles'" // NoPeriod
})
public void testAuthorPUNC(String arg, String expectedResult) {
ParamLayoutFormatter a = new Authors();
a.setArgument(arg);
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
authorsLayoutFormatter.setArgument(arg);
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
assertEquals(expectedResult, formattedStr);
}

Expand All @@ -217,9 +197,8 @@ public void testAuthorPUNC(String arg, String expectedResult) {
"'Comma, Semicolon', 'B. C. Bruce, C. Manson, J. Jumper; C. Chuckles'", // Comma Semicolon
})
public void testAuthorSEPARATORS(String arg, String expectedResult) {
ParamLayoutFormatter a = new Authors();
a.setArgument(arg);
String formattedStr = a.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
authorsLayoutFormatter.setArgument(arg);
String formattedStr = authorsLayoutFormatter.format("Bob Croydon Bruce and Charles Manson and Jolly Jumper and Chuck Chuckles");
assertEquals(expectedResult, formattedStr);
}
}
50 changes: 25 additions & 25 deletions src/test/java/org/jabref/logic/layout/format/DOICheckTest.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package org.jabref.logic.layout.format;

import java.util.stream.Stream;

import org.jabref.logic.layout.LayoutFormatter;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DOICheckTest {

@Test
public void testFormat() {
LayoutFormatter lf = new DOICheck();

assertEquals("", lf.format(""));
assertEquals(null, lf.format(null));

assertEquals("https://doi.org/10.1000/ISBN1-900512-44-0", lf.format("10.1000/ISBN1-900512-44-0"));
assertEquals("https://doi.org/10.1000/ISBN1-900512-44-0",
lf.format("http://dx.doi.org/10.1000/ISBN1-900512-44-0"));

assertEquals("https://doi.org/10.1000/ISBN1-900512-44-0",
lf.format("http://doi.acm.org/10.1000/ISBN1-900512-44-0"));
private LayoutFormatter layoutFormatter = new DOICheck();

assertEquals("https://doi.org/10.1145/354401.354407",
lf.format("http://doi.acm.org/10.1145/354401.354407"));
assertEquals("https://doi.org/10.1145/354401.354407", lf.format("10.1145/354401.354407"));

// Works even when having a / at the front
assertEquals("https://doi.org/10.1145/354401.354407", lf.format("/10.1145/354401.354407"));

// Obviously a wrong doi, will not change anything.
assertEquals("10", lf.format("10"));
@ParameterizedTest
@MethodSource("provideDOI")
void formatDOI(String formattedDOI, String originalDOI) {
assertEquals(formattedDOI, layoutFormatter.format(originalDOI));
}

// Obviously a wrong doi, will not change anything.
assertEquals("1", lf.format("1"));
private static Stream<Arguments> provideDOI() {
return Stream.of(
Arguments.of("", ""),
Arguments.of(null, null),
Arguments.of("https://doi.org/10.1000/ISBN1-900512-44-0", "10.1000/ISBN1-900512-44-0"),
Arguments.of("https://doi.org/10.1000/ISBN1-900512-44-0", "http://dx.doi.org/10.1000/ISBN1-900512-44-0"),
Arguments.of("https://doi.org/10.1000/ISBN1-900512-44-0", "http://doi.acm.org/10.1000/ISBN1-900512-44-0"),
Arguments.of("https://doi.org/10.1145/354401.354407", "http://doi.acm.org/10.1145/354401.354407"),
Arguments.of("https://doi.org/10.1145/354401.354407", "10.1145/354401.354407"),
Arguments.of("https://doi.org/10.1145/354401.354407", "/10.1145/354401.354407"),
Arguments.of("10", "10"),
Arguments.of("1", "1")

);
}
}
Loading