From 3ec8405e943a0fa191e2c434e9993225b13144b7 Mon Sep 17 00:00:00 2001 From: faco400 Date: Sat, 16 Oct 2021 18:02:12 -0300 Subject: [PATCH 1/3] Added more unit tests in AuthorTest --- .../org/jabref/model/entry/AuthorTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/test/java/org/jabref/model/entry/AuthorTest.java b/src/test/java/org/jabref/model/entry/AuthorTest.java index 046c602b1e3..7124f517f58 100644 --- a/src/test/java/org/jabref/model/entry/AuthorTest.java +++ b/src/test/java/org/jabref/model/entry/AuthorTest.java @@ -39,4 +39,61 @@ void addDotIfAbbreviationDoNotAddDot() { assertEquals("Moore, O. and O. Moore", Author.addDotIfAbbreviation("Moore, O. and O. Moore")); assertEquals("Moore, O. and O. Moore and Moore, O. O.", Author.addDotIfAbbreviation("Moore, O. and O. Moore and Moore, O. O.")); } + + @Test + void addDotIfAbbreviationIfNameIsNull() { + String nameTest = null; + assertEquals(null, Author.addDotIfAbbreviation(nameTest)); + } + + @Test + void addDotIfAbbreviationReturnNameIfEmptyString() { + assertEquals("", Author.addDotIfAbbreviation("")); + } + + @Test + void addDotIfAbbreviationMoreLowerCaseLetters() { + assertEquals("asdf", Author.addDotIfAbbreviation("asdf")); + } + + @Test + void addDotIfAbbreviationOnlyOneCharLowerCase() { + assertEquals("a", Author.addDotIfAbbreviation("a")); + } + + @Test + void addDotIfAbbreviationStartWithUpperCaseAndHyphen() { + assertEquals("A.-melia", Author.addDotIfAbbreviation("A-melia")); + } + + @Test + void addDotIfAbbreviationEndsWithUpperCaseLetter() { + assertEquals("AmeliA", Author.addDotIfAbbreviation("AmeliA")); + } + + @Test + void addDotIfAbbreviationEndsWithUpperCaseLetterSpaced() { + assertEquals("Ameli A.", Author.addDotIfAbbreviation("Ameli A")); + } + + @Test + void addDotIfAbbreviationEndsWithWhiteSpaced() { + assertEquals("Ameli", Author.addDotIfAbbreviation("Ameli ")); + } + + @Test + void addDotIfAbbreviationEndsWithDoubleAbbreviation() { + assertEquals("Ameli A. A.", Author.addDotIfAbbreviation("Ameli AA")); + } + + @Test + void addDotIfAbbreviationIfStartsWithNumber() { + assertEquals("1", Author.addDotIfAbbreviation("1")); + } + + @Test + void addDotIfAbbreviationIfStartsWithSpacedNumber() { + assertEquals("1 23", Author.addDotIfAbbreviation("1 23")); + } + } From 8ee641ac07d3136e403a005a1377aca811d3e5cf Mon Sep 17 00:00:00 2001 From: faco400 Date: Thu, 11 Nov 2021 15:32:43 -0300 Subject: [PATCH 2/3] refactor a few unit tests to parameterized --- .../org/jabref/model/entry/AuthorTest.java | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/test/java/org/jabref/model/entry/AuthorTest.java b/src/test/java/org/jabref/model/entry/AuthorTest.java index 7124f517f58..f8642c5dfc1 100644 --- a/src/test/java/org/jabref/model/entry/AuthorTest.java +++ b/src/test/java/org/jabref/model/entry/AuthorTest.java @@ -1,6 +1,9 @@ package org.jabref.model.entry; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,25 +43,16 @@ void addDotIfAbbreviationDoNotAddDot() { assertEquals("Moore, O. and O. Moore and Moore, O. O.", Author.addDotIfAbbreviation("Moore, O. and O. Moore and Moore, O. O.")); } - @Test - void addDotIfAbbreviationIfNameIsNull() { - String nameTest = null; - assertEquals(null, Author.addDotIfAbbreviation(nameTest)); - } - - @Test - void addDotIfAbbreviationReturnNameIfEmptyString() { - assertEquals("", Author.addDotIfAbbreviation("")); - } - - @Test - void addDotIfAbbreviationMoreLowerCaseLetters() { - assertEquals("asdf", Author.addDotIfAbbreviation("asdf")); + @ParameterizedTest + @NullAndEmptySource + void addDotIfAbbreviationIfNameIsNullOrEmpty(String input) { + assertEquals(input, Author.addDotIfAbbreviation(input)); } - @Test - void addDotIfAbbreviationOnlyOneCharLowerCase() { - assertEquals("a", Author.addDotIfAbbreviation("a")); + @ParameterizedTest + @ValueSource(strings = {"asdf", "a"}) + void addDotIfAbbreviationLowerCaseLetters(String input) { + assertEquals(input, Author.addDotIfAbbreviation(input)); } @Test @@ -86,14 +80,10 @@ void addDotIfAbbreviationEndsWithDoubleAbbreviation() { assertEquals("Ameli A. A.", Author.addDotIfAbbreviation("Ameli AA")); } - @Test - void addDotIfAbbreviationIfStartsWithNumber() { - assertEquals("1", Author.addDotIfAbbreviation("1")); - } - - @Test - void addDotIfAbbreviationIfStartsWithSpacedNumber() { - assertEquals("1 23", Author.addDotIfAbbreviation("1 23")); + @ParameterizedTest + @ValueSource(strings = {"1", "1 23"}) + void addDotIfAbbreviationIfStartsWithNumber(String input) { + assertEquals(input, Author.addDotIfAbbreviation(input)); } } From 945cc78454947c03cf02beb80521f5b90f7b44a4 Mon Sep 17 00:00:00 2001 From: faco400 Date: Thu, 11 Nov 2021 15:43:12 -0300 Subject: [PATCH 3/3] refactor AddDotIfAbbeviationDoNotAddDot test to parameterized --- .../org/jabref/model/entry/AuthorTest.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/jabref/model/entry/AuthorTest.java b/src/test/java/org/jabref/model/entry/AuthorTest.java index f8642c5dfc1..8935c197a4d 100644 --- a/src/test/java/org/jabref/model/entry/AuthorTest.java +++ b/src/test/java/org/jabref/model/entry/AuthorTest.java @@ -23,24 +23,14 @@ void addDotIfAbbreviationDoesNotAddMultipleSpaces() { assertEquals("A. O.", Author.addDotIfAbbreviation("A O")); } - @Test - void addDotIfAbbreviationDoNotAddDot() { - assertEquals("O.", Author.addDotIfAbbreviation("O.")); - assertEquals("A. O.", Author.addDotIfAbbreviation("A. O.")); - assertEquals("A.-O.", Author.addDotIfAbbreviation("A.-O.")); - assertEquals("O. Moore", Author.addDotIfAbbreviation("O. Moore")); - assertEquals("A. O. Moore", Author.addDotIfAbbreviation("A. O. Moore")); - assertEquals("O. von Moore", Author.addDotIfAbbreviation("O. von Moore")); - assertEquals("A.-O. Moore", Author.addDotIfAbbreviation("A.-O. Moore")); - assertEquals("Moore, O.", Author.addDotIfAbbreviation("Moore, O.")); - assertEquals("Moore, O., Jr.", Author.addDotIfAbbreviation("Moore, O., Jr.")); - assertEquals("Moore, A. O.", Author.addDotIfAbbreviation("Moore, A. O.")); - assertEquals("Moore, A.-O.", Author.addDotIfAbbreviation("Moore, A.-O.")); - assertEquals("MEmre", Author.addDotIfAbbreviation("MEmre")); - assertEquals("{\\'{E}}douard", Author.addDotIfAbbreviation("{\\'{E}}douard")); - assertEquals("J{\\\"o}rg", Author.addDotIfAbbreviation("J{\\\"o}rg")); - assertEquals("Moore, O. and O. Moore", Author.addDotIfAbbreviation("Moore, O. and O. Moore")); - assertEquals("Moore, O. and O. Moore and Moore, O. O.", Author.addDotIfAbbreviation("Moore, O. and O. Moore and Moore, O. O.")); + @ParameterizedTest + @ValueSource(strings = {"O.", "A. O.", "A.-O.", + "O. Moore", "A. O. Moore", "O. von Moore", "A.-O. Moore", + "Moore, O.", "Moore, O., Jr.", "Moore, A. O.", "Moore, A.-O.", + "MEmre", "{\\'{E}}douard", "J{\\\"o}rg", "Moore, O. and O. Moore", + "Moore, O. and O. Moore and Moore, O. O."}) + void addDotIfAbbreviationDoNotAddDot(String input) { + assertEquals(input, Author.addDotIfAbbreviation(input)); } @ParameterizedTest