From d39e9e45c61f563be2fd675d4b9bff0fa6796fa5 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 15:13:15 +0200 Subject: [PATCH 01/12] DOIStripTest -> convert into ParametrizedTest --- .../logic/layout/format/DOIStripTest.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/DOIStripTest.java b/src/test/java/org/jabref/logic/layout/format/DOIStripTest.java index 8bb16e57265..b8576d4e783 100644 --- a/src/test/java/org/jabref/logic/layout/format/DOIStripTest.java +++ b/src/test/java/org/jabref/logic/layout/format/DOIStripTest.java @@ -1,25 +1,35 @@ 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 DOIStripTest { - @Test - public void testFormat() { - LayoutFormatter lf = new DOIStrip(); - - assertEquals("", lf.format("")); - assertEquals(null, lf.format(null)); - - assertEquals("10.1000/ISBN1-900512-44-0", lf.format("10.1000/ISBN1-900512-44-0")); - assertEquals("10.1000/ISBN1-900512-44-0", - lf.format("http://dx.doi.org/10.1000/ISBN1-900512-44-0")); - - assertEquals("10.1000/ISBN1-900512-44-0", - lf.format("http://doi.acm.org/10.1000/ISBN1-900512-44-0")); - } + LayoutFormatter layoutFormatter = new DOIStrip(); + + @ParameterizedTest + @MethodSource("provideDOI") + public void testFormatDOIStrip(String formattedDOI, String originalDOI) { + assertEquals(formattedDOI, layoutFormatter.format(originalDOI)); + } + + private static Stream provideDOI() { + return Stream.of( + Arguments.of("", ""), + Arguments.of(null, null), + Arguments.of("10.1000/ISBN1-900512-44-0", "10.1000/ISBN1-900512-44-0"), + Arguments.of("10.1000/ISBN1-900512-44-0", "http://dx.doi.org/10.1000/ISBN1-900512-44-0"), + Arguments.of("10.1000/ISBN1-900512-44-0", "http://doi.acm.org/10.1000/ISBN1-900512-44-0"), + Arguments.of("10.1145/354401.354407", "http://doi.acm.org/10.1145/354401.354407"), + Arguments.of("10", "10"), + Arguments.of("1", "1") + ); + } } From 03b72816f98f78429993860fc8217e16706820df Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 15:36:16 +0200 Subject: [PATCH 02/12] DefaultTest -> convert into ParametrizedTest --- .../logic/layout/format/DefaultTest.java | 57 +++++++------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/DefaultTest.java b/src/test/java/org/jabref/logic/layout/format/DefaultTest.java index c746de8c858..2a44b69b141 100644 --- a/src/test/java/org/jabref/logic/layout/format/DefaultTest.java +++ b/src/test/java/org/jabref/logic/layout/format/DefaultTest.java @@ -1,49 +1,36 @@ 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 DefaultTest { - @Test - public void testSimpleText() { - ParamLayoutFormatter a = new Default(); - a.setArgument("DEFAULT TEXT"); - assertEquals("Bob Bruce", a.format("Bob Bruce")); - } - - @Test - public void testFormatNullExpectReplace() { - ParamLayoutFormatter a = new Default(); - a.setArgument("DEFAULT TEXT"); - assertEquals("DEFAULT TEXT", a.format(null)); - } - - @Test - public void testFormatEmpty() { - ParamLayoutFormatter a = new Default(); - a.setArgument("DEFAULT TEXT"); - assertEquals("DEFAULT TEXT", a.format("")); - } - - @Test - public void testNoArgumentSet() { - ParamLayoutFormatter a = new Default(); - assertEquals("Bob Bruce and Jolly Jumper", a.format("Bob Bruce and Jolly Jumper")); - } + ParamLayoutFormatter paramLayoutFormatter = new Default(); - @Test - public void testNoArgumentSetNullInput() { - ParamLayoutFormatter a = new Default(); - assertEquals("", a.format(null)); + @ParameterizedTest + @MethodSource("formatTests") + void paramLayoutFormatTest(String expectedString, String inputString, String formatterArgument){ + if (!formatterArgument.isEmpty()){ + paramLayoutFormatter.setArgument(formatterArgument); + } + assertEquals(expectedString, paramLayoutFormatter.format(inputString)); } - @Test - public void testNoArgumentSetEmptyInput() { - ParamLayoutFormatter a = new Default(); - assertEquals("", a.format("")); + private static Stream formatTests() { + return Stream.of( + Arguments.of("Bob Bruce", "Bob Bruce", "DEFAULT TEXT"), + Arguments.of("DEFAULT TEXT", null, "DEFAULT TEXT"), + Arguments.of("DEFAULT TEXT", "", "DEFAULT TEXT"), + Arguments.of("Bob Bruce and Jolly Jumper", "Bob Bruce and Jolly Jumper", ""), + Arguments.of("", null, ""), + Arguments.of("", "", "") + ); } } From 23f3a516005e56a1bfa6abb7f79171c718d40008 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 23:53:09 +0200 Subject: [PATCH 03/12] ToUpperCaseTest -> DefaultTest -> converted into ParametrizedTest --- .../logic/layout/format/ToUpperCaseTest.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java b/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java index adb559e5bf9..d49f9d5a2f4 100644 --- a/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java +++ b/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java @@ -1,34 +1,30 @@ package org.jabref.logic.layout.format; -import org.junit.jupiter.api.Test; +import java.util.stream.Stream; + +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; -import static org.junit.jupiter.api.Assertions.assertNull; public class ToUpperCaseTest { - @Test - public void testEmpty() { - assertEquals("", new ToUpperCase().format("")); - } - - @Test - public void testNull() { - assertNull(new ToUpperCase().format(null)); - } - - @Test - public void testLowerCase() { - assertEquals("ABCD EFG", new ToUpperCase().format("abcd efg")); - } + ToUpperCase upperCase = new ToUpperCase(); - @Test - public void testUpperCase() { - assertEquals("ABCD EFG", new ToUpperCase().format("ABCD EFG")); + @ParameterizedTest + @MethodSource("toUpperCaseTests") + void toUpperCaseTests(String expectedString, String inputString){ + assertEquals(expectedString, upperCase.format(inputString)); } - @Test - public void testMixedCase() { - assertEquals("ABCD EFG", new ToUpperCase().format("abCD eFg")); + private static Stream toUpperCaseTests() { + return Stream.of( + Arguments.of("", ""), + Arguments.of(null, null), + Arguments.of("ABCD EFG", "abcd efg"), + Arguments.of("ABCD EFG", "ABCD EFG"), + Arguments.of("ABCD EFG", "abCD eFg") + ); } } From 7d1b2ae0f11c9058e1bde55247a4d1cf1b88450a Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 23:53:22 +0200 Subject: [PATCH 04/12] IfPluralTest -> converted into ParametrizedTest --- .../logic/layout/format/IfPluralTest.java | 59 +++++++------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java b/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java index bb5dbbaceff..ab5e2f70132 100644 --- a/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java +++ b/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java @@ -1,51 +1,36 @@ 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 IfPluralTest { - @Test - public void testStandardUsageOneEditor() { - ParamLayoutFormatter a = new IfPlural(); - a.setArgument("Eds.,Ed."); - assertEquals("Ed.", a.format("Bob Bruce")); - } - - @Test - public void testStandardUsageTwoEditors() { - ParamLayoutFormatter a = new IfPlural(); - a.setArgument("Eds.,Ed."); - assertEquals("Eds.", a.format("Bob Bruce and Jolly Jumper")); - } - - @Test - public void testFormatNull() { - ParamLayoutFormatter a = new IfPlural(); - a.setArgument("Eds.,Ed."); - assertEquals("", a.format(null)); - } - - @Test - public void testFormatEmpty() { - ParamLayoutFormatter a = new IfPlural(); - a.setArgument("Eds.,Ed."); - assertEquals("", a.format("")); - } + ParamLayoutFormatter ifPluralFormatter = new IfPlural(); - @Test - public void testNoArgumentSet() { - ParamLayoutFormatter a = new IfPlural(); - assertEquals("", a.format("Bob Bruce and Jolly Jumper")); + @ParameterizedTest + @MethodSource("formatTests") + void testIfPluralFormat(String expectedString, String inputString, String formatterArgument) { + if (!formatterArgument.isEmpty()) { + ifPluralFormatter.setArgument(formatterArgument); + } + assertEquals(expectedString, ifPluralFormatter.format(inputString)); } - @Test - public void testNoProperArgument() { - ParamLayoutFormatter a = new IfPlural(); - a.setArgument("Eds."); - assertEquals("", a.format("Bob Bruce and Jolly Jumper")); + private static Stream formatTests() { + return Stream.of( + Arguments.of("Ed.", "Bob Bruce", "Eds.,Ed."), + Arguments.of("Eds.", "Bob Bruce and Jolly Jumper", "Eds.,Ed."), + Arguments.of("", null, "Eds.,Ed."), + Arguments.of("", "", "Eds.,Ed."), + Arguments.of("", "Bob Bruce and Jolly Jumper", ""), + Arguments.of("", "Bob Bruce and Jolly Jumper", "Eds.") + ); } } From cb79f6c7db90abd64d7d5508ea3d21ca88517c81 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 23:54:24 +0200 Subject: [PATCH 05/12] HTMLParagraphsTest -> converted into ParametrizedTest --- .../layout/format/HTMLParagraphsTest.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java b/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java index 6b2094c3ce4..bdc1b0ddab2 100644 --- a/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java +++ b/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java @@ -1,22 +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 HTMLParagraphsTest { - @Test - public void testFormat() { + LayoutFormatter htmlFormatter = new HTMLParagraphs(); - LayoutFormatter f = new HTMLParagraphs(); + @ParameterizedTest + @MethodSource("htmlFormatTests") + void testCorrectFormat(String expectedString, String inputString){ + assertEquals(expectedString, htmlFormatter.format(inputString)); + } - assertEquals("", f.format("")); - assertEquals("

\nHello\n

", f.format("Hello")); - assertEquals("

\nHello\nWorld\n

", f.format("Hello\nWorld")); - assertEquals("

\nHello World\n

\n

\nWhat a lovely day\n

", f.format("Hello World\n \nWhat a lovely day\n")); - assertEquals("

\nHello World\n

\n

\nCould not be any better\n

\n

\nWhat a lovely day\n

", f.format("Hello World\n \n\nCould not be any better\n\nWhat a lovely day\n")); + private static Stream htmlFormatTests() { + return Stream.of( + Arguments.of("", ""), + Arguments.of("

\nHello\n

", "Hello"), + Arguments.of("

\nHello\nWorld\n

", "Hello\nWorld"), + Arguments.of("

\nHello World\n

\n

\nWhat a lovely day\n

", "Hello World\n \nWhat a lovely day\n"), + Arguments.of("

\nHello World\n

\n

\nCould not be any better\n

\n

\nWhat a lovely day\n

", "Hello World\n \n\nCould not be any better\n\nWhat a lovely day\n") + ); } } From 1b9793846829fa3b70a5c01915d698ce88ce3e67 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 23:54:43 +0200 Subject: [PATCH 06/12] EntryTypeFormatterTest -> converted into ParametrizedTest --- .../layout/format/EntryTypeFormatterTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java index 0dd5c4f7c11..d8c3cf23517 100644 --- a/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java +++ b/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java @@ -2,30 +2,30 @@ 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 java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; public class EntryTypeFormatterTest { - private EntryTypeFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new EntryTypeFormatter(); - } - - @Test - public void testCorrectFormatArticle() { - assertEquals("Article", formatter.format("article")); - } + private EntryTypeFormatter formatter = new EntryTypeFormatter(); - @Test - public void testCorrectFormatInBook() { - assertEquals("InBook", formatter.format("inbook")); + @ParameterizedTest + @MethodSource("formatTests") + void testCorrectFormat(String expectedString, String inputString){ + assertEquals(expectedString, formatter.format(inputString)); } - @Test - public void testIncorrectTypeAarticle() { - assertEquals("Aarticle", formatter.format("aarticle")); + private static Stream formatTests() { + return Stream.of( + Arguments.of("Article", "article"), + Arguments.of("Banana", "banana"), + Arguments.of("InBook", "inbook"), + Arguments.of("Aarticle", "aarticle") + ); } } From cb43f3baf42c21e6c590fd9e19134a8d328906d4 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 23:54:59 +0200 Subject: [PATCH 07/12] AuthorOrgSciTest -> converted into ParametrizedTest --- .../logic/layout/format/AuthorOrgSciTest.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java b/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java index 522c4caae58..93250457f78 100644 --- a/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java +++ b/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java @@ -1,27 +1,42 @@ 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 AuthorOrgSciTest { - @Test - public void testOrgSci() { - LayoutFormatter f = new AuthorOrgSci(); + LayoutFormatter authorOrgNatFormatter = new AuthorOrgSci(); + LayoutFormatter authorOrgNatFormatterComposite = new CompositeFormat(new AuthorOrgSci(), new NoSpaceBetweenAbbreviations()); - assertEquals("Flynn, J., S. Gartska", f.format("John Flynn and Sabine Gartska")); - assertEquals("Garvin, D. A.", f.format("David A. Garvin")); - assertEquals("Makridakis, S., S. C. Wheelwright, V. E. McGee", f.format("Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee")); + @ParameterizedTest + @MethodSource("formatTests") + void paramLayoutFormatTest(String expectedString, String inputString, boolean removeSpacesBetweenAbbreviations){ + if (!removeSpacesBetweenAbbreviations) { + assertEquals(expectedString, authorOrgNatFormatter.format(inputString)); + } + else{ + assertEquals(expectedString, authorOrgNatFormatterComposite.format(inputString)); + } } - @Test - public void testOrgSciPlusAbbreviation() { - LayoutFormatter f = new CompositeFormat(new AuthorOrgSci(), new NoSpaceBetweenAbbreviations()); - assertEquals("Flynn, J., S. Gartska", f.format("John Flynn and Sabine Gartska")); - assertEquals("Garvin, D.A.", f.format("David A. Garvin")); - assertEquals("Makridakis, S., S.C. Wheelwright, V.E. McGee", f.format("Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee")); + private static Stream formatTests() { + return Stream.of( + //OrgSci Formatting Tests + Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska", false), + Arguments.of("Garvin, D. A.", "David A. Garvin", false), + Arguments.of("Makridakis, S., S. C. Wheelwright, V. E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee", false), + + //Composite OrgSci Formatting Tests + Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska", true), + Arguments.of("Garvin, D.A.", "David A. Garvin", true), + Arguments.of("Makridakis, S., S.C. Wheelwright, V.E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee", true) + ); } } From 4874ea06cde47a262168e668eb94e76ebb91868f Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 23:55:15 +0200 Subject: [PATCH 08/12] AuthorNatBibTest -> converted into ParametrizedTest --- .../logic/layout/format/AuthorNatBibTest.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java b/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java index 35b8d4b0cae..3db1db9b8b2 100644 --- a/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java +++ b/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java @@ -1,25 +1,36 @@ package org.jabref.logic.layout.format; -import org.junit.jupiter.api.Test; +import java.util.stream.Stream; + +import org.jabref.logic.layout.LayoutFormatter; +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 AuthorNatBibTest { - /** - * Test method for {@link org.jabref.logic.layout.format.AuthorNatBib#format(java.lang.String)}. - */ - @Test - public void testFormatThreeAuthors() { - assertEquals("von Neumann et al.", - new AuthorNatBib().format("von Neumann,,John and John Smith and Black Brown, Jr, Peter")); + LayoutFormatter authorNatBibFormatter = new AuthorNatBib(); + + @ParameterizedTest + @MethodSource("formatTests") + void paramLayoutFormatTest(String expectedString, String inputString){ + assertEquals(expectedString, authorNatBibFormatter.format(inputString)); } - /** - * Test method for {@link org.jabref.logic.layout.format.AuthorLF_FF#format(java.lang.String)}. - */ - @Test - public void testFormatTwoAuthors() { - assertEquals("von Neumann and Smith", new AuthorNatBib().format("von Neumann,,John and John Smith")); + private static Stream formatTests() { + return Stream.of( + /** + * Test method for {@link org.jabref.logic.layout.format.AuthorNatBib#format(java.lang.String)}. + */ + Arguments.of("von Neumann et al.", "von Neumann,,John and John Smith and Black Brown, Jr, Peter"), + + /** + * Test method for {@link org.jabref.logic.layout.format.AuthorLF_FF#format(java.lang.String)}. + */ + Arguments.of("von Neumann and Smith", "von Neumann,,John and John Smith"), + Arguments.of("von Neumann", "von Neumann, John") + ); } } From 20cf290428b054d78fca2b5098926681ede0ab13 Mon Sep 17 00:00:00 2001 From: Dario Safa Date: Mon, 3 May 2021 23:55:29 +0200 Subject: [PATCH 09/12] AuthorFirstLastCommasTest -> converted into ParametrizedTest --- .../format/AuthorFirstLastCommasTest.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/AuthorFirstLastCommasTest.java b/src/test/java/org/jabref/logic/layout/format/AuthorFirstLastCommasTest.java index 6ba9a15966d..bdf0490a42f 100644 --- a/src/test/java/org/jabref/logic/layout/format/AuthorFirstLastCommasTest.java +++ b/src/test/java/org/jabref/logic/layout/format/AuthorFirstLastCommasTest.java @@ -1,35 +1,37 @@ 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 AuthorFirstLastCommasTest { + LayoutFormatter authorFLCFormatter = new AuthorFirstLastCommas(); + /** * Test method for {@link org.jabref.logic.layout.format.AuthorFirstLastCommas#format(java.lang.String)}. */ - @Test - public void testFormat() { - LayoutFormatter a = new AuthorFirstLastCommas(); - - // Empty case - assertEquals("", a.format("")); - - // Single Names - assertEquals("Van Something Someone", a.format("Someone, Van Something")); - - // Two names - assertEquals("John von Neumann and Peter Black Brown", a - .format("John von Neumann and Peter Black Brown")); - - // Three names - assertEquals("John von Neumann, John Smith and Peter Black Brown", a - .format("von Neumann, John and Smith, John and Black Brown, Peter")); + @ParameterizedTest + @MethodSource("formatTests") + void paramLayoutFormatTest(String expectedString, String inputString) { + assertEquals(expectedString, authorFLCFormatter.format(inputString)); + } - assertEquals("John von Neumann, John Smith and Peter Black Brown", a - .format("John von Neumann and John Smith and Black Brown, Peter")); + private static Stream formatTests() { + return Stream.of( + Arguments.of("", ""), + Arguments.of("Van Something Someone", "Someone, Van Something"), + Arguments.of("John von Neumann and Peter Black Brown", "John von Neumann and Peter Black Brown"), + Arguments.of("John von Neumann, John Smith and Peter Black Brown", "von Neumann, John and Smith, John and Black Brown, Peter"), + Arguments.of("John von Neumann, John Smith and Peter Black Brown", "John von Neumann and John Smith and Black Brown, Peter"), + Arguments.of("John von Neumann and Peter Black Brown", "John von Neumann and Peter Black Brown"), + Arguments.of("John von Neumann and Peter Black Brown", "John von Neumann and Peter Black Brown") + ); } } From 5f43374ab42fac371a97bdb4901f99a4b97189a1 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 7 Jun 2021 22:40:48 +0200 Subject: [PATCH 10/12] Fix Checkstyle Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> --- .../jabref/logic/layout/format/AuthorNatBibTest.java | 11 ++++------- .../jabref/logic/layout/format/AuthorOrgSciTest.java | 9 ++++----- .../org/jabref/logic/layout/format/DefaultTest.java | 4 ++-- .../logic/layout/format/EntryTypeFormatterTest.java | 4 +--- .../logic/layout/format/HTMLParagraphsTest.java | 2 +- .../jabref/logic/layout/format/ToUpperCaseTest.java | 2 +- 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java b/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java index 3db1db9b8b2..164e4c667de 100644 --- a/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java +++ b/src/test/java/org/jabref/logic/layout/format/AuthorNatBibTest.java @@ -3,6 +3,7 @@ import java.util.stream.Stream; import org.jabref.logic.layout.LayoutFormatter; + import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -15,20 +16,16 @@ public class AuthorNatBibTest { @ParameterizedTest @MethodSource("formatTests") - void paramLayoutFormatTest(String expectedString, String inputString){ + void paramLayoutFormatTest(String expectedString, String inputString) { assertEquals(expectedString, authorNatBibFormatter.format(inputString)); } private static Stream formatTests() { return Stream.of( - /** - * Test method for {@link org.jabref.logic.layout.format.AuthorNatBib#format(java.lang.String)}. - */ + // Test method for {@link org.jabref.logic.layout.format.AuthorNatBib#format(java.lang.String)}. Arguments.of("von Neumann et al.", "von Neumann,,John and John Smith and Black Brown, Jr, Peter"), - /** - * Test method for {@link org.jabref.logic.layout.format.AuthorLF_FF#format(java.lang.String)}. - */ + // Test method for {@link org.jabref.logic.layout.format.AuthorLF_FF#format(java.lang.String)}. Arguments.of("von Neumann and Smith", "von Neumann,,John and John Smith"), Arguments.of("von Neumann", "von Neumann, John") ); diff --git a/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java b/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java index 93250457f78..09d808a0f7a 100644 --- a/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java +++ b/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java @@ -17,23 +17,22 @@ public class AuthorOrgSciTest { @ParameterizedTest @MethodSource("formatTests") - void paramLayoutFormatTest(String expectedString, String inputString, boolean removeSpacesBetweenAbbreviations){ + void paramLayoutFormatTest(String expectedString, String inputString, boolean removeSpacesBetweenAbbreviations) { if (!removeSpacesBetweenAbbreviations) { assertEquals(expectedString, authorOrgNatFormatter.format(inputString)); - } - else{ + } else { assertEquals(expectedString, authorOrgNatFormatterComposite.format(inputString)); } } private static Stream formatTests() { return Stream.of( - //OrgSci Formatting Tests + // OrgSci Formatting Tests Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska", false), Arguments.of("Garvin, D. A.", "David A. Garvin", false), Arguments.of("Makridakis, S., S. C. Wheelwright, V. E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee", false), - //Composite OrgSci Formatting Tests + // Composite OrgSci Formatting Tests Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska", true), Arguments.of("Garvin, D.A.", "David A. Garvin", true), Arguments.of("Makridakis, S., S.C. Wheelwright, V.E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee", true) diff --git a/src/test/java/org/jabref/logic/layout/format/DefaultTest.java b/src/test/java/org/jabref/logic/layout/format/DefaultTest.java index 2a44b69b141..4414990c4fc 100644 --- a/src/test/java/org/jabref/logic/layout/format/DefaultTest.java +++ b/src/test/java/org/jabref/logic/layout/format/DefaultTest.java @@ -16,8 +16,8 @@ public class DefaultTest { @ParameterizedTest @MethodSource("formatTests") - void paramLayoutFormatTest(String expectedString, String inputString, String formatterArgument){ - if (!formatterArgument.isEmpty()){ + void paramLayoutFormatTest(String expectedString, String inputString, String formatterArgument) { + if (!formatterArgument.isEmpty()) { paramLayoutFormatter.setArgument(formatterArgument); } assertEquals(expectedString, paramLayoutFormatter.format(inputString)); diff --git a/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java index d8c3cf23517..54adc5fea00 100644 --- a/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java +++ b/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java @@ -1,7 +1,5 @@ package org.jabref.logic.layout.format; -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; @@ -16,7 +14,7 @@ public class EntryTypeFormatterTest { @ParameterizedTest @MethodSource("formatTests") - void testCorrectFormat(String expectedString, String inputString){ + void testCorrectFormat(String expectedString, String inputString) { assertEquals(expectedString, formatter.format(inputString)); } diff --git a/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java b/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java index bdc1b0ddab2..26391ed935d 100644 --- a/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java +++ b/src/test/java/org/jabref/logic/layout/format/HTMLParagraphsTest.java @@ -16,7 +16,7 @@ public class HTMLParagraphsTest { @ParameterizedTest @MethodSource("htmlFormatTests") - void testCorrectFormat(String expectedString, String inputString){ + void testCorrectFormat(String expectedString, String inputString) { assertEquals(expectedString, htmlFormatter.format(inputString)); } diff --git a/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java b/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java index d49f9d5a2f4..4611ed276ed 100644 --- a/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java +++ b/src/test/java/org/jabref/logic/layout/format/ToUpperCaseTest.java @@ -14,7 +14,7 @@ public class ToUpperCaseTest { @ParameterizedTest @MethodSource("toUpperCaseTests") - void toUpperCaseTests(String expectedString, String inputString){ + void toUpperCaseTests(String expectedString, String inputString) { assertEquals(expectedString, upperCase.format(inputString)); } From 99ec48b02d64720d0d27a08fbf0b9be8ac1ed49c Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 7 Jun 2021 22:51:01 +0200 Subject: [PATCH 11/12] Adress comments Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> --- .../logic/layout/format/AuthorOrgSciTest.java | 34 ++++++----- .../layout/format/CompositeFormatTest.java | 1 - .../logic/layout/format/IfPluralTest.java | 59 ++++++++++++------- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java b/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java index 09d808a0f7a..22b5b82a565 100644 --- a/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java +++ b/src/test/java/org/jabref/logic/layout/format/AuthorOrgSciTest.java @@ -17,25 +17,29 @@ public class AuthorOrgSciTest { @ParameterizedTest @MethodSource("formatTests") - void paramLayoutFormatTest(String expectedString, String inputString, boolean removeSpacesBetweenAbbreviations) { - if (!removeSpacesBetweenAbbreviations) { - assertEquals(expectedString, authorOrgNatFormatter.format(inputString)); - } else { - assertEquals(expectedString, authorOrgNatFormatterComposite.format(inputString)); - } + void paramLayoutFormatTest(String expectedString, String inputString) { + assertEquals(expectedString, authorOrgNatFormatter.format(inputString)); + } + + @ParameterizedTest + @MethodSource("formatTestsComposite") + void paramLayoutFormatTestComposite(String expectedString, String inputString) { + assertEquals(expectedString, authorOrgNatFormatterComposite.format(inputString)); } private static Stream formatTests() { return Stream.of( - // OrgSci Formatting Tests - Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska", false), - Arguments.of("Garvin, D. A.", "David A. Garvin", false), - Arguments.of("Makridakis, S., S. C. Wheelwright, V. E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee", false), - - // Composite OrgSci Formatting Tests - Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska", true), - Arguments.of("Garvin, D.A.", "David A. Garvin", true), - Arguments.of("Makridakis, S., S.C. Wheelwright, V.E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee", true) + Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska"), + Arguments.of("Garvin, D. A.", "David A. Garvin"), + Arguments.of("Makridakis, S., S. C. Wheelwright, V. E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee") + ); + } + + private static Stream formatTestsComposite() { + return Stream.of( + Arguments.of("Flynn, J., S. Gartska", "John Flynn and Sabine Gartska"), + Arguments.of("Garvin, D.A.", "David A. Garvin"), + Arguments.of("Makridakis, S., S.C. Wheelwright, V.E. McGee", "Sa Makridakis and Sa Ca Wheelwright and Va Ea McGee") ); } } diff --git a/src/test/java/org/jabref/logic/layout/format/CompositeFormatTest.java b/src/test/java/org/jabref/logic/layout/format/CompositeFormatTest.java index da23a764241..9b0c6d49a2f 100644 --- a/src/test/java/org/jabref/logic/layout/format/CompositeFormatTest.java +++ b/src/test/java/org/jabref/logic/layout/format/CompositeFormatTest.java @@ -24,7 +24,6 @@ public void testArrayComposite() { @Test public void testDoubleComposite() { - LayoutFormatter f = new CompositeFormat(new AuthorOrgSci(), new NoSpaceBetweenAbbreviations()); LayoutFormatter first = new AuthorOrgSci(); LayoutFormatter second = new NoSpaceBetweenAbbreviations(); diff --git a/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java b/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java index ab5e2f70132..bb5dbbaceff 100644 --- a/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java +++ b/src/test/java/org/jabref/logic/layout/format/IfPluralTest.java @@ -1,36 +1,51 @@ package org.jabref.logic.layout.format; -import java.util.stream.Stream; - import org.jabref.logic.layout.ParamLayoutFormatter; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class IfPluralTest { - ParamLayoutFormatter ifPluralFormatter = new IfPlural(); + @Test + public void testStandardUsageOneEditor() { + ParamLayoutFormatter a = new IfPlural(); + a.setArgument("Eds.,Ed."); + assertEquals("Ed.", a.format("Bob Bruce")); + } + + @Test + public void testStandardUsageTwoEditors() { + ParamLayoutFormatter a = new IfPlural(); + a.setArgument("Eds.,Ed."); + assertEquals("Eds.", a.format("Bob Bruce and Jolly Jumper")); + } + + @Test + public void testFormatNull() { + ParamLayoutFormatter a = new IfPlural(); + a.setArgument("Eds.,Ed."); + assertEquals("", a.format(null)); + } + + @Test + public void testFormatEmpty() { + ParamLayoutFormatter a = new IfPlural(); + a.setArgument("Eds.,Ed."); + assertEquals("", a.format("")); + } - @ParameterizedTest - @MethodSource("formatTests") - void testIfPluralFormat(String expectedString, String inputString, String formatterArgument) { - if (!formatterArgument.isEmpty()) { - ifPluralFormatter.setArgument(formatterArgument); - } - assertEquals(expectedString, ifPluralFormatter.format(inputString)); + @Test + public void testNoArgumentSet() { + ParamLayoutFormatter a = new IfPlural(); + assertEquals("", a.format("Bob Bruce and Jolly Jumper")); } - private static Stream formatTests() { - return Stream.of( - Arguments.of("Ed.", "Bob Bruce", "Eds.,Ed."), - Arguments.of("Eds.", "Bob Bruce and Jolly Jumper", "Eds.,Ed."), - Arguments.of("", null, "Eds.,Ed."), - Arguments.of("", "", "Eds.,Ed."), - Arguments.of("", "Bob Bruce and Jolly Jumper", ""), - Arguments.of("", "Bob Bruce and Jolly Jumper", "Eds.") - ); + @Test + public void testNoProperArgument() { + ParamLayoutFormatter a = new IfPlural(); + a.setArgument("Eds."); + assertEquals("", a.format("Bob Bruce and Jolly Jumper")); } } From 87ff0ef687fa8c720313b9ef80dd60a2df1a6105 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 7 Jun 2021 23:00:42 +0200 Subject: [PATCH 12/12] Fix imports --- .../jabref/logic/layout/format/EntryTypeFormatterTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java b/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java index 54adc5fea00..8fca35e0b3a 100644 --- a/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java +++ b/src/test/java/org/jabref/logic/layout/format/EntryTypeFormatterTest.java @@ -1,11 +1,11 @@ package org.jabref.logic.layout.format; +import java.util.stream.Stream; + import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.util.stream.Stream; - import static org.junit.jupiter.api.Assertions.assertEquals; public class EntryTypeFormatterTest {