Skip to content

Conversation

@Shanaya-1981
Copy link
Contributor

@Shanaya-1981 Shanaya-1981 commented Oct 21, 2025

Refs #676

This PR refactors StringUtilTest to use parameterized tests (@CsvSource and @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

  • I own the copyright of the code submitted and I license it under the MIT license
  • [/] I manually tested my changes in running JabRef (always required)
  • [/] I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (if change is visible to the user)
  • [/] I described the change in CHANGELOG.md in a way that is understandable for the average user (if change is visible to the user)
  • I checked the user documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request updating file(s) in https://github.com/JabRef/user-documentation/tree/main/en.

@Siedlerchr
Copy link
Member

Siedlerchr commented Oct 28, 2025

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

@Siedlerchr Siedlerchr added dev: testing Related to tests status: changes-required Pull requests that are not yet complete labels Oct 28, 2025
@Siedlerchr
Copy link
Member

Copy link
Member

@koppor koppor left a 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@MethodSource("provideDecodeStringDoubleArrayData")
@MethodSource

assertFalse(StringUtil.isInCurlyBrackets("}"));
assertFalse(StringUtil.isInCurlyBrackets("a{}a"));
assertFalse(StringUtil.isInCurlyBrackets("{\\AA}sa {\\AA}Stor{\\aa}"));
static Stream<Arguments> provideDecodeStringDoubleArrayData() {
Copy link
Member

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.

Suggested change
static Stream<Arguments> provideDecodeStringDoubleArrayData() {
static Stream<Arguments> decodeStringDoubleArray() {

Comment on lines 228 to 242
@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));
}
Copy link
Member

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

Comment on lines 244 to 255
@ParameterizedTest
@CsvSource(textBlock = """
false,
true, []
true, [a]
false, [
false, ]
false, a[]a
""")
void isInSquareBrackets(boolean expected, String input) {
assertEquals(expected, StringUtil.isInSquareBrackets(input));
}
Copy link
Member

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)

Comment on lines 234 to 267
@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));
}
Copy link
Member

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)

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Nov 13, 2025
Copy link
Member

@koppor koppor left a 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.

@koppor koppor enabled auto-merge November 13, 2025 08:45
@koppor koppor added this pull request to the merge queue Nov 13, 2025
Merged via the queue into JabRef:main with commit d6fda1d Nov 13, 2025
45 checks passed
Siedlerchr added a commit that referenced this pull request Nov 13, 2025
* 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
  ...
merlinymy pushed a commit to merlinymy/jabref that referenced this pull request Nov 19, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev: testing Related to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants