From 93a97bc770886c7e5fdd09066e12091fd2cf2b81 Mon Sep 17 00:00:00 2001 From: Davfon Date: Wed, 24 Mar 2021 21:46:05 +0100 Subject: [PATCH 01/10] Increase line/statement coverage (simple unit tests) --- .../jabref/logic/util/io/FileHistoryTest.java | 28 ++++++ .../org/jabref/model/paging/PageTest.java | 59 ++++++++++++ .../preferences/FilePreferenceTest.java | 91 +++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 src/test/java/org/jabref/model/paging/PageTest.java create mode 100644 src/test/java/org/jabref/preferences/FilePreferenceTest.java 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..caadea740b1 --- /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()); + } +} From 4d11f5f2ebbda1d99ada09b8278a9f0786abd267 Mon Sep 17 00:00:00 2001 From: Davfon Date: Fri, 26 Mar 2021 09:34:30 +0100 Subject: [PATCH 02/10] fix typos --- .../org/jabref/logic/integrity/HowPublishedCheckerTest.java | 2 +- .../org/jabref/logic/integrity/NoBibTexFieldCheckerTest.java | 4 ++-- src/test/java/org/jabref/logic/integrity/TypeCheckerTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 a177f7e1ef6..0f12c3a2426 100644 --- a/src/test/java/org/jabref/logic/integrity/NoBibTexFieldCheckerTest.java +++ b/src/test/java/org/jabref/logic/integrity/NoBibTexFieldCheckerTest.java @@ -53,7 +53,7 @@ void commentIsNotRecognizedAsBiblatexOnlyField() { } @Test - void instituationIsNotRecognizedAsBiblatexOnlyField() { + void institutionIsNotRecognizedAsBiblatexOnlyField() { BibEntry entry = new BibEntry(); entry.setField(StandardField.INSTITUTION, "test"); assertEquals(Collections.emptyList(), checker.check(entry)); @@ -67,7 +67,7 @@ void journalIsNotRecognizedAsBiblatexOnlyField() { } @Test - void journaltitleIsRecognizedAsBiblatexOnlyField() { + void journalTitleIsRecognizedAsBiblatexOnlyField() { BibEntry entry = new BibEntry(); entry.setField(StandardField.JOURNALTITLE, "test"); IntegrityMessage message = new IntegrityMessage("biblatex field only", entry, StandardField.JOURNALTITLE); 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)); From 5ef25ef5088d52f065045becfae7c13c5d2a22ec Mon Sep 17 00:00:00 2001 From: Davfon Date: Fri, 26 Mar 2021 14:53:36 +0100 Subject: [PATCH 03/10] move formatter creation out of @BeforeEach It is unnecessary to create a new formatter for each test. ("test smell": General Fixture / Test Code Duplication) renamed UnicodeConverterTest to UnicodeConverterFormatterTest --- .../formatter/bibtexfields/AddBracesFormatterTest.java | 8 +------- .../bibtexfields/CleanupUrlFormatterTest.java | 8 +------- .../formatter/bibtexfields/ClearFormatterTest.java | 8 +------- .../bibtexfields/EscapeAmpersandsFormatterTest.java | 8 +------- .../bibtexfields/EscapeUnderscoresFormatterTest.java | 8 +------- .../bibtexfields/HtmlToLatexFormatterTest.java | 8 +------- .../bibtexfields/HtmlToUnicodeFormatterTest.java | 8 +------- .../bibtexfields/LatexCleanupFormatterTest.java | 8 +------- .../bibtexfields/NormalizeDateFormatterTest.java | 8 +------- .../bibtexfields/NormalizeEnDashesFormatterTest.java | 8 +------- .../bibtexfields/NormalizeMonthFormatterTest.java | 8 +------- .../bibtexfields/NormalizeNamesFormatterTest.java | 8 +------- .../bibtexfields/NormalizePagesFormatterTest.java | 2 +- .../OrdinalsToSuperscriptFormatterTest.java | 8 +------- .../bibtexfields/RemoveBracesFormatterTest.java | 8 +------- .../bibtexfields/RemoveDigitsFormatterTest.java | 8 +------- .../RemoveHyphenatedNewlinesFormatterTest.java | 7 +------ .../bibtexfields/RemoveNewlinesFormatterTest.java | 8 +------- .../RemoveRedundantSpacesFormatterTest.java | 8 +------- .../bibtexfields/ReplaceTabsBySpaceFormaterTest.java | 9 +-------- .../bibtexfields/ShortenDOIFormatterTest.java | 8 +------- .../bibtexfields/TrimWhitespaceFormatterTest.java | 9 +-------- ...terTest.java => UnicodeConverterFormatterTest.java} | 10 ++-------- .../bibtexfields/UnicodeToLatexFormatterTest.java | 8 +------- .../bibtexfields/UnitsToLatexFormatterTest.java | 8 +------- 25 files changed, 26 insertions(+), 171 deletions(-) rename src/test/java/org/jabref/logic/formatter/bibtexfields/{UnicodeConverterTest.java => UnicodeConverterFormatterTest.java} (78%) diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java index 85b6ef5003e..7e52a35b15e 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ class AddBracesFormatterTest { - private AddBracesFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new AddBracesFormatter(); - } + private static final AddBracesFormatter formatter = new AddBracesFormatter(); @Test public void formatAddsSingleEnclosingBraces() { 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..537f777aaeb 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ class CleanupUrlFormatterTest { - private CleanupUrlFormatter formatter; - - @BeforeEach - void setUp() { - formatter = new CleanupUrlFormatter(); - } + private static final CleanupUrlFormatter formatter = new CleanupUrlFormatter(); @Test void removeSpecialSymbolsFromURLLink() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java index e1c759ac635..b2960c60f6e 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class ClearFormatterTest { - private ClearFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new ClearFormatter(); - } + private static final ClearFormatter formatter = new ClearFormatter(); /** * Check whether the clear formatter really returns the empty string for the empty string diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java index 2e1a3d6b222..09a776abda3 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java @@ -1,18 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class EscapeAmpersandsFormatterTest { - private EscapeAmpersandsFormatter formatter; - - @BeforeEach - void setUp() { - formatter = new EscapeAmpersandsFormatter(); - } + private static final EscapeAmpersandsFormatter formatter = new EscapeAmpersandsFormatter(); @Test void formatReturnsSameTextIfNoAmpersandsPresent() throws Exception { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java index 2c756e7eebf..ba2d4c6dc1a 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java @@ -1,18 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class EscapeUnderscoresFormatterTest { - private EscapeUnderscoresFormatter formatter; - - @BeforeEach - void setUp() { - formatter = new EscapeUnderscoresFormatter(); - } + private static final EscapeUnderscoresFormatter formatter = new EscapeUnderscoresFormatter(); @Test void formatReturnsSameTextIfNoUnderscoresPresent() throws Exception { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java index b8b6ac22ec3..878aeca9eae 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class HtmlToLatexFormatterTest { - private HtmlToLatexFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new HtmlToLatexFormatter(); - } + private static final HtmlToLatexFormatter formatter = new HtmlToLatexFormatter(); @Test public void formatWithoutHtmlCharactersReturnsSameString() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java index 81997715f25..c685ad35d16 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java @@ -1,18 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class HtmlToUnicodeFormatterTest { - private HtmlToUnicodeFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new HtmlToUnicodeFormatter(); - } + private static final HtmlToUnicodeFormatter formatter = new HtmlToUnicodeFormatter(); @Test public void formatWithoutHtmlCharactersReturnsSameString() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java index 3c98058713e..0b92e349cb3 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java @@ -1,18 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class LatexCleanupFormatterTest { - private LatexCleanupFormatter formatter; - - @BeforeEach - void setUp() { - formatter = new LatexCleanupFormatter(); - } + private static final LatexCleanupFormatter formatter = new LatexCleanupFormatter(); @Test void test() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java index 92ddc83ebf3..07e9c7f6591 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class NormalizeDateFormatterTest { - private NormalizeDateFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new NormalizeDateFormatter(); - } + private static final NormalizeDateFormatter formatter = new NormalizeDateFormatter(); @Test public void formatDateYYYYMM0D() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java index ace49c02398..6635b8f04bf 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class NormalizeEnDashesFormatterTest { - private NormalizeEnDashesFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new NormalizeEnDashesFormatter(); - } + private static final NormalizeEnDashesFormatter formatter = new NormalizeEnDashesFormatter(); @Test public void formatExample() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java index 32d196bcc2a..e724654ae2f 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class NormalizeMonthFormatterTest { - private NormalizeMonthFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new NormalizeMonthFormatter(); - } + private static final NormalizeMonthFormatter formatter = new NormalizeMonthFormatter(); @Test public void formatExample() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java index c2f74c4d560..4e122faa1f0 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class NormalizeNamesFormatterTest { - private NormalizeNamesFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new NormalizeNamesFormatter(); - } + private static final NormalizeNamesFormatter formatter = new NormalizeNamesFormatter(); @Test public void testNormalizeAuthorList() { 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 1281c8a5202..b27ec6375a3 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizePagesFormatterTest.java @@ -13,7 +13,7 @@ */ public class NormalizePagesFormatterTest { - private final NormalizePagesFormatter formatter = new NormalizePagesFormatter(); + private static final NormalizePagesFormatter formatter = new NormalizePagesFormatter(); private static Stream tests() { return Stream.of( diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatterTest.java index 6fffcf6ee30..fa5f7cff52f 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class OrdinalsToSuperscriptFormatterTest { - private OrdinalsToSuperscriptFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new OrdinalsToSuperscriptFormatter(); - } + private static final OrdinalsToSuperscriptFormatter formatter = new OrdinalsToSuperscriptFormatter(); @Test public void replacesSuperscript() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java index b2f417cd587..260d18d0a3a 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class RemoveBracesFormatterTest { - private RemoveBracesFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new RemoveBracesFormatter(); - } + private static final RemoveBracesFormatter formatter = new RemoveBracesFormatter(); @Test public void formatRemovesSingleEnclosingBraces() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java index 4eed8b2c31d..20ca02e3c11 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java @@ -1,18 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveDigitsFormatterTest { - private RemoveDigitsFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new RemoveDigitsFormatter(); - } + private static final RemoveDigitsFormatter formatter = new RemoveDigitsFormatter(); @Test public void doNothingIfSingleSpace() { 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..6c9ec7009f6 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java @@ -1,17 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveHyphenatedNewlinesFormatterTest { - private RemoveHyphenatedNewlinesFormatter formatter; - @BeforeEach - public void setUp() { - formatter = new RemoveHyphenatedNewlinesFormatter(); - } + private static final RemoveHyphenatedNewlinesFormatter formatter = new RemoveHyphenatedNewlinesFormatter(); @Test public void removeHyphensBeforeNewlines() { 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..51b76b1787b 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java @@ -1,19 +1,13 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveNewlinesFormatterTest { - private RemoveNewlinesFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new RemoveNewlinesFormatter(); - } + private static final RemoveNewlinesFormatter formatter = new RemoveNewlinesFormatter(); @Test public void removeCarriageReturnLineFeed() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java index b4b4d1e2461..48b1c042f96 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java @@ -1,18 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveRedundantSpacesFormatterTest { - private RemoveRedundantSpacesFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new RemoveRedundantSpacesFormatter(); - } + private static final RemoveRedundantSpacesFormatter formatter = new RemoveRedundantSpacesFormatter(); @Test public void doNothingIfSingleSpace() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java index cf902fdd3ee..3d69b9d278f 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java @@ -1,19 +1,12 @@ - package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class ReplaceTabsBySpaceFormaterTest { - private ReplaceTabsBySpaceFormater formatter; - - @BeforeEach - public void setUp() { - formatter = new ReplaceTabsBySpaceFormater(); - } + private static final ReplaceTabsBySpaceFormater formatter = new ReplaceTabsBySpaceFormater(); @Test public void removeSingleTab() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java index 1da025cdb4b..6c29a254199 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java @@ -2,7 +2,6 @@ import org.jabref.testutils.category.FetcherTest; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ @FetcherTest class ShortenDOIFormatterTest { - private ShortenDOIFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new ShortenDOIFormatter(); - } + private static final ShortenDOIFormatter formatter = new ShortenDOIFormatter(); @Test public void formatDoi() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java index 3154a1a91fb..558bb35c98b 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java @@ -1,19 +1,12 @@ - package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class TrimWhitespaceFormatterTest { - private TrimWhitespaceFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new TrimWhitespaceFormatter(); - } + private static final TrimWhitespaceFormatter formatter = new TrimWhitespaceFormatter(); @Test public void removeHorizontalTabulations() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterFormatterTest.java similarity index 78% rename from src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterTest.java rename to src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterFormatterTest.java index a4d7f3fa7cb..13766ac385a 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -8,14 +7,9 @@ /** * Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} */ -public class UnicodeConverterTest { +public class UnicodeConverterFormatterTest { - private UnicodeToLatexFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new UnicodeToLatexFormatter(); - } + private static final UnicodeToLatexFormatter formatter = new UnicodeToLatexFormatter(); @Test public void testBasic() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java index 865c4a8da79..5633db31aca 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java @@ -1,18 +1,12 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class UnicodeToLatexFormatterTest { - private UnicodeToLatexFormatter formatter; - - @BeforeEach - void setUp() { - formatter = new UnicodeToLatexFormatter(); - } + private static final UnicodeToLatexFormatter formatter = new UnicodeToLatexFormatter(); @Test void formatWithoutUnicodeCharactersReturnsSameString() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java index 292a79b7869..e95937dc543 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class UnitsToLatexFormatterTest { - private UnitsToLatexFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new UnitsToLatexFormatter(); - } + private static final UnitsToLatexFormatter formatter = new UnitsToLatexFormatter(); @Test public void test() { From e9aa9b3d42d4f42af4c9753a724cd3dc5a7d0329 Mon Sep 17 00:00:00 2001 From: Davfon Date: Fri, 26 Mar 2021 15:03:22 +0100 Subject: [PATCH 04/10] move formatter creation out of @BeforeEach It is unnecessary to create a new formatter for each test. ("test smell": General Fixture / Test Code Duplication) --- .../casechanger/CapitalizeFormatterTest.java | 8 +------- .../casechanger/LowerCaseFormatterTest.java | 8 +------- .../casechanger/ProtectTermsFormatterTest.java | 12 +++--------- .../casechanger/SentenceCaseFormatterTest.java | 2 +- .../casechanger/TitleCaseFormatterTest.java | 2 +- .../casechanger/UnprotectTermsFormatterTest.java | 2 +- .../casechanger/UpperCaseFormatterTest.java | 8 +------- 7 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java index 5cba9c90172..a1cc9e1f6c0 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.casechanger; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -12,12 +11,7 @@ */ public class CapitalizeFormatterTest { - private CapitalizeFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new CapitalizeFormatter(); - } + private static final CapitalizeFormatter formatter = new CapitalizeFormatter(); @Test public void test() { 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..b021cc3a5c7 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.casechanger; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class LowerCaseFormatterTest { - private LowerCaseFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new LowerCaseFormatter(); - } + private static final LowerCaseFormatter formatter = new LowerCaseFormatter(); @Test public void test() { diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java index 5840c12a4c6..94b1ec62e12 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java @@ -5,7 +5,6 @@ import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.protectedterms.ProtectedTermsPreferences; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -15,14 +14,9 @@ */ public class ProtectTermsFormatterTest { - private ProtectTermsFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new ProtectTermsFormatter( - new ProtectedTermsLoader(new ProtectedTermsPreferences(ProtectedTermsLoader.getInternalLists(), - Collections.emptyList(), Collections.emptyList(), Collections.emptyList()))); - } + private static final ProtectTermsFormatter formatter = new ProtectTermsFormatter( + new ProtectedTermsLoader(new ProtectedTermsPreferences(ProtectedTermsLoader.getInternalLists(), + Collections.emptyList(), Collections.emptyList(), Collections.emptyList()))); @Test public void testSingleWord() { 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..0a526361af9 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/SentenceCaseFormatterTest.java @@ -13,7 +13,7 @@ */ public class SentenceCaseFormatterTest { - private final SentenceCaseFormatter formatter = new SentenceCaseFormatter(); + private static final SentenceCaseFormatter formatter = new SentenceCaseFormatter(); private static Stream testData() { return Stream.of( 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..84173a2ccb5 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/TitleCaseFormatterTest.java @@ -13,7 +13,7 @@ */ public class TitleCaseFormatterTest { - private final TitleCaseFormatter formatter = new TitleCaseFormatter(); + private static final TitleCaseFormatter formatter = new TitleCaseFormatter(); private static Stream testData() { return Stream.of( 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 28b78052958..8f2411c3aaf 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UnprotectTermsFormatterTest.java @@ -14,7 +14,7 @@ */ public class UnprotectTermsFormatterTest { - private UnprotectTermsFormatter formatter = new UnprotectTermsFormatter(); + private static final UnprotectTermsFormatter formatter = new UnprotectTermsFormatter(); private static Stream terms() throws IOException { return Stream.of( diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java index 2c669a6a5d2..895564af764 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.casechanger; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class UpperCaseFormatterTest { - private UpperCaseFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new UpperCaseFormatter(); - } + private static final UpperCaseFormatter formatter = new UpperCaseFormatter(); @Test public void test() { From 3563a1b826f0bda4c9f842feacce0dd17c2a15e2 Mon Sep 17 00:00:00 2001 From: Davfon Date: Fri, 26 Mar 2021 15:07:54 +0100 Subject: [PATCH 05/10] move formatter creation out of @BeforeEach It is unnecessary to create a new formatter for each test. ("test smell": General Fixture / Test Code Duplication) --- .../formatter/minifier/MinifyNameListFormatterTest.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java b/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java index 28d6140e248..e77a1102f2b 100644 --- a/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java @@ -1,6 +1,5 @@ package org.jabref.logic.formatter.minifier; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -10,12 +9,7 @@ */ public class MinifyNameListFormatterTest { - private MinifyNameListFormatter formatter; - - @BeforeEach - public void setUp() { - formatter = new MinifyNameListFormatter(); - } + private static final MinifyNameListFormatter formatter = new MinifyNameListFormatter(); @Test public void minifyAuthorNames() { From 7e4a486601273be09fe1b3c0f441e03d6a27c706 Mon Sep 17 00:00:00 2001 From: Davfon Date: Fri, 26 Mar 2021 15:58:18 +0100 Subject: [PATCH 06/10] remove unnecessary @BeforeEach & @AfterEach It is unnecessary to create a new comparator before each test and setting it to null after each test. ("test smell": General Fixture / Test Code Duplication) --- .../comparator/CrossRefEntryComparatorTest.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java b/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java index 5bf856aeeb7..10a1b3e351e 100644 --- a/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java +++ b/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java @@ -3,24 +3,13 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class CrossRefEntryComparatorTest { - private CrossRefEntryComparator comparator; - @BeforeEach - public void setUp() { - comparator = new CrossRefEntryComparator(); - } - - @AfterEach - public void tearDown() { - comparator = null; - } + private static final CrossRefEntryComparator comparator = new CrossRefEntryComparator(); @Test public void isEqualForEntriesWithoutCrossRef() { From 98004a938019515c6fd2f318a2717e96f972bb6f Mon Sep 17 00:00:00 2001 From: Davfon Date: Fri, 26 Mar 2021 16:02:18 +0100 Subject: [PATCH 07/10] convert to Parameterized Tests test code quality improvement ("test smell": Test Code Duplication) easier to maintain, less risk of error propagation. --- .../logic/bst/BibtexCaseChangersTest.java | 240 ++++++++++-------- .../jabref/logic/bst/BibtexPurifyTest.java | 35 ++- .../org/jabref/logic/bst/BibtexWidthTest.java | 64 ++--- .../logic/integrity/BibStringCheckerTest.java | 30 ++- .../logic/l10n/LocalizationKeyParamsTest.java | 27 +- 5 files changed, 224 insertions(+), 172 deletions(-) diff --git a/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java b/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java index bcdcac3b4ce..f3504921037 100644 --- a/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java +++ b/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java @@ -1,134 +1,156 @@ package org.jabref.logic.bst; +import java.util.stream.Stream; + import org.jabref.logic.bst.BibtexCaseChanger.FORMAT_MODE; -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( + // part1 + 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"), + + // part2 + 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") + ); } - @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"); + @ParameterizedTest + @MethodSource("provideStringsForAllLowers") + public void testChangeCaseAllLowers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.ALL_LOWERS)); + } - // real use case: Formulas - assertCaseChangerAllUppers("AN {$O(n \\log n)$} SORTING ALGORITHM", "An {$O(n \\log n)$} Sorting Algorithm"); + private static Stream provideStringsForAllLowers() { + return Stream.of( + // part1 + 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"), + + // part2 + 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("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") + ); + } + + @ParameterizedTest + @MethodSource("provideStringsForAllUppers") + public void testChangeCaseAllUppers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.ALL_UPPERS)); + } - // 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 provideStringsForAllUppers() { + return Stream.of( + // part1 + 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"), + + // part2 + 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}"); - - /* 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}"); + @ParameterizedTest + @MethodSource("provideTitleCaseAllLowers") + public void testTitleCaseAllLowers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.ALL_LOWERS)); } - private void assertCaseChangerTitleLowers(final String string, final String string2) { - assertEquals(string, BibtexCaseChanger.changeCase(string2, FORMAT_MODE.TITLE_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 assertCaseChangerAllLowers(final String string, final String string2) { - assertEquals(string, BibtexCaseChanger.changeCase(string2, FORMAT_MODE.ALL_LOWERS)); + /* the real test would look like as follows. Also from the comment of issue 176, order reversed as the "should be" comes first + @ParameterizedTest + @MethodSource("provideTitleCaseTitleUppers") + public void testTitleCaseTitleUppers(String expected, String toBeFormatted) { + assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.TITLE_UPPERS)); } - private void assertCaseChangerAllUppers(final String string, final String string2) { - assertEquals(string, BibtexCaseChanger.changeCase(string2, FORMAT_MODE.ALL_UPPERS)); + private static Stream provideTitleCaseTitleUppers() { + return Stream.of( + 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}") + ); } + */ } diff --git a/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java b/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java index 799a4d572ba..0764f6d42b4 100644 --- a/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java +++ b/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java @@ -1,23 +1,34 @@ 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) { + assertPurify(expected, toBePurified); + } + + 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") + ); } private void assertPurify(final String string, final String string2) { 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/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/l10n/LocalizationKeyParamsTest.java b/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java index 657d0e76649..9624bb32e4a 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java @@ -1,21 +1,34 @@ 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 public void testTooManyParams() { assertThrows(IllegalStateException.class, () -> new LocalizationKeyParams("", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0")); From 94d4625d4027f40ce82d29caa5f9414ddab6305e Mon Sep 17 00:00:00 2001 From: Davfon Date: Tue, 13 Apr 2021 12:11:24 +0200 Subject: [PATCH 08/10] Revert BeforeEach changes, use setup method --- .../CrossRefEntryComparatorTest.java | 13 ++++++++- .../bibtexfields/AddBracesFormatterTest.java | 8 +++++- .../bibtexfields/CleanupUrlFormatterTest.java | 8 +++++- .../bibtexfields/ClearFormatterTest.java | 8 +++++- .../EscapeAmpersandsFormatterTest.java | 8 +++++- .../EscapeUnderscoresFormatterTest.java | 8 +++++- .../HtmlToLatexFormatterTest.java | 8 +++++- .../HtmlToUnicodeFormatterTest.java | 8 +++++- .../LatexCleanupFormatterTest.java | 8 +++++- .../NormalizeDateFormatterTest.java | 8 +++++- .../NormalizeEnDashesFormatterTest.java | 8 +++++- .../NormalizeMonthFormatterTest.java | 8 +++++- .../NormalizeNamesFormatterTest.java | 8 +++++- .../NormalizePagesFormatterTest.java | 8 +++++- .../OrdinalsToSuperscriptFormatterTest.java | 8 +++++- .../RemoveBracesFormatterTest.java | 8 +++++- .../RemoveDigitsFormatterTest.java | 8 +++++- ...RemoveHyphenatedNewlinesFormatterTest.java | 8 +++++- .../RemoveNewlinesFormatterTest.java | 8 +++++- .../RemoveRedundantSpacesFormatterTest.java | 8 +++++- .../ReplaceTabsBySpaceFormaterTest.java | 9 +++++- .../bibtexfields/ShortenDOIFormatterTest.java | 8 +++++- .../TrimWhitespaceFormatterTest.java | 9 +++++- ...terTest.java => UnicodeConverterTest.java} | 10 +++++-- .../UnicodeToLatexFormatterTest.java | 8 +++++- .../UnitsToLatexFormatterTest.java | 8 +++++- .../casechanger/CapitalizeFormatterTest.java | 8 +++++- .../casechanger/LowerCaseFormatterTest.java | 8 +++++- .../ProtectTermsFormatterTest.java | 12 ++++++-- .../SentenceCaseFormatterTest.java | 18 ++++++++---- .../casechanger/TitleCaseFormatterTest.java | 28 +++++++++++-------- .../UnprotectTermsFormatterTest.java | 8 +++++- .../casechanger/UpperCaseFormatterTest.java | 8 +++++- .../minifier/MinifyNameListFormatterTest.java | 8 +++++- 34 files changed, 263 insertions(+), 52 deletions(-) rename src/test/java/org/jabref/logic/formatter/bibtexfields/{UnicodeConverterFormatterTest.java => UnicodeConverterTest.java} (78%) diff --git a/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java b/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java index 10a1b3e351e..5bf856aeeb7 100644 --- a/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java +++ b/src/test/java/org/jabref/logic/bibtex/comparator/CrossRefEntryComparatorTest.java @@ -3,13 +3,24 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class CrossRefEntryComparatorTest { + private CrossRefEntryComparator comparator; - private static final CrossRefEntryComparator comparator = new CrossRefEntryComparator(); + @BeforeEach + public void setUp() { + comparator = new CrossRefEntryComparator(); + } + + @AfterEach + public void tearDown() { + comparator = null; + } @Test public void isEqualForEntriesWithoutCrossRef() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java index 7e52a35b15e..85b6ef5003e 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/AddBracesFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ class AddBracesFormatterTest { - private static final AddBracesFormatter formatter = new AddBracesFormatter(); + private AddBracesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new AddBracesFormatter(); + } @Test public void formatAddsSingleEnclosingBraces() { 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 537f777aaeb..0fb47acf98e 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/CleanupUrlFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ class CleanupUrlFormatterTest { - private static final CleanupUrlFormatter formatter = new CleanupUrlFormatter(); + private CleanupUrlFormatter formatter; + + @BeforeEach + void setUp() { + formatter = new CleanupUrlFormatter(); + } @Test void removeSpecialSymbolsFromURLLink() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java index b2960c60f6e..e1c759ac635 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/ClearFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class ClearFormatterTest { - private static final ClearFormatter formatter = new ClearFormatter(); + private ClearFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new ClearFormatter(); + } /** * Check whether the clear formatter really returns the empty string for the empty string diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java index 09a776abda3..2e1a3d6b222 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeAmpersandsFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class EscapeAmpersandsFormatterTest { - private static final EscapeAmpersandsFormatter formatter = new EscapeAmpersandsFormatter(); + private EscapeAmpersandsFormatter formatter; + + @BeforeEach + void setUp() { + formatter = new EscapeAmpersandsFormatter(); + } @Test void formatReturnsSameTextIfNoAmpersandsPresent() throws Exception { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java index ba2d4c6dc1a..2c756e7eebf 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/EscapeUnderscoresFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class EscapeUnderscoresFormatterTest { - private static final EscapeUnderscoresFormatter formatter = new EscapeUnderscoresFormatter(); + private EscapeUnderscoresFormatter formatter; + + @BeforeEach + void setUp() { + formatter = new EscapeUnderscoresFormatter(); + } @Test void formatReturnsSameTextIfNoUnderscoresPresent() throws Exception { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java index 878aeca9eae..b8b6ac22ec3 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToLatexFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class HtmlToLatexFormatterTest { - private static final HtmlToLatexFormatter formatter = new HtmlToLatexFormatter(); + private HtmlToLatexFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new HtmlToLatexFormatter(); + } @Test public void formatWithoutHtmlCharactersReturnsSameString() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java index c685ad35d16..81997715f25 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/HtmlToUnicodeFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class HtmlToUnicodeFormatterTest { - private static final HtmlToUnicodeFormatter formatter = new HtmlToUnicodeFormatter(); + private HtmlToUnicodeFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new HtmlToUnicodeFormatter(); + } @Test public void formatWithoutHtmlCharactersReturnsSameString() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java index 0b92e349cb3..3c98058713e 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/LatexCleanupFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class LatexCleanupFormatterTest { - private static final LatexCleanupFormatter formatter = new LatexCleanupFormatter(); + private LatexCleanupFormatter formatter; + + @BeforeEach + void setUp() { + formatter = new LatexCleanupFormatter(); + } @Test void test() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java index 07e9c7f6591..92ddc83ebf3 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeDateFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class NormalizeDateFormatterTest { - private static final NormalizeDateFormatter formatter = new NormalizeDateFormatter(); + private NormalizeDateFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new NormalizeDateFormatter(); + } @Test public void formatDateYYYYMM0D() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java index 6635b8f04bf..ace49c02398 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeEnDashesFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class NormalizeEnDashesFormatterTest { - private static final NormalizeEnDashesFormatter formatter = new NormalizeEnDashesFormatter(); + private NormalizeEnDashesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new NormalizeEnDashesFormatter(); + } @Test public void formatExample() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java index e724654ae2f..32d196bcc2a 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class NormalizeMonthFormatterTest { - private static final NormalizeMonthFormatter formatter = new NormalizeMonthFormatter(); + private NormalizeMonthFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new NormalizeMonthFormatter(); + } @Test public void formatExample() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java index 4e122faa1f0..c2f74c4d560 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeNamesFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class NormalizeNamesFormatterTest { - private static final NormalizeNamesFormatter formatter = new NormalizeNamesFormatter(); + private NormalizeNamesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new NormalizeNamesFormatter(); + } @Test public void testNormalizeAuthorList() { 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 b27ec6375a3..4628a7f1696 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 static 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/OrdinalsToSuperscriptFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatterTest.java index fa5f7cff52f..6fffcf6ee30 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/OrdinalsToSuperscriptFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class OrdinalsToSuperscriptFormatterTest { - private static final OrdinalsToSuperscriptFormatter formatter = new OrdinalsToSuperscriptFormatter(); + private OrdinalsToSuperscriptFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new OrdinalsToSuperscriptFormatter(); + } @Test public void replacesSuperscript() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java index 260d18d0a3a..b2f417cd587 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveBracesFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class RemoveBracesFormatterTest { - private static final RemoveBracesFormatter formatter = new RemoveBracesFormatter(); + private RemoveBracesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new RemoveBracesFormatter(); + } @Test public void formatRemovesSingleEnclosingBraces() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java index 20ca02e3c11..4eed8b2c31d 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveDigitsFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveDigitsFormatterTest { - private static final RemoveDigitsFormatter formatter = new RemoveDigitsFormatter(); + private RemoveDigitsFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new RemoveDigitsFormatter(); + } @Test public void doNothingIfSingleSpace() { 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 6c9ec7009f6..7010ca2a79c 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveHyphenatedNewlinesFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveHyphenatedNewlinesFormatterTest { - private static final RemoveHyphenatedNewlinesFormatter formatter = new RemoveHyphenatedNewlinesFormatter(); + private RemoveHyphenatedNewlinesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new RemoveHyphenatedNewlinesFormatter(); + } @Test public void removeHyphensBeforeNewlines() { 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 51b76b1787b..6bbc60e0154 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveNewlinesFormatterTest.java @@ -1,13 +1,19 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveNewlinesFormatterTest { - private static final RemoveNewlinesFormatter formatter = new RemoveNewlinesFormatter(); + private RemoveNewlinesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new RemoveNewlinesFormatter(); + } @Test public void removeCarriageReturnLineFeed() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java index 48b1c042f96..b4b4d1e2461 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/RemoveRedundantSpacesFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoveRedundantSpacesFormatterTest { - private static final RemoveRedundantSpacesFormatter formatter = new RemoveRedundantSpacesFormatter(); + private RemoveRedundantSpacesFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new RemoveRedundantSpacesFormatter(); + } @Test public void doNothingIfSingleSpace() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java index 3d69b9d278f..cf902fdd3ee 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/ReplaceTabsBySpaceFormaterTest.java @@ -1,12 +1,19 @@ + package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class ReplaceTabsBySpaceFormaterTest { - private static final ReplaceTabsBySpaceFormater formatter = new ReplaceTabsBySpaceFormater(); + private ReplaceTabsBySpaceFormater formatter; + + @BeforeEach + public void setUp() { + formatter = new ReplaceTabsBySpaceFormater(); + } @Test public void removeSingleTab() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java index 6c29a254199..1da025cdb4b 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/ShortenDOIFormatterTest.java @@ -2,6 +2,7 @@ import org.jabref.testutils.category.FetcherTest; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ @FetcherTest class ShortenDOIFormatterTest { - private static final ShortenDOIFormatter formatter = new ShortenDOIFormatter(); + private ShortenDOIFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new ShortenDOIFormatter(); + } @Test public void formatDoi() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java index 558bb35c98b..3154a1a91fb 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/TrimWhitespaceFormatterTest.java @@ -1,12 +1,19 @@ + package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class TrimWhitespaceFormatterTest { - private static final TrimWhitespaceFormatter formatter = new TrimWhitespaceFormatter(); + private TrimWhitespaceFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new TrimWhitespaceFormatter(); + } @Test public void removeHorizontalTabulations() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterTest.java similarity index 78% rename from src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterFormatterTest.java rename to src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterTest.java index 13766ac385a..a4d7f3fa7cb 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeConverterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -7,9 +8,14 @@ /** * Tests in addition to the general tests from {@link org.jabref.logic.formatter.FormatterTest} */ -public class UnicodeConverterFormatterTest { +public class UnicodeConverterTest { - private static final UnicodeToLatexFormatter formatter = new UnicodeToLatexFormatter(); + private UnicodeToLatexFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new UnicodeToLatexFormatter(); + } @Test public void testBasic() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java index 5633db31aca..865c4a8da79 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnicodeToLatexFormatterTest.java @@ -1,12 +1,18 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class UnicodeToLatexFormatterTest { - private static final UnicodeToLatexFormatter formatter = new UnicodeToLatexFormatter(); + private UnicodeToLatexFormatter formatter; + + @BeforeEach + void setUp() { + formatter = new UnicodeToLatexFormatter(); + } @Test void formatWithoutUnicodeCharactersReturnsSameString() { diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java index e95937dc543..292a79b7869 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/UnitsToLatexFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.bibtexfields; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class UnitsToLatexFormatterTest { - private static final UnitsToLatexFormatter formatter = new UnitsToLatexFormatter(); + private UnitsToLatexFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new UnitsToLatexFormatter(); + } @Test public void test() { diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java index a1cc9e1f6c0..5cba9c90172 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/CapitalizeFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.casechanger; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -11,7 +12,12 @@ */ public class CapitalizeFormatterTest { - private static final CapitalizeFormatter formatter = new CapitalizeFormatter(); + private CapitalizeFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new CapitalizeFormatter(); + } @Test public void test() { 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 b021cc3a5c7..0629e48a3fe 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/LowerCaseFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.casechanger; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class LowerCaseFormatterTest { - private static final LowerCaseFormatter formatter = new LowerCaseFormatter(); + private LowerCaseFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new LowerCaseFormatter(); + } @Test public void test() { diff --git a/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java index 94b1ec62e12..5840c12a4c6 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/ProtectTermsFormatterTest.java @@ -5,6 +5,7 @@ import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.protectedterms.ProtectedTermsPreferences; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -14,9 +15,14 @@ */ public class ProtectTermsFormatterTest { - private static final ProtectTermsFormatter formatter = new ProtectTermsFormatter( - new ProtectedTermsLoader(new ProtectedTermsPreferences(ProtectedTermsLoader.getInternalLists(), - Collections.emptyList(), Collections.emptyList(), Collections.emptyList()))); + private ProtectTermsFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new ProtectTermsFormatter( + new ProtectedTermsLoader(new ProtectedTermsPreferences(ProtectedTermsLoader.getInternalLists(), + Collections.emptyList(), Collections.emptyList(), Collections.emptyList()))); + } @Test public void testSingleWord() { 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 0a526361af9..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 static 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 84173a2ccb5..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 static 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 8f2411c3aaf..a5e87c82319 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 static final 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/formatter/casechanger/UpperCaseFormatterTest.java b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java index 895564af764..2c669a6a5d2 100644 --- a/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/casechanger/UpperCaseFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.casechanger; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class UpperCaseFormatterTest { - private static final UpperCaseFormatter formatter = new UpperCaseFormatter(); + private UpperCaseFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new UpperCaseFormatter(); + } @Test public void test() { diff --git a/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java b/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java index e77a1102f2b..28d6140e248 100644 --- a/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/minifier/MinifyNameListFormatterTest.java @@ -1,5 +1,6 @@ package org.jabref.logic.formatter.minifier; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +10,12 @@ */ public class MinifyNameListFormatterTest { - private static final MinifyNameListFormatter formatter = new MinifyNameListFormatter(); + private MinifyNameListFormatter formatter; + + @BeforeEach + public void setUp() { + formatter = new MinifyNameListFormatter(); + } @Test public void minifyAuthorNames() { From 50420b9df37dc43335d5400d571b1589b08b6746 Mon Sep 17 00:00:00 2001 From: Davfon Date: Tue, 13 Apr 2021 17:03:44 +0200 Subject: [PATCH 09/10] BibtexCaseChangersTest & BibtexPurifyTest - remove unmeaningful comment - testSpecialBracketPlacement - add disabled for commented code - integrate assertion in testPurify --- .../logic/bst/BibtexCaseChangersTest.java | 42 ++++++++----------- .../jabref/logic/bst/BibtexPurifyTest.java | 6 +-- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java b/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java index f3504921037..5349be3ef3f 100644 --- a/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java +++ b/src/test/java/org/jabref/logic/bst/BibtexCaseChangersTest.java @@ -4,6 +4,8 @@ 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; @@ -20,7 +22,6 @@ public void testChangeCaseTitleLowers(String expected, String toBeFormatted) { private static Stream provideStringsForTitleLowers() { return Stream.of( - // part1 Arguments.of("i", "i"), Arguments.of("0i~ ", "0I~ "), Arguments.of("Hi hi ", "Hi Hi "), @@ -32,7 +33,6 @@ private static Stream provideStringsForTitleLowers() { 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"), - // part2 Arguments.of("hallo", "hallo"), Arguments.of("Hallo", "HAllo"), Arguments.of("Hallo world", "HAllo World"), @@ -47,7 +47,12 @@ private static Stream provideStringsForTitleLowers() { 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") ); } @@ -59,7 +64,6 @@ public void testChangeCaseAllLowers(String expected, String toBeFormatted) { private static Stream provideStringsForAllLowers() { return Stream.of( - // part1 Arguments.of("i", "i"), Arguments.of("0i~ ", "0I~ "), Arguments.of("hi hi ", "Hi Hi "), @@ -71,7 +75,6 @@ private static Stream provideStringsForAllLowers() { 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"), - // part2 Arguments.of("hallo", "hallo"), Arguments.of("hallo", "HAllo"), Arguments.of("hallo world", "HAllo World"), @@ -80,9 +83,7 @@ private static Stream provideStringsForAllLowers() { 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") + Arguments.of("an {$O(n \\log n)$} sorting algorithm", "An {$O(n \\log n)$} Sorting Algorithm") ); } @@ -94,7 +95,6 @@ public void testChangeCaseAllUppers(String expected, String toBeFormatted) { private static Stream provideStringsForAllUppers() { return Stream.of( - // part1 Arguments.of("I", "i"), Arguments.of("0I~ ", "0I~ "), Arguments.of("HI HI ", "Hi Hi "), @@ -106,7 +106,6 @@ private static Stream provideStringsForAllUppers() { 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"), - // part2 Arguments.of("HALLO", "hallo"), Arguments.of("HALLO", "HAllo"), Arguments.of("HALLO WORLD", "HAllo World"), @@ -137,20 +136,13 @@ private static Stream provideTitleCaseAllLowers() { ); } - /* the real test would look like as follows. Also from the comment of issue 176, order reversed as the "should be" comes first - @ParameterizedTest - @MethodSource("provideTitleCaseTitleUppers") - public void testTitleCaseTitleUppers(String expected, String toBeFormatted) { - assertEquals(expected, BibtexCaseChanger.changeCase(toBeFormatted, FORMAT_MODE.TITLE_UPPERS)); - } - - private static Stream provideTitleCaseTitleUppers() { - return Stream.of( - 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}") - ); + @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 0764f6d42b4..684e4366225 100644 --- a/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java +++ b/src/test/java/org/jabref/logic/bst/BibtexPurifyTest.java @@ -14,7 +14,7 @@ public class BibtexPurifyTest { @ParameterizedTest @MethodSource("provideTestStrings") public void testPurify(String expected, String toBePurified) { - assertPurify(expected, toBePurified); + assertEquals(expected, BibtexPurify.purify(toBePurified, s -> fail("Should not Warn (" + s + ")! purify should be " + expected + " for " + toBePurified))); } private static Stream provideTestStrings() { @@ -30,8 +30,4 @@ private static Stream provideTestStrings() { Arguments.of("Ulrich Underwood and Ned Net and Paul Pot", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot") ); } - - 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))); - } } From a23e989c68ac9aa97d35517b3e0f8de9c5b9c365 Mon Sep 17 00:00:00 2001 From: Davfon Date: Tue, 13 Apr 2021 19:20:40 +0200 Subject: [PATCH 10/10] Fix CheckStyle --- .../java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java | 1 - src/test/java/org/jabref/model/paging/PageTest.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java b/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java index 9624bb32e4a..cd7fcd49964 100644 --- a/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java +++ b/src/test/java/org/jabref/logic/l10n/LocalizationKeyParamsTest.java @@ -28,7 +28,6 @@ private static Stream provideTestData() { ); } - @Test public void testTooManyParams() { assertThrows(IllegalStateException.class, () -> new LocalizationKeyParams("", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0")); diff --git a/src/test/java/org/jabref/model/paging/PageTest.java b/src/test/java/org/jabref/model/paging/PageTest.java index caadea740b1..e08e0d43619 100644 --- a/src/test/java/org/jabref/model/paging/PageTest.java +++ b/src/test/java/org/jabref/model/paging/PageTest.java @@ -30,7 +30,7 @@ public void setup() { @Test public void getContentTest() { - //make sure the collections have the same elements + // make sure the collections have the same elements List differences = new ArrayList<>(testContent); differences.removeAll(page1.getContent()); assertTrue(differences.isEmpty());