Skip to content

Commit

Permalink
Added more unit tests in AuthorTest (#8214)
Browse files Browse the repository at this point in the history
  • Loading branch information
faco400 authored Nov 13, 2021
1 parent c593f35 commit d80eb7c
Showing 1 changed file with 54 additions and 17 deletions.
71 changes: 54 additions & 17 deletions src/test/java/org/jabref/model/entry/AuthorTest.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -20,23 +23,57 @@ void addDotIfAbbreviationDoesNotAddMultipleSpaces() {
assertEquals("A. O.", Author.addDotIfAbbreviation("A 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
@NullAndEmptySource
void addDotIfAbbreviationIfNameIsNullOrEmpty(String input) {
assertEquals(input, Author.addDotIfAbbreviation(input));
}

@ParameterizedTest
@ValueSource(strings = {"asdf", "a"})
void addDotIfAbbreviationLowerCaseLetters(String input) {
assertEquals(input, Author.addDotIfAbbreviation(input));
}

@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."));
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"));
}

@ParameterizedTest
@ValueSource(strings = {"1", "1 23"})
void addDotIfAbbreviationIfStartsWithNumber(String input) {
assertEquals(input, Author.addDotIfAbbreviation(input));
}

}

0 comments on commit d80eb7c

Please sign in to comment.