Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more unit tests in AuthorTest #8214

Merged
merged 3 commits into from
Nov 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}

}