Refactor some formats tests to use parameterized tests#14558
Conversation
| assertEquals("bla", LayoutEntry.parseMethodsCalls("bla,foo").getFirst().getFirst()); | ||
| assertEquals("foo", LayoutEntry.parseMethodsCalls("bla,foo").get(1).getFirst()); | ||
| @ParameterizedTest | ||
| @CsvSource(delimiterString = "->", textBlock = """ |
There was a problem hiding this comment.
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 = """ |
There was a problem hiding this comment.
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\") |
| @CsvSource(textBlock = """ | ||
| bla , bla | ||
| bla , bla | ||
| _bla.bla.blub , _bla.bla.blub | ||
| """) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:
| 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 = """ |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
These whole tests seem to got lost. I don't find a line
'bla("test"),foo("fark")'
There was a problem hiding this comment.
Good catch, Thank you:) It should be fixed now
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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" :)
| bla, foo, test, fark, 'bla("test"),foo("fark")' | ||
| bla, foo, test, fark, 'bla(test),foo(fark)' | ||
| """) |
There was a problem hiding this comment.
A perfect PR would have reorded things to make if more reacble
bla, test, foo, fark
But it is OK as is.
|
Update: I finished the PR for myself 😅. Maybe you learn something from the diff. |
* 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>
* 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>
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.RemoveLatexCommandsFormatterTestMandatory checks
CHANGELOG.mdin a way that is understandable for the average user (if change is visible to the user)