-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring existing unit tests (#7693)
- Loading branch information
Showing
4 changed files
with
69 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 19 additions & 31 deletions
50
src/test/java/org/jabref/logic/layout/format/LastPageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,34 @@ | ||
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 LastPageTest { | ||
|
||
@Test | ||
public void testFormatEmpty() { | ||
LayoutFormatter a = new LastPage(); | ||
assertEquals("", a.format("")); | ||
} | ||
|
||
@Test | ||
public void testFormatNull() { | ||
LayoutFormatter a = new LastPage(); | ||
assertEquals("", a.format(null)); | ||
} | ||
private LayoutFormatter lastPageLayoutFormatter = new LastPage(); | ||
|
||
@Test | ||
public void testFormatSinglePage() { | ||
LayoutFormatter a = new LastPage(); | ||
assertEquals("345", a.format("345")); | ||
@ParameterizedTest | ||
@MethodSource("provideArguments") | ||
void formatLastPage(String formattedText, String originalText) { | ||
assertEquals(formattedText, lastPageLayoutFormatter.format(originalText)); | ||
} | ||
|
||
@Test | ||
public void testFormatSingleDash() { | ||
LayoutFormatter a = new LastPage(); | ||
assertEquals("350", a.format("345-350")); | ||
} | ||
|
||
@Test | ||
public void testFormatDoubleDash() { | ||
LayoutFormatter a = new LastPage(); | ||
assertEquals("350", a.format("345--350")); | ||
} | ||
private static Stream<Arguments> provideArguments() { | ||
return Stream.of( | ||
Arguments.of("", ""), | ||
Arguments.of("", null), | ||
Arguments.of("345", "345"), | ||
Arguments.of("350", "345-350"), | ||
Arguments.of("350", "345--350"), | ||
Arguments.of("", "--") | ||
); | ||
|
||
@Test | ||
public void testFinalCoverageCase() { | ||
LayoutFormatter a = new LastPage(); | ||
assertEquals("", a.format("--")); | ||
} | ||
} |
30 changes: 21 additions & 9 deletions
30
src/test/java/org/jabref/logic/layout/format/NoSpaceBetweenAbbreviationsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
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 NoSpaceBetweenAbbreviationsTest { | ||
|
||
@Test | ||
public void testFormat() { | ||
LayoutFormatter f = new NoSpaceBetweenAbbreviations(); | ||
assertEquals("", f.format("")); | ||
assertEquals("John Meier", f.format("John Meier")); | ||
assertEquals("J.F. Kennedy", f.format("J. F. Kennedy")); | ||
assertEquals("J.R.R. Tolkien", f.format("J. R. R. Tolkien")); | ||
assertEquals("J.R.R. Tolkien and J.F. Kennedy", f.format("J. R. R. Tolkien and J. F. Kennedy")); | ||
private LayoutFormatter nsbaLayoutFormatter = new NoSpaceBetweenAbbreviations(); | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideAbbreviations") | ||
void formatAbbreviations(String formattedAbbreviation, String originalAbbreviation) { | ||
assertEquals(formattedAbbreviation, nsbaLayoutFormatter.format(originalAbbreviation)); | ||
} | ||
|
||
private static Stream<Arguments> provideAbbreviations() { | ||
return Stream.of( | ||
Arguments.of("", ""), | ||
Arguments.of("John Meier", "John Meier"), | ||
Arguments.of("J.F. Kennedy", "J. F. Kennedy"), | ||
Arguments.of("J.R.R. Tolkien", "J. R. R. Tolkien"), | ||
Arguments.of("J.R.R. Tolkien and J.F. Kennedy", "J. R. R. Tolkien and J. F. Kennedy") | ||
); | ||
} | ||
} |
82 changes: 28 additions & 54 deletions
82
src/test/java/org/jabref/logic/layout/format/WrapContentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,39 @@ | ||
package org.jabref.logic.layout.format; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.jabref.logic.layout.ParamLayoutFormatter; | ||
|
||
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 WrapContentTest { | ||
|
||
@Test | ||
public void testSimpleText() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
a.setArgument("<,>"); | ||
assertEquals("<Bob>", a.format("Bob")); | ||
} | ||
|
||
@Test | ||
public void testEmptyStart() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
a.setArgument(",:"); | ||
assertEquals("Bob:", a.format("Bob")); | ||
} | ||
|
||
@Test | ||
public void testEmptyEnd() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
a.setArgument("Content: ,"); | ||
assertEquals("Content: Bob", a.format("Bob")); | ||
} | ||
|
||
@Test | ||
public void testEscaping() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
a.setArgument("Name\\,Field\\,,\\,Author"); | ||
assertEquals("Name,Field,Bob,Author", a.format("Bob")); | ||
} | ||
|
||
@Test | ||
public void testFormatNullExpectNothingAdded() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
a.setArgument("Eds.,Ed."); | ||
assertEquals(null, a.format(null)); | ||
} | ||
|
||
@Test | ||
public void testFormatEmptyExpectNothingAdded() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
a.setArgument("Eds.,Ed."); | ||
assertEquals("", a.format("")); | ||
} | ||
|
||
@Test | ||
public void testNoArgumentSetExpectNothingAdded() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
assertEquals("Bob Bruce and Jolly Jumper", a.format("Bob Bruce and Jolly Jumper")); | ||
} | ||
|
||
@Test | ||
public void testNoProperArgumentExpectNothingAdded() { | ||
ParamLayoutFormatter a = new WrapContent(); | ||
a.setArgument("Eds."); | ||
assertEquals("Bob Bruce and Jolly Jumper", a.format("Bob Bruce and Jolly Jumper")); | ||
private ParamLayoutFormatter wrapContentParamLayoutFormatter = new WrapContent(); | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideContent") | ||
void formatContent(String formattedContent, String originalContent, String desiredFormat) { | ||
if (!desiredFormat.isEmpty()) { | ||
wrapContentParamLayoutFormatter.setArgument(desiredFormat); | ||
} | ||
|
||
assertEquals(formattedContent, wrapContentParamLayoutFormatter.format(originalContent)); | ||
} | ||
|
||
private static Stream<Arguments> provideContent() { | ||
return Stream.of( | ||
Arguments.of("<Bob>", "Bob", "<,>"), | ||
Arguments.of("Bob:", "Bob", ",:"), | ||
Arguments.of("Content: Bob", "Bob", "Content: ,"), | ||
Arguments.of("Name,Field,Bob,Author", "Bob", "Name\\,Field\\,,\\,Author"), | ||
Arguments.of(null, null, "Eds.,Ed."), | ||
Arguments.of("", "", "Eds.,Ed."), | ||
Arguments.of("Bob Bruce and Jolly Jumper", "Bob Bruce and Jolly Jumper", ""), | ||
Arguments.of("Bob Bruce and Jolly Jumper", "Bob Bruce and Jolly Jumper", "Eds.") | ||
); | ||
} | ||
} |