-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refactor StringUtilTest to use parameterized tests #14126
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
Conversation
|
In the meantime another PR was merged, which moved the StringUtil classes to tbe logic package . Please update your branch and adapt to the changes and follow the code style |
jablib/src/test/java/org/jabref/model/strings/StringUtilTest.java
Outdated
Show resolved
Hide resolved
This reverts commit c7dd338.
jablib/src/test/java/org/jabref/logic/util/strings/StringUtilTest.java
Outdated
Show resolved
Hide resolved
jablib/src/test/java/org/jabref/logic/util/strings/StringUtilTest.java
Outdated
Show resolved
Hide resolved
koppor
left a comment
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.
Much, much better!
I have some small things which would make the tests even better. Maybe, you can do that, too?
| // assertArrayEquals(stringArray2res, StringUtil.decodeStringDoubleArray(encStringArray2)); | ||
| assertArrayEquals(new String[][] {{"a", ":b"}, {"c;", "d"}}, StringUtil.decodeStringDoubleArray("a:\\:b;c\\;:d")); | ||
| @ParameterizedTest | ||
| @MethodSource("provideDecodeStringDoubleArrayData") |
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.
| @MethodSource("provideDecodeStringDoubleArrayData") | |
| @MethodSource |
| assertFalse(StringUtil.isInCurlyBrackets("}")); | ||
| assertFalse(StringUtil.isInCurlyBrackets("a{}a")); | ||
| assertFalse(StringUtil.isInCurlyBrackets("{\\AA}sa {\\AA}Stor{\\aa}")); | ||
| static Stream<Arguments> provideDecodeStringDoubleArrayData() { |
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.
Name the method the same as the "calling" method.
| static Stream<Arguments> provideDecodeStringDoubleArrayData() { | |
| static Stream<Arguments> decodeStringDoubleArray() { |
| @ParameterizedTest | ||
| @CsvSource(textBlock = """ | ||
| false, | ||
| true, {} | ||
| true, {a} | ||
| true, '{a{a}}' | ||
| true, '{{\\AA}sa {\\AA}Stor{\\aa}}' | ||
| false, { | ||
| false, } | ||
| false, a{}a | ||
| false, '{\\AA}sa {\\AA}Stor{\\aa}' | ||
| """) | ||
| void isInCurlyBrackets(boolean expected, String input) { | ||
| assertEquals(expected, StringUtil.isInCurlyBrackets(input)); | ||
| } |
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.
Split into two tests
isInCurlyBrackets
isNotInCurlyBrackets
| @ParameterizedTest | ||
| @CsvSource(textBlock = """ | ||
| false, | ||
| true, [] | ||
| true, [a] | ||
| false, [ | ||
| false, ] | ||
| false, a[]a | ||
| """) | ||
| void isInSquareBrackets(boolean expected, String input) { | ||
| assertEquals(expected, StringUtil.isInSquareBrackets(input)); | ||
| } |
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.
See above (split into two tests)
| @Test | ||
| void intValueOfSingleDigit() { | ||
| assertEquals(1, StringUtil.intValueOf("1")); | ||
| assertEquals(2, StringUtil.intValueOf("2")); | ||
| assertEquals(8, StringUtil.intValueOf("8")); | ||
| @ParameterizedTest | ||
| @CsvSource(textBlock = """ | ||
| false, | ||
| true, "" | ||
| true, "a" | ||
| false, " | ||
| false, a""a | ||
| """) | ||
| void isInCitationMarks(boolean expected, String input) { | ||
| assertEquals(expected, StringUtil.isInCitationMarks(input)); | ||
| } |
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.
See above (split into two tests)
koppor
left a comment
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.
I fixed for myself to keep things going. Now, its ready for merge.
* upstream/main: (30 commits) Chore(deps): Bump io.github.classgraph:classgraph from 4.8.181 to 4.8.184 in /versions (#14304) Chore(deps): Bump com.fasterxml:aalto-xml in /versions (#14311) Chore(deps): Bump commons-io:commons-io in /versions (#14310) Chore(deps): Bump org.apache.maven.plugins:maven-surefire-plugin (#14298) Disable fetcher-gui-test (#14308) Chore(deps): Bump com.dlsc.gemsfx:gemsfx in /versions (#14307) No labels for dependeabot updates Fix fallback window height from 786 to 768 (#14295) Chore(deps): Bump com.fasterxml.jackson.dataformat:jackson-dataformat-yaml (#14306) Chore(deps): Bump org.apache.maven.plugins:maven-compiler-plugin (#14302) Chore(deps): Bump org.apache.maven.plugins:maven-deploy-plugin (#14300) Chore(deps): Bump org.apache.maven.plugins:maven-clean-plugin (#14299) Chore(deps): Bump jablib/src/main/resources/csl-styles (#14296) Chore(deps): Bump com.vanniktech.maven.publish in /jablib (#14303) Chore(deps): Bump org.apache.maven.plugins:maven-project-info-reports-plugin (#14297) Update all dependencies (#14301) Prepare maven3 example project (#14294) Refactor StringUtilTest to use parameterized tests (#14126) Try to fix download of pr_number Fix workflow names ...
* Parameterize tests (issue JabRef#676) * Remove unnecessary quotes in CSV tests * Apply IntelliJ auto-format * Fix indentation in StringUtilTest * Fix code formatting in StringUtilTest * Remove csl-styles/locales file * Use text blocks and fix formatting * Revert "Remove csl-styles/locales file" This reverts commit c7dd338. * Fix format issue in textblock test * Refactor tests to use text block format * Fix text block indentation * Address review comments --------- Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
Refs #676
This PR refactors
StringUtilTestto use parameterized tests (@CsvSourceand@MethodSource) following the one-assertion-per-test guideline.Note: My classmates are also contributing to this issue.
@espertusnu
How to test:
./gradlew :jablib:test --tests org.jabref.model.strings.StringUtilTest
Mandatory checks
CHANGELOG.mdin a way that is understandable for the average user (if change is visible to the user)