diff --git a/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java b/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java index bcdcac3b4ce..5349be3ef3f 100644 --- a/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java +++ b/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java @@ -1,134 +1,148 @@ package org.jabref.logic.bst; +import java.util.stream.Stream; + import org.jabref.logic.bst.BibtexCaseChanger.FORMAT_MODE; +import org.junit.jupiter.api.Disabled; 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 BibtexCaseChangersTest { - @Test - public void testChangeCase() { - - assertCaseChangerTitleLowers("i", "i"); - assertCaseChangerAllLowers("i", "i"); - assertCaseChangerAllUppers("I", "i"); - assertCaseChangerTitleLowers("0i~ ", "0I~ "); - assertCaseChangerAllLowers("0i~ ", "0I~ "); - assertCaseChangerAllUppers("0I~ ", "0I~ "); - assertCaseChangerTitleLowers("Hi hi ", "Hi Hi "); - assertCaseChangerAllLowers("hi hi ", "Hi Hi "); - assertCaseChangerAllUppers("HI HI ", "Hi Hi "); - assertCaseChangerTitleLowers("{\\oe}", "{\\oe}"); - assertCaseChangerAllLowers("{\\oe}", "{\\oe}"); - assertCaseChangerAllUppers("{\\OE}", "{\\oe}"); - assertCaseChangerTitleLowers("Hi {\\oe }hi ", "Hi {\\oe }Hi "); - assertCaseChangerAllLowers("hi {\\oe }hi ", "Hi {\\oe }Hi "); - assertCaseChangerAllUppers("HI {\\OE }HI ", "Hi {\\oe }Hi "); - assertCaseChangerTitleLowers( - "Jonathan meyer and charles louis xavier joseph de la vall{\\'e}e poussin", - "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"); - assertCaseChangerAllLowers( - "jonathan meyer and charles louis xavier joseph de la vall{\\'e}e poussin", - "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"); - assertCaseChangerAllUppers( - "JONATHAN MEYER AND CHARLES LOUIS XAVIER JOSEPH DE LA VALL{\\'E}E POUSSIN", - "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"); - assertCaseChangerTitleLowers("{\\'e}", "{\\'e}"); - assertCaseChangerAllLowers("{\\'e}", "{\\'e}"); - assertCaseChangerAllUppers("{\\'E}", "{\\'e}"); - assertCaseChangerTitleLowers("{\\'{E}}douard masterly", "{\\'{E}}douard Masterly"); - assertCaseChangerAllLowers("{\\'{e}}douard masterly", "{\\'{E}}douard Masterly"); - assertCaseChangerAllUppers("{\\'{E}}DOUARD MASTERLY", "{\\'{E}}douard Masterly"); - assertCaseChangerTitleLowers("Ulrich {\\\"{u}}nderwood and ned {\\~n}et and paul {\\={p}}ot", - "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"); - assertCaseChangerAllLowers("ulrich {\\\"{u}}nderwood and ned {\\~n}et and paul {\\={p}}ot", - "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"); - assertCaseChangerAllUppers("ULRICH {\\\"{U}}NDERWOOD AND NED {\\~N}ET AND PAUL {\\={P}}OT", - "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"); - assertCaseChangerTitleLowers("An {$O(n \\log n / \\! \\log\\log n)$} sorting algorithm", - "An {$O(n \\log n / \\! \\log\\log n)$} Sorting Algorithm"); - assertCaseChangerAllLowers("an {$O(n \\log n / \\! \\log\\log n)$} sorting algorithm", - "An {$O(n \\log n / \\! \\log\\log n)$} Sorting Algorithm"); - assertCaseChangerAllUppers("AN {$O(n \\log n / \\! \\log\\log n)$} SORTING ALGORITHM", - "An {$O(n \\log n / \\! \\log\\log n)$} Sorting Algorithm"); - - assertCaseChangerTitleLowers("hallo", "hallo"); - assertCaseChangerTitleLowers("Hallo", "HAllo"); - assertCaseChangerTitleLowers("Hallo world", "HAllo World"); - assertCaseChangerTitleLowers("Hallo world. how", "HAllo WORLD. HOW"); - assertCaseChangerTitleLowers("Hallo {WORLD}. how", "HAllo {WORLD}. HOW"); - assertCaseChangerTitleLowers("Hallo {\\world}. how", "HAllo {\\WORLD}. HOW"); - - assertCaseChangerAllLowers("hallo", "hallo"); - assertCaseChangerAllLowers("hallo", "HAllo"); - assertCaseChangerAllLowers("hallo world", "HAllo World"); - assertCaseChangerAllLowers("hallo world. how", "HAllo WORLD. HOW"); - assertCaseChangerAllLowers("hallo {worLD}. how", "HAllo {worLD}. HOW"); - assertCaseChangerAllLowers("hallo {\\world}. how", "HAllo {\\WORLD}. HOW"); - - assertCaseChangerAllUppers("HALLO", "hallo"); - assertCaseChangerAllUppers("HALLO", "HAllo"); - assertCaseChangerAllUppers("HALLO WORLD", "HAllo World"); - assertCaseChangerAllUppers("HALLO WORLD. HOW", "HAllo World. How"); - assertCaseChangerAllUppers("HALLO {worLD}. HOW", "HAllo {worLD}. how"); - assertCaseChangerAllUppers("HALLO {\\WORLD}. HOW", "HAllo {\\woRld}. hoW"); - - assertCaseChangerTitleLowers("On notions of information transfer in {VLSI} circuits", - "On Notions of Information Transfer in {VLSI} Circuits"); + @ParameterizedTest + @MethodSource("provideStringsForTitleLowers") + public void testChangeCaseTitleLowers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.TITLE_LOWERS)); } - @Test - public void testColon() { - assertCaseChangerTitleLowers("Hallo world: How", "HAllo WORLD: HOW"); - assertCaseChangerTitleLowers("Hallo world! how", "HAllo WORLD! HOW"); - assertCaseChangerTitleLowers("Hallo world? how", "HAllo WORLD? HOW"); - assertCaseChangerTitleLowers("Hallo world. how", "HAllo WORLD. HOW"); - assertCaseChangerTitleLowers("Hallo world, how", "HAllo WORLD, HOW"); - assertCaseChangerTitleLowers("Hallo world; how", "HAllo WORLD; HOW"); - assertCaseChangerTitleLowers("Hallo world- how", "HAllo WORLD- HOW"); + private static Stream provideStringsForTitleLowers() { + return Stream.of( + Arguments.of("i", "i"), + Arguments.of("0i~ ", "0I~ "), + Arguments.of("Hi hi ", "Hi Hi "), + Arguments.of("{\\oe}", "{\\oe}"), + Arguments.of("Hi {\\oe }hi ", "Hi {\\oe }Hi "), + Arguments.of("Jonathan meyer and charles louis xavier joseph de la vall{\\'e}e poussin", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"), + Arguments.of("{\\'{E}}douard masterly", "{\\'{E}}douard Masterly"), + Arguments.of("Ulrich {\\\"{u}}nderwood and ned {\\~n}et and paul {\\={p}}ot", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"), + Arguments.of("An {$O(n \\log n / \\! \\log\\log n)$} sorting algorithm", "An {$O(n \\log n / \\! \\log\\log n)$} Sorting Algorithm"), + Arguments.of("On notions of information transfer in {VLSI} circuits", "On Notions of Information Transfer in {VLSI} Circuits"), + + Arguments.of("hallo", "hallo"), + Arguments.of("Hallo", "HAllo"), + Arguments.of("Hallo world", "HAllo World"), + Arguments.of("Hallo world. how", "HAllo WORLD. HOW"), + Arguments.of("Hallo {WORLD}. how", "HAllo {WORLD}. HOW"), + Arguments.of("Hallo {\\world}. how", "HAllo {\\WORLD}. HOW"), + + // testSpecialCharacters + Arguments.of("Hallo world: How", "HAllo WORLD: HOW"), + Arguments.of("Hallo world! how", "HAllo WORLD! HOW"), + Arguments.of("Hallo world? how", "HAllo WORLD? HOW"), + Arguments.of("Hallo world. how", "HAllo WORLD. HOW"), + Arguments.of("Hallo world, how", "HAllo WORLD, HOW"), + Arguments.of("Hallo world; how", "HAllo WORLD; HOW"), + Arguments.of("Hallo world- how", "HAllo WORLD- HOW"), + + // testSpecialBracketPlacement + Arguments.of("this i{S REALLY CraZy ST}uff", "tHIS I{S REALLY CraZy ST}UfF"), + Arguments.of("this i{S R{\\'E}ALLY CraZy ST}uff", "tHIS I{S R{\\'E}ALLY CraZy ST}UfF"), + Arguments.of("this is r{\\'e}ally crazy stuff", "tHIS IS R{\\'E}ALLY CraZy STUfF") + ); } - @Test - public void testSpecialBracketPlacement() { - // area between brackets spanning multiple words - assertCaseChangerAllLowers("this i{S REALLY CraZy ST}uff", "tHIS I{S REALLY CraZy ST}UfF"); - assertCaseChangerAllLowers("this i{S R{\\'E}ALLY CraZy ST}uff", "tHIS I{S R{\\'E}ALLY CraZy ST}UfF"); - - // real use case: Formulas - assertCaseChangerAllUppers("AN {$O(n \\log n)$} SORTING ALGORITHM", "An {$O(n \\log n)$} Sorting Algorithm"); + @ParameterizedTest + @MethodSource("provideStringsForAllLowers") + public void testChangeCaseAllLowers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.ALL_LOWERS)); + } - // only one special character, no strange bracket placement - assertCaseChangerAllLowers("this is r{\\'e}ally crazy stuff", "tHIS IS R{\\'E}ALLY CraZy STUfF"); + private static Stream provideStringsForAllLowers() { + return Stream.of( + Arguments.of("i", "i"), + Arguments.of("0i~ ", "0I~ "), + Arguments.of("hi hi ", "Hi Hi "), + Arguments.of("{\\oe}", "{\\oe}"), + Arguments.of("hi {\\oe }hi ", "Hi {\\oe }Hi "), + Arguments.of("jonathan meyer and charles louis xavier joseph de la vall{\\'e}e poussin", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"), + Arguments.of("{\\'e}", "{\\'e}"), + Arguments.of("{\\'{e}}douard masterly", "{\\'{E}}douard Masterly"), + Arguments.of("ulrich {\\\"{u}}nderwood and ned {\\~n}et and paul {\\={p}}ot", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"), + Arguments.of("an {$O(n \\log n / \\! \\log\\log n)$} sorting algorithm", "An {$O(n \\log n / \\! \\log\\log n)$} Sorting Algorithm"), + + Arguments.of("hallo", "hallo"), + Arguments.of("hallo", "HAllo"), + Arguments.of("hallo world", "HAllo World"), + Arguments.of("hallo world. how", "HAllo WORLD. HOW"), + Arguments.of("hallo {worLD}. how", "HAllo {worLD}. HOW"), + Arguments.of("hallo {\\world}. how", "HAllo {\\WORLD}. HOW"), + + // testSpecialBracketPlacement + Arguments.of("an {$O(n \\log n)$} sorting algorithm", "An {$O(n \\log n)$} Sorting Algorithm") + ); } - @Test - public void testTitleCase() { - // CaseChangers.TITLE is good at keeping some words lower case - // Here some modified test cases to show that escaping with BibtexCaseChanger also works - // Examples taken from https://github.com/JabRef/jabref/pull/176#issuecomment-142723792 - assertCaseChangerAllLowers("this is a simple example {TITLE}", "This is a simple example {TITLE}"); - assertCaseChangerAllLowers("this {IS} another simple example tit{LE}", "This {IS} another simple example tit{LE}"); - assertCaseChangerAllLowers("{What ABOUT thIS} one?", "{What ABOUT thIS} one?"); - assertCaseChangerAllLowers("{And {thIS} might {a{lso}} be possible}", "{And {thIS} might {a{lso}} be possible}"); + @ParameterizedTest + @MethodSource("provideStringsForAllUppers") + public void testChangeCaseAllUppers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.ALL_UPPERS)); + } - /* the real test would look like as follows. Also from the comment of issue 176, order reversed as the "should be" comes first */ - // assertCaseChangerTitleUppers("This is a Simple Example {TITLE}", "This is a simple example {TITLE}"); - // assertCaseChangerTitleUppers("This {IS} Another Simple Example Tit{LE}", "This {IS} another simple example tit{LE}"); - // assertCaseChangerTitleUppers("{What ABOUT thIS} one?", "{What ABOUT thIS} one?"); - // assertCaseChangerTitleUppers("{And {thIS} might {a{lso}} be possible}", "{And {thIS} might {a{lso}} be possible}"); + private static Stream provideStringsForAllUppers() { + return Stream.of( + Arguments.of("I", "i"), + Arguments.of("0I~ ", "0I~ "), + Arguments.of("HI HI ", "Hi Hi "), + Arguments.of("{\\OE}", "{\\oe}"), + Arguments.of("HI {\\OE }HI ", "Hi {\\oe }Hi "), + Arguments.of("JONATHAN MEYER AND CHARLES LOUIS XAVIER JOSEPH DE LA VALL{\\'E}E POUSSIN", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"), + Arguments.of("{\\'E}", "{\\'e}"), + Arguments.of("{\\'{E}}DOUARD MASTERLY", "{\\'{E}}douard Masterly"), + Arguments.of("ULRICH {\\\"{U}}NDERWOOD AND NED {\\~N}ET AND PAUL {\\={P}}OT", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"), + Arguments.of("AN {$O(n \\log n / \\! \\log\\log n)$} SORTING ALGORITHM", "An {$O(n \\log n / \\! \\log\\log n)$} Sorting Algorithm"), + + Arguments.of("HALLO", "hallo"), + Arguments.of("HALLO", "HAllo"), + Arguments.of("HALLO WORLD", "HAllo World"), + Arguments.of("HALLO WORLD. HOW", "HAllo World. How"), + Arguments.of("HALLO {worLD}. HOW", "HAllo {worLD}. how"), + Arguments.of("HALLO {\\WORLD}. HOW", "HAllo {\\woRld}. hoW"), + + // testSpecialBracketPlacement + Arguments.of("AN {$O(n \\log n)$} SORTING ALGORITHM", "An {$O(n \\log n)$} Sorting Algorithm") + ); } - private void assertCaseChangerTitleLowers(final String string, final String string2) { - assertEquals(string, BibtexCaseChanger.changeCase(string2, FORMAT_MODE.TITLE_LOWERS)); + @ParameterizedTest + @MethodSource("provideTitleCaseAllLowers") + public void testTitleCaseAllLowers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.ALL_LOWERS)); } - private void assertCaseChangerAllLowers(final String string, final String string2) { - assertEquals(string, BibtexCaseChanger.changeCase(string2, FORMAT_MODE.ALL_LOWERS)); + private static Stream provideTitleCaseAllLowers() { + return Stream.of( + // CaseChangers.TITLE is good at keeping some words lower case + // Here some modified test cases to show that escaping with BibtexCaseChanger also works + // Examples taken from https://github.com/JabRef/jabref/pull/176#issuecomment-142723792 + Arguments.of("this is a simple example {TITLE}", "This is a simple example {TITLE}"), + Arguments.of("this {IS} another simple example tit{LE}", "This {IS} another simple example tit{LE}"), + Arguments.of("{What ABOUT thIS} one?", "{What ABOUT thIS} one?"), + Arguments.of("{And {thIS} might {a{lso}} be possible}", "{And {thIS} might {a{lso}} be possible}") + ); } - private void assertCaseChangerAllUppers(final String string, final String string2) { - assertEquals(string, BibtexCaseChanger.changeCase(string2, FORMAT_MODE.ALL_UPPERS)); + @Disabled + @Test + public void testTitleCaseAllUppers() { + /* the real test would look like as follows. Also from the comment of issue 176, order reversed as the "should be" comes first */ + // assertCaseChangerTitleUppers("This is a Simple Example {TITLE}", "This is a simple example {TITLE}"); + // assertCaseChangerTitleUppers("This {IS} Another Simple Example Tit{LE}", "This {IS} another simple example tit{LE}"); + // assertCaseChangerTitleUppers("{What ABOUT thIS} one?", "{What ABOUT thIS} one?"); + // assertCaseChangerTitleUppers("{And {thIS} might {a{lso}} be possible}", "{And {thIS} might {a{lso}} be possible}") } } diff --git a/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java b/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java index 799a4d572ba..684e4366225 100644 --- a/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java +++ b/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java @@ -1,26 +1,33 @@ package org.jabref.logic.bst; -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.fail; public class BibtexPurifyTest { - @Test - public void testPurify() { - assertPurify("i", "i"); - assertPurify("0I ", "0I~ "); - assertPurify("Hi Hi ", "Hi Hi "); - assertPurify("oe", "{\\oe}"); - assertPurify("Hi oeHi ", "Hi {\\oe }Hi "); - assertPurify("Jonathan Meyer and Charles Louis Xavier Joseph de la Vallee Poussin", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"); - assertPurify("e", "{\\'e}"); - assertPurify("Edouard Masterly", "{\\'{E}}douard Masterly"); - assertPurify("Ulrich Underwood and Ned Net and Paul Pot", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"); + @ParameterizedTest + @MethodSource("provideTestStrings") + public void testPurify(String expected, String toBePurified) { + assertEquals(expected, BibtexPurify.purify(toBePurified, s -> fail("Should not Warn (" + s + ")! purify should be " + expected + " for " + toBePurified))); } - private void assertPurify(final String string, final String string2) { - assertEquals(string, BibtexPurify.purify(string2, s -> fail("Should not Warn (" + s + ")! purify should be " + string + " for " + string2))); + private static Stream provideTestStrings() { + return Stream.of( + Arguments.of("i", "i"), + Arguments.of("0I ", "0I~ "), + Arguments.of("Hi Hi ", "Hi Hi "), + Arguments.of("oe", "{\\oe}"), + Arguments.of("Hi oeHi ", "Hi {\\oe }Hi "), + Arguments.of("Jonathan Meyer and Charles Louis Xavier Joseph de la Vallee Poussin", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"), + Arguments.of("e", "{\\'e}"), + Arguments.of("Edouard Masterly", "{\\'{E}}douard Masterly"), + Arguments.of("Ulrich Underwood and Ned Net and Paul Pot", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot") + ); } } diff --git a/src/test/java/org/jabref/logic/bst/BibtexWidthTest.java b/src/test/java/org/jabref/logic/bst/BibtexWidthTest.java index 015eb900300..79cb00b3eb8 100644 --- a/src/test/java/org/jabref/logic/bst/BibtexWidthTest.java +++ b/src/test/java/org/jabref/logic/bst/BibtexWidthTest.java @@ -1,6 +1,10 @@ package org.jabref.logic.bst; -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; @@ -33,39 +37,39 @@ */ public class BibtexWidthTest { - private void assertBibtexWidth(final int i, final String string) { - assertEquals(i, BibtexWidth.width(string)); + @ParameterizedTest + @MethodSource("provideTestWidth") + public void testWidth(int i, String str) { + assertEquals(i, BibtexWidth.width(str)); } - @Test - public void testWidth() { - - assertBibtexWidth(278, "i"); - - assertBibtexWidth(1639, "0I~ "); - - assertBibtexWidth(2612, "Hi Hi "); - - assertBibtexWidth(778, "{\\oe}"); - - assertBibtexWidth(3390, "Hi {\\oe }Hi "); - - assertBibtexWidth(444, "{\\'e}"); - - assertBibtexWidth(19762, "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"); - - assertBibtexWidth(7861, "{\\'{E}}douard Masterly"); - - assertBibtexWidth(30514, "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"); + private static Stream provideTestWidth() { + return Stream.of( + Arguments.of(278, "i"), + Arguments.of(1639, "0I~ "), + Arguments.of(2612, "Hi Hi "), + Arguments.of(778, "{\\oe}"), + Arguments.of(3390, "Hi {\\oe }Hi "), + Arguments.of(444, "{\\'e}"), + Arguments.of(19762, "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"), + Arguments.of(7861, "{\\'{E}}douard Masterly"), + Arguments.of(30514, "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin") + ); + } + @ParameterizedTest + @MethodSource("provideTestGetCharWidth") + public void testGetCharWidth(int i, Character c) { + assertEquals(i, BibtexWidth.getCharWidth(c)); } - @Test - public void testGetCharWidth() { - assertEquals(500, BibtexWidth.getCharWidth('0')); - assertEquals(361, BibtexWidth.getCharWidth('I')); - assertEquals(500, BibtexWidth.getCharWidth('~')); - assertEquals(500, BibtexWidth.getCharWidth('}')); - assertEquals(278, BibtexWidth.getCharWidth(' ')); + private static Stream provideTestGetCharWidth() { + return Stream.of( + Arguments.of(500, '0'), + Arguments.of(361, 'I'), + Arguments.of(500, '~'), + Arguments.of(500, '}'), + Arguments.of(278, ' ') + ); } } diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java index f1dd4241bd3..e789d2002ec 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java @@ -2,6 +2,7 @@ import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -13,7 +14,12 @@ */ public class NormalizePagesFormatterTest { - private final NormalizePagesFormatter formatter = new NormalizePagesFormatter(); + private NormalizePagesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new NormalizePagesFormatter(); + } private static Stream tests() { return Stream.of( diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java index 86a65ceef0e..7010ca2a79c 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java @@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveHyphenatedNewlinesFormatterTest { + private RemoveHyphenatedNewlinesFormatter formatter; @BeforeEach diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatterTest.java index c9035ff5eb4..ddbc7ab6a2e 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatterTest.java @@ -2,6 +2,7 @@ import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -13,7 +14,12 @@ */ public class SentenceCaseFormatterTest { - private final SentenceCaseFormatter formatter = new SentenceCaseFormatter(); + private SentenceCaseFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new SentenceCaseFormatter(); + } private static Stream testData() { return Stream.of( @@ -22,15 +28,15 @@ private static Stream testData() { Arguments.of("Upper {NOT} first", "upper {NOT} FIRST"), Arguments.of("Upper {N}ot first", "upper {N}OT FIRST"), Arguments.of("Whose music? A sociology of musical language", - "Whose music? a sociology of musical language"), + "Whose music? a sociology of musical language"), Arguments.of("Bibliographic software. A comparison.", - "bibliographic software. a comparison."), + "bibliographic software. a comparison."), Arguments.of("England’s monitor; The history of the separation", - "England’s Monitor; the History of the Separation"), + "England’s Monitor; the History of the Separation"), Arguments.of("Dr. schultz: a dentist turned bounty hunter.", - "Dr. schultz: a dentist turned bounty hunter."), + "Dr. schultz: a dentist turned bounty hunter."), Arguments.of("Example case. {EXCLUDED SENTENCE.}", - "Example case. {EXCLUDED SENTENCE.}"), + "Example case. {EXCLUDED SENTENCE.}"), Arguments.of("I have {Aa} dream", new SentenceCaseFormatter().getExampleInput())); } diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatterTest.java index 3d0ffe87e7c..8d3cfe97d9e 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatterTest.java @@ -2,6 +2,7 @@ import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -13,7 +14,12 @@ */ public class TitleCaseFormatterTest { - private final TitleCaseFormatter formatter = new TitleCaseFormatter(); + private TitleCaseFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new TitleCaseFormatter(); + } private static Stream testData() { return Stream.of( @@ -22,25 +28,25 @@ private static Stream testData() { Arguments.of("An Upper Each First And", "an upper each first and"), Arguments.of("An Upper Each First And", "an upper each first AND"), Arguments.of("An Upper Each of the and First And", - "an upper each of the and first and"), + "an upper each of the and first and"), Arguments.of("An Upper Each of the and First And", - "an upper each of the AND first and"), + "an upper each of the AND first and"), Arguments.of("An Upper Each of: The and First And", - "an upper each of: the and first and"), + "an upper each of: the and first and"), Arguments.of("An Upper First with and without {CURLY} {brackets}", - "AN UPPER FIRST WITH AND WITHOUT {CURLY} {brackets}"), + "AN UPPER FIRST WITH AND WITHOUT {CURLY} {brackets}"), Arguments.of("An Upper First with {A}nd without {C}urly {b}rackets", - "AN UPPER FIRST WITH {A}ND WITHOUT {C}URLY {b}rackets"), + "AN UPPER FIRST WITH {A}ND WITHOUT {C}URLY {b}rackets"), Arguments.of("{b}rackets {b}rac{K}ets Brack{E}ts", - "{b}RaCKeTS {b}RaC{K}eTS bRaCK{E}ts"), + "{b}RaCKeTS {b}RaC{K}eTS bRaCK{E}ts"), Arguments.of("Two Experiences Designing for Effective Security", - "Two experiences designing for effective security"), + "Two experiences designing for effective security"), Arguments.of("Bibliographic Software. A Comparison.", - "bibliographic software. a comparison."), + "bibliographic software. a comparison."), Arguments.of("Bibliographic Software. {A COMPARISON.}", - "bibliographic software. {A COMPARISON.}"), + "bibliographic software. {A COMPARISON.}"), Arguments.of("{BPMN} Conformance in Open Source Engines", - new TitleCaseFormatter().getExampleInput())); + new TitleCaseFormatter().getExampleInput())); } @ParameterizedTest diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatterTest.java index 06a285705bd..5c7e0979789 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatterTest.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -14,7 +15,12 @@ */ public class UnprotectTermsFormatterTest { - private UnprotectTermsFormatter formatter = new UnprotectTermsFormatter(); + private UnprotectTermsFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new UnprotectTermsFormatter(); + } private static Stream terms() throws IOException { return Stream.of( diff --git a/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java index dba7f6bb196..71c09f2e6a4 100644 --- a/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/BibStringCheckerTest.java @@ -2,11 +2,16 @@ import java.util.Collections; import java.util.List; +import java.util.stream.Stream; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; 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; @@ -15,22 +20,19 @@ public class BibStringCheckerTest { private final BibStringChecker checker = new BibStringChecker(); private final BibEntry entry = new BibEntry(); - @Test - void fieldAcceptsNoHashMarks() { - entry.setField(StandardField.TITLE, "Not a single hash mark"); - assertEquals(Collections.emptyList(), checker.check(entry)); + @ParameterizedTest + @MethodSource("provideAcceptedInputs") + void acceptsAllowedInputs(List expected, Field field, String value) { + entry.setField(field, value); + assertEquals(expected, checker.check(entry)); } - @Test - void monthAcceptsEvenNumberOfHashMarks() { - entry.setField(StandardField.MONTH, "#jan#"); - assertEquals(Collections.emptyList(), checker.check(entry)); - } - - @Test - void authorAcceptsEvenNumberOfHashMarks() { - entry.setField(StandardField.AUTHOR, "#einstein# and #newton#"); - assertEquals(Collections.emptyList(), checker.check(entry)); + private static Stream provideAcceptedInputs() { + return Stream.of( + Arguments.of(Collections.emptyList(), StandardField.TITLE, "Not a single hash mark"), + Arguments.of(Collections.emptyList(), StandardField.MONTH, "#jan#"), + Arguments.of(Collections.emptyList(), StandardField.AUTHOR, "#einstein# and #newton#") + ); } @Test diff --git a/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java b/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java index c9263efadf6..f1ec32ad5e2 100644 --- a/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/HowPublishedCheckerTest.java @@ -32,7 +32,7 @@ void bibTexAcceptsStringWithCapitalFirstLetter() { } @Test - void bibTexDoesNotCareAboutSpecialChracters() { + void bibTexDoesNotCareAboutSpecialCharacters() { assertEquals(Optional.empty(), checker.checkValue("Lorem ipsum? 10")); } diff --git a/src/test/java/org/jabref/logic/integrity/NoBibTexFieldCheckerTest.java b/src/test/java/org/jabref/logic/integrity/NoBibTexFieldCheckerTest.java index 857c9514cdd..46ade9e221e 100644 --- a/src/test/java/org/jabref/logic/integrity/NoBibTexFieldCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/NoBibTexFieldCheckerTest.java @@ -56,5 +56,4 @@ void biblatexOnlyField(StandardField field) { List messages = checker.check(entry); assertEquals(Collections.singletonList(message), messages); } - } diff --git a/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java index 3d2f10ac6e9..28827390074 100644 --- a/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java @@ -17,7 +17,7 @@ public class TypeCheckerTest { private BibEntry entry; @Test - void inProceedingshasPagesNumbers() { + void inProceedingsHasPagesNumbers() { entry = new BibEntry(StandardEntryType.InProceedings); entry.setField(StandardField.PAGES, "11--15"); assertEquals(Collections.emptyList(), checker.check(entry)); diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java b/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java index 657d0e76649..cd7fcd49964 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java @@ -1,19 +1,31 @@ package org.jabref.logic.l10n; +import java.util.stream.Stream; + 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; import static org.junit.jupiter.api.Assertions.assertThrows; public class LocalizationKeyParamsTest { - @Test - public void testReplacePlaceholders() { - assertEquals("biblatex mode", new LocalizationKeyParams("biblatex mode").replacePlaceholders()); - assertEquals("biblatex mode", new LocalizationKeyParams("%0 mode", "biblatex").replacePlaceholders()); - assertEquals("C:\\bla mode", new LocalizationKeyParams("%0 mode", "C:\\bla").replacePlaceholders()); - assertEquals("What \n : %e %c a b", new LocalizationKeyParams("What \n : %e %c %0 %1", "a", "b").replacePlaceholders()); - assertEquals("What \n : %e %c_a b", new LocalizationKeyParams("What \n : %e %c_%0 %1", "a", "b").replacePlaceholders()); + @ParameterizedTest + @MethodSource("provideTestData") + public void testReplacePlaceholders(String expected, LocalizationKeyParams input) { + assertEquals(expected, input.replacePlaceholders()); + } + + private static Stream provideTestData() { + return Stream.of( + Arguments.of("biblatex mode", new LocalizationKeyParams("biblatex mode")), + Arguments.of("biblatex mode", new LocalizationKeyParams("%0 mode", "biblatex")), + Arguments.of("C:\\bla mode", new LocalizationKeyParams("%0 mode", "C:\\bla")), + Arguments.of("What \n : %e %c a b", new LocalizationKeyParams("What \n : %e %c %0 %1", "a", "b")), + Arguments.of("What \n : %e %c_a b", new LocalizationKeyParams("What \n : %e %c_%0 %1", "a", "b")) + ); } @Test diff --git a/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java b/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java index 9c1bfcccefb..38f63a6c87d 100644 --- a/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java +++ b/src/test/java/org/jabref/logic/util/io/FileHistoryTest.java @@ -8,6 +8,8 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class FileHistoryTest { private FileHistory history; @@ -42,4 +44,30 @@ void removeItemsLeavesOtherItemsInRightOrder() { assertEquals(Arrays.asList(Path.of("cc"), Path.of("aa")), history.getHistory()); } + + @Test + void sizeTest() { + assertEquals(0, history.size()); + history.newFile(Path.of("aa")); + assertEquals(1, history.size()); + history.newFile(Path.of("bb")); + assertEquals(2, history.size()); + } + + @Test + void isEmptyTest() { + assertTrue(history.isEmpty()); + history.newFile(Path.of("aa")); + assertFalse(history.isEmpty()); + } + + @Test + void getFileAtTest() { + history.newFile(Path.of("aa")); + history.newFile(Path.of("bb")); + history.newFile(Path.of("cc")); + assertEquals(Path.of("bb"), history.getFileAt(1)); + } } + + diff --git a/src/test/java/org/jabref/model/paging/PageTest.java b/src/test/java/org/jabref/model/paging/PageTest.java new file mode 100644 index 00000000000..e08e0d43619 --- /dev/null +++ b/src/test/java/org/jabref/model/paging/PageTest.java @@ -0,0 +1,59 @@ +package org.jabref.model.paging; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class PageTest { + private Page page1; + private Page page2; + private final int testPageNumber = 3; + private final String testQuery = "anyQuery"; + private Collection testContent = new ArrayList<>(); + private final String[] testStrings = {"str1", "str2", "str3"}; + + @BeforeEach + public void setup() { + testContent.addAll(Arrays.asList(testStrings)); + testContent = Collections.unmodifiableCollection(testContent); + page1 = new Page(testQuery, testPageNumber, testContent); + page2 = new Page(testQuery, testPageNumber); + } + + @Test + public void getContentTest() { + // make sure the collections have the same elements + List differences = new ArrayList<>(testContent); + differences.removeAll(page1.getContent()); + assertTrue(differences.isEmpty()); + + List differences2 = new ArrayList<>(page1.getContent()); + differences2.removeAll(testContent); + assertTrue(differences2.isEmpty()); + + assertTrue(page2.getContent().isEmpty()); + } + + @Test + public void getPageNumberTest() { + assertEquals(testPageNumber, page1.getPageNumber()); + } + + @Test + public void getQueryTest() { + assertEquals(testQuery, page1.getQuery()); + } + + @Test + public void getSizeTest() { + assertEquals(testContent.size(), page1.getSize()); + } +} diff --git a/src/test/java/org/jabref/preferences/FilePreferenceTest.java b/src/test/java/org/jabref/preferences/FilePreferenceTest.java new file mode 100644 index 00000000000..d97efe91c86 --- /dev/null +++ b/src/test/java/org/jabref/preferences/FilePreferenceTest.java @@ -0,0 +1,91 @@ +package org.jabref.preferences; + +import java.nio.file.Path; +import java.util.Optional; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class FilePreferenceTest { + + private FilePreferences filePreferences; + private final String testUser = "test"; + private final String testMainFileDirectory = "test"; + private final boolean shouldStoreFilesRelativeToBibFile = false; + private final String testFileNamePattern = "test"; + private final String testFileDirPattern = "test"; + private final boolean shouldDownloadLinkedFiles = false; + private final boolean shouldSearchFilesOnOpen = false; + private final boolean shouldOpenBrowseOnCreate = false; + + @BeforeEach + public void setup() { + filePreferences = new FilePreferences(testUser, testMainFileDirectory, shouldStoreFilesRelativeToBibFile, + testFileNamePattern, testFileDirPattern, shouldDownloadLinkedFiles, shouldSearchFilesOnOpen, + shouldOpenBrowseOnCreate); + } + + @Test + public void getUserTest() { + assertEquals(testUser, filePreferences.getUser()); + } + + @Test + public void getFileDirectoryNonEmptyTest() { + assertEquals(Optional.of(Path.of(testMainFileDirectory)), filePreferences.getFileDirectory()); + } + + @Test + public void getFileDirectoryEmptyTest() { + filePreferences = new FilePreferences(testUser, "", shouldStoreFilesRelativeToBibFile, + testFileNamePattern, testFileDirPattern, shouldDownloadLinkedFiles, shouldSearchFilesOnOpen, + shouldOpenBrowseOnCreate); + + assertEquals(Optional.empty(), filePreferences.getFileDirectory()); + } + + @Test + public void shouldStoreFilesRelativeToBibTest() { + assertEquals(shouldStoreFilesRelativeToBibFile, filePreferences.shouldStoreFilesRelativeToBib()); + } + + @Test + public void getFileNamePatternTest() { + assertEquals(testFileNamePattern, filePreferences.getFileNamePattern()); + } + + @Test + public void getFileDirectoryPatternTest() { + assertEquals(testFileDirPattern, filePreferences.getFileDirectoryPattern()); + } + + @Test + public void shouldDownloadLinkedFilesTest() { + assertEquals(shouldDownloadLinkedFiles, filePreferences.shouldDownloadLinkedFiles()); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void withShouldDownloadLinkedFilesTest(boolean newShouldDownloadLinkedFiles) { + FilePreferences expected = new FilePreferences(testUser, testMainFileDirectory, shouldStoreFilesRelativeToBibFile, + testFileNamePattern, testFileDirPattern, newShouldDownloadLinkedFiles, shouldSearchFilesOnOpen, + shouldOpenBrowseOnCreate); + + assertEquals(expected.shouldDownloadLinkedFiles(), + filePreferences.withShouldDownloadLinkedFiles(newShouldDownloadLinkedFiles).shouldDownloadLinkedFiles()); + } + + @Test + public void shouldSearchFilesOnOpenTest() { + assertEquals(shouldSearchFilesOnOpen, filePreferences.shouldSearchFilesOnOpen()); + } + + @Test + public void shouldOpenBrowseOnCreateTest() { + assertEquals(shouldOpenBrowseOnCreate, filePreferences.shouldOpenBrowseOnCreate()); + } +}