From d422fd5298431ad8e15493c4eca4e6f11c3a75e5 Mon Sep 17 00:00:00 2001 From: Davfon Date: Sun, 2 May 2021 15:00:35 +0200 Subject: [PATCH 1/2] Add simple unit tests Add elemental test case for formatters, to check that a valid input remains unmodified. --- .../formatter/bibtexfields/CleanupUrlFormatterTest.java | 6 ++++++ .../bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java | 5 +++++ .../formatter/bibtexfields/RemoveNewlinesFormatterTest.java | 5 +++++ .../logic/formatter/casechanger/LowerCaseFormatterTest.java | 1 + .../org/jabref/logic/layout/format/RemoveBracketsTest.java | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java index 0fb47acf98e..047ffffe57a 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java @@ -29,6 +29,12 @@ void extractURLFormLink() { formatter.format("away.php?to=http%3A%2F%2Fwikipedia.org&a=snippet")); } + @Test + void validURLUnmodified() { + // the caller has to pay attention that this does not happen + assertEquals("http://wikipedia.org", formatter.format("http://wikipedia.org")); + } + @Test void latexCommandsNotRemoved() { assertEquals("http://pi.informatik.uni-siegen.de/stt/36\\_2/./03\\_Technische\\_Beitraege/ZEUS2016/beitrag\\_2.pdf", formatter.format("http://pi.informatik.uni-siegen.de/stt/36\\_2/./03\\_Technische\\_Beitraege/ZEUS2016/beitrag\\_2.pdf")); 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..0c24c3a2dfe 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java @@ -20,6 +20,11 @@ public void removeHyphensBeforeNewlines() { assertEquals("water", formatter.format("wa-\rter")); } + @Test + public void withoutHyphensUnmodified() { + assertEquals("water", formatter.format("water")); + } + @Test public void removeHyphensBeforePlatformSpecificNewlines() { String newLine = String.format("%n"); diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java index 6bbc60e0154..f3a887838fe 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java @@ -30,6 +30,11 @@ public void removeLineFeed() { assertEquals("n linebreak", formatter.format("n\nlinebreak")); } + @Test + public void withoutNewLineUnmodified() { + assertEquals("no linebreak", formatter.format("no linebreak")); + } + @Test public void removePlatformSpecificNewLine() { String newLine = String.format("%n"); diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java index 0629e48a3fe..87e2e76f3ad 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java @@ -19,6 +19,7 @@ public void setUp() { @Test public void test() { + assertEquals("lower", formatter.format("lower")); assertEquals("lower", formatter.format("LOWER")); assertEquals("lower {UPPER}", formatter.format("LOWER {UPPER}")); assertEquals("lower {U}pper", formatter.format("LOWER {U}PPER")); diff --git a/src/test/java/org/jabref/logic/layout/format/RemoveBracketsTest.java b/src/test/java/org/jabref/logic/layout/format/RemoveBracketsTest.java index 018d5354786..000cc393d32 100644 --- a/src/test/java/org/jabref/logic/layout/format/RemoveBracketsTest.java +++ b/src/test/java/org/jabref/logic/layout/format/RemoveBracketsTest.java @@ -34,4 +34,9 @@ public void singleClosingBraceCorrectlyRemoved() throws Exception { public void bracePairWithEscapedBackslashCorrectlyRemoved() throws Exception { assertEquals("\\some text\\", formatter.format("\\{some text\\}")); } + + @Test + public void withoutBracketsUnmodified() throws Exception { + assertEquals("some text", formatter.format("some text")); + } } From 0e8c83eb7f79b3a20800fa27a6cce8a09e8f9f8d Mon Sep 17 00:00:00 2001 From: Davfon Date: Wed, 12 May 2021 15:37:05 +0200 Subject: [PATCH 2/2] Convert to Parameterized Tests Address the requested changes from #7696 --- .../bibtexfields/CleanupUrlFormatterTest.java | 3 +-- .../casechanger/LowerCaseFormatterTest.java | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java index 047ffffe57a..8e577b44593 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java @@ -30,8 +30,7 @@ void extractURLFormLink() { } @Test - void validURLUnmodified() { - // the caller has to pay attention that this does not happen + void validUrlUnmodified() { assertEquals("http://wikipedia.org", formatter.format("http://wikipedia.org")); } diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java index 87e2e76f3ad..55eb22e6451 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java @@ -1,7 +1,12 @@ package org.jabref.logic.formatter.casechanger; +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; @@ -17,12 +22,19 @@ public void setUp() { formatter = new LowerCaseFormatter(); } - @Test - public void test() { - assertEquals("lower", formatter.format("lower")); - assertEquals("lower", formatter.format("LOWER")); - assertEquals("lower {UPPER}", formatter.format("LOWER {UPPER}")); - assertEquals("lower {U}pper", formatter.format("LOWER {U}PPER")); + @ParameterizedTest + @MethodSource("provideStringsForFormat") + public void test(String expected, String input) { + assertEquals(expected, formatter.format(input)); + } + + private static Stream provideStringsForFormat() { + return Stream.of( + Arguments.of("lower", "lower"), + Arguments.of("lower", "LOWER"), + Arguments.of("lower {UPPER}", "LOWER {UPPER}"), + Arguments.of("lower {U}pper", "LOWER {U}PPER") + ); } @Test