Skip to content

Commit

Permalink
Refactoring existing unit tests (#7693)
Browse files Browse the repository at this point in the history
  • Loading branch information
BShaq committed May 3, 2021
1 parent 57720ab commit 596323b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class UnprotectTermsFormatterTest {

private static Stream<Arguments> terms() throws IOException {
return Stream.of(
Arguments.of("", ""),
Arguments.of("VLSI", "{VLSI}"),
Arguments.of("VLsI", "VLsI"),
Arguments.of("VLSI", "VLSI"),
Expand Down
50 changes: 19 additions & 31 deletions src/test/java/org/jabref/logic/layout/format/LastPageTest.java
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("--"));
}
}
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 src/test/java/org/jabref/logic/layout/format/WrapContentTest.java
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.")
);
}
}

0 comments on commit 596323b

Please sign in to comment.