Skip to content

Refactor some formats tests to use parameterized tests#14558

Merged
koppor merged 7 commits into
JabRef:mainfrom
merlinymy:contribution-to-issue676
Dec 11, 2025
Merged

Refactor some formats tests to use parameterized tests#14558
koppor merged 7 commits into
JabRef:mainfrom
merlinymy:contribution-to-issue676

Conversation

@merlinymy

Copy link
Copy Markdown
Contributor

Refs JabRef#676
I am part of a Java graduate school class. My classmates will submit other PRs that address this issue as well.

This PR refactors multiple test classes to follow the one-assertion-per-test guideline and improve overall test readability and maintainability. Parameterized tests (@CsvSource) were introduced where appropriate to replace repetitive assertions.

Steps to test
To test this code run:

Steps to test

./gradlew :jablib:test \ --tests org.jabref.logic.layout.format.AuthorAndsReplacerTest \ --tests org.jabref.logic.layout.format.AuthorFirstLastOxfordCommasTest \ --tests org.jabref.logic.layout.format.AuthorLastFirstAbbrOxfordCommasTest \ --tests org.jabref.logic.layout.format.AuthorLastFirstAbbreviatorTest \ --tests org.jabref.logic.layout.format.RemoveBracketsTest \ --tests org.jabref.logic.layout.format.RemoveLatexCommandsFormatterTest

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.

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Dec 9, 2025
assertEquals("bla", LayoutEntry.parseMethodsCalls("bla,foo").getFirst().getFirst());
assertEquals("foo", LayoutEntry.parseMethodsCalls("bla,foo").get(1).getFirst());
@ParameterizedTest
@CsvSource(delimiterString = "->", textBlock = """

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We like the default separator"," more 😅

Moreover with -> the intention "expected" and "input" is wrong.

assertEquals("test", LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").getFirst().get(1));
assertEquals("fark", LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1).get(1));
@ParameterizedTest
@CsvSource(delimiterString = "->", textBlock = """

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here, one could use ; as delimiter

One could also use ' to sourround the string

assertEquals("fark", LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1).get(1));
@ParameterizedTest
@CsvSource(delimiterString = "->", textBlock = """
bla -> foo -> test -> fark -> bla(\"test\"),foo(\"fark\")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for " in CSV AFAIK

@github-actions github-actions Bot removed the status: changes-required Pull requests that are not yet complete label Dec 10, 2025
Comment on lines +77 to +81
@CsvSource(textBlock = """
bla , bla
bla , bla
_bla.bla.blub , _bla.bla.blub
""")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is more readable, but reads strange as there is a space before the comma

What about

bla, bla

? This would make it more close to "natural" sentences.

@ParameterizedTest
@CsvSource(textBlock = """
bla, bla
bla, bla

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't see in the first review that the second test case was `bla,'. Note the final comma! You removed it while converting. I think, it should be possible to get this in again with following change:

Suggested change
bla, bla
bla, 'bla,'

assertEquals("test", LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").getFirst().get(1));
assertEquals("fark", LayoutEntry.parseMethodsCalls("bla(test),foo(fark)").get(1).get(1));
@ParameterizedTest
@CsvSource(delimiterString = ";", textBlock = """

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Test caes in one package should be consistent. Below, you used , and '. Here, you use " and '. Please the remove the explicit delimiterString ";" here and change ";" to "," below. Since you use ', it should work.

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Dec 10, 2025
@calixtus calixtus changed the title Refactor tests to use parameterized tests Refactor some formats tests to use parameterized tests Dec 10, 2025
@github-actions github-actions Bot removed the status: changes-required Pull requests that are not yet complete label Dec 10, 2025
Comment on lines -91 to +87
assertEquals(2, LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").size());
assertEquals("bla", LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").getFirst().getFirst());
assertEquals("foo", LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1).getFirst());
assertEquals("test", LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").getFirst().get(1));
assertEquals("fark", LayoutEntry.parseMethodsCalls("bla(\"test\"),foo(\"fark\")").get(1).get(1));
@Test

@koppor koppor Dec 10, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These whole tests seem to got lost. I don't find a line

'bla("test"),foo("fark")'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, Thank you:) It should be fixed now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@merlinymy Are you really using "Good catch" when communicating with others? Imaging you are asking a friend to review text for you and she finds something. You really say "good catch"? Does this change if you are taking an assignment? You are handing in an exam and then you talk to the teacher. Do you really say "good catch" if she recognizes a wrong answer in your exam?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is entirely on me, not Merlin. I recommended documents (such as How To Give a Great Code Review) that advise such responses. We're in Cailfornia, where we tend to be informal and disregard hierarchy. I will advise my students in the future that it is better to err on the side of formality.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@espertusnu Thank you for clarification. Normally, only ChatGPT creates such a text. And we have very bad experiences in LLM-generated answers. Thus, I am bit biased against "Good catch" :)

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Dec 10, 2025
@github-actions github-actions Bot removed the status: changes-required Pull requests that are not yet complete label Dec 11, 2025
koppor
koppor previously approved these changes Dec 11, 2025

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have no energy to request another change and check if the update was correct. Sometimes, new errors come with new commits.

Please, in future, recheck the diff for your self

It is obvious that @CsvSource could have been used at one more place.

Comment on lines +98 to +100
bla, foo, test, fark, 'bla("test"),foo("fark")'
bla, foo, test, fark, 'bla(test),foo(fark)'
""")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A perfect PR would have reorded things to make if more reacble

bla, test, foo, fark

But it is OK as is.

@koppor koppor added this pull request to the merge queue Dec 11, 2025
@koppor koppor removed this pull request from the merge queue due to a manual request Dec 11, 2025
@koppor

koppor commented Dec 11, 2025

Copy link
Copy Markdown
Member

Update: I finished the PR for myself 😅. Maybe you learn something from the diff.

@koppor koppor enabled auto-merge December 11, 2025 09:59
@koppor koppor added this pull request to the merge queue Dec 11, 2025
Merged via the queue into JabRef:main with commit b6ab730 Dec 11, 2025
48 checks passed
shubhamk0205 pushed a commit to shubhamk0205/jabref that referenced this pull request Dec 11, 2025
* Parameterize tests (issue JabRef#676)

* Address code review feedback

* Fix code style

* Remove spaces before delimiter in CSV test data

* Restore trailing comma in test cases

* Add missing test case

* Adress review comments

---------

Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
Siva-Sai22 pushed a commit to Siva-Sai22/jabref that referenced this pull request Dec 19, 2025
* Parameterize tests (issue JabRef#676)

* Address code review feedback

* Fix code style

* Remove spaces before delimiter in CSV test data

* Restore trailing comma in test cases

* Add missing test case

* Adress 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants