-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Formatter refactoring #3919
Formatter refactoring #3919
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,102 +38,101 @@ | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class FormatterTest { | ||
class FormatterTest { | ||
|
||
private static ProtectedTermsLoader protectedTermsLoader; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
static void setUp() { | ||
protectedTermsLoader = new ProtectedTermsLoader( | ||
new ProtectedTermsPreferences(ProtectedTermsLoader.getInternalLists(), Collections.emptyList(), | ||
Collections.emptyList(), Collections.emptyList())); | ||
|
||
} | ||
|
||
private static Stream<Formatter> getFormatters() { | ||
// all classes implementing {@link net.sf.jabref.model.cleanup.Formatter} | ||
// sorted alphabetically | ||
// Alternative: Use reflection - https://github.com/ronmamo/reflections | ||
// @formatter:off | ||
return Stream.of( | ||
new CapitalizeFormatter(), | ||
new ClearFormatter(), | ||
new HtmlToLatexFormatter(), | ||
new HtmlToUnicodeFormatter(), | ||
new IdentityFormatter(), | ||
new LatexCleanupFormatter(), | ||
new LatexToUnicodeFormatter(), | ||
new LowerCaseFormatter(), | ||
new MinifyNameListFormatter(), | ||
new NormalizeDateFormatter(), | ||
new NormalizeMonthFormatter(), | ||
new NormalizeNamesFormatter(), | ||
new NormalizePagesFormatter(), | ||
new OrdinalsToSuperscriptFormatter(), | ||
new ProtectTermsFormatter(protectedTermsLoader), | ||
new RegexFormatter("(\" \",\"-\")"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to do nitpkicking but that Regex Formatter indentation is clear off There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, no idea why there were these |
||
new RemoveBracesFormatter(), | ||
new SentenceCaseFormatter(), | ||
new TitleCaseFormatter(), | ||
new UnicodeToLatexFormatter(), | ||
new UnitsToLatexFormatter(), | ||
new UpperCaseFormatter()); | ||
|
||
// @formatter:on | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void getNameReturnsNotNull(Formatter formatter) { | ||
void getNameReturnsNotNull(Formatter formatter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you remove the public? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the new convention with JUnit 5 that test classes and their methods are package private. IntellJ even complains if they are marked with public. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah okay, that was new to me |
||
assertNotNull(formatter.getName()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void getNameReturnsNotEmpty(Formatter formatter) { | ||
void getNameReturnsNotEmpty(Formatter formatter) { | ||
assertNotEquals("", formatter.getName()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void getKeyReturnsNotNull(Formatter formatter) { | ||
void getKeyReturnsNotNull(Formatter formatter) { | ||
assertNotNull(formatter.getKey()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void getKeyReturnsNotEmpty(Formatter formatter) { | ||
void getKeyReturnsNotEmpty(Formatter formatter) { | ||
assertNotEquals("", formatter.getKey()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void formatOfNullThrowsException(Formatter formatter) { | ||
void formatOfNullThrowsException(Formatter formatter) { | ||
assertThrows(NullPointerException.class, () -> formatter.format(null)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void formatOfEmptyStringReturnsEmpty(Formatter formatter) { | ||
void formatOfEmptyStringReturnsEmpty(Formatter formatter) { | ||
assertEquals("", formatter.format("")); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void formatNotReturnsNull(Formatter formatter) { | ||
void formatNotReturnsNull(Formatter formatter) { | ||
assertNotNull(formatter.format("string")); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void getDescriptionAlwaysNonEmpty(Formatter formatter) { | ||
void getDescriptionAlwaysNonEmpty(Formatter formatter) { | ||
assertFalse(formatter.getDescription().isEmpty()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getFormatters") | ||
public void getExampleInputAlwaysNonEmpty(Formatter formatter) { | ||
void getExampleInputAlwaysNonEmpty(Formatter formatter) { | ||
assertFalse(formatter.getExampleInput().isEmpty()); | ||
} | ||
|
||
public static Stream<Formatter> getFormatters() { | ||
// all classes implementing {@link net.sf.jabref.model.cleanup.Formatter} | ||
// sorted alphabetically | ||
// Alternative: Use reflection - https://github.com/ronmamo/reflections | ||
// @formatter:off | ||
return Stream.of( | ||
new CapitalizeFormatter(), | ||
new ClearFormatter(), | ||
new HtmlToLatexFormatter(), | ||
new HtmlToUnicodeFormatter(), | ||
new IdentityFormatter(), | ||
new LatexCleanupFormatter(), | ||
new LatexToUnicodeFormatter(), | ||
new LowerCaseFormatter(), | ||
new MinifyNameListFormatter(), | ||
new NormalizeDateFormatter(), | ||
new NormalizeMonthFormatter(), | ||
new NormalizeNamesFormatter(), | ||
new NormalizePagesFormatter(), | ||
new OrdinalsToSuperscriptFormatter(), | ||
new ProtectTermsFormatter(protectedTermsLoader), | ||
new RegexFormatter(), | ||
new RemoveBracesFormatter(), | ||
new SentenceCaseFormatter(), | ||
new TitleCaseFormatter(), | ||
new UnicodeToLatexFormatter(), | ||
new UnitsToLatexFormatter(), | ||
new UpperCaseFormatter()); | ||
|
||
// @formatter:on | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does not make any sense does it?
The method returns an optional. So you can directly return formatter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no formatter is found, then we still want to try the switch at the end. I now reordered the code a bit and it should be clearer now. Good point.