Skip to content

Conversation

Jenish-1235
Copy link

@Jenish-1235 Jenish-1235 commented Aug 29, 2025

Closes #13709

  • Added clearer asserts, resource null-checks, CLI return-code checks and safe System.out.
  • Enabled ArgumentProcessorTest in jabkit again.

Steps to test

  • To run only this test class: ./gradlew :jabkit:test --tests "org.jabref.cli.ArgumentProcessorTest"
  • To run the whole module tests: ./gradlew :jabkit:test

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.

Comment on lines 78 to 83
URL originUrl = ArgumentProcessorTest.class.getResource("origin.bib");
assertNotNull(originUrl, "Test resource origin.bib not found on classpath");
String fullBib = Path.of(originUrl.toURI()).toAbsolutePath().toString();

URL auxUrl = ArgumentProcessorTest.class.getResource("paper.aux");
assertNotNull(auxUrl, "Test resource paper.aux not found on classpath");
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is not correct.
Test should assert if auxImport works and not if Path.of or getResource works (the are covered by the jdk test suite) or if the resources are there.
If the test fails, because the test resources are not there, this should be "more dramatic" than "just" to assert if the logic does not work. This is a different scope and a different level of abstraction.

Copy link
Author

Choose a reason for hiding this comment

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

Also can you confirm about auxImport test ? I am looking for solution to put the @BeforeAll annotation to checkTestResources() and remove per-test assertNotNull calls from auxImport test and it will be performed by class-level check. Am I thinking in right direction ?

@calixtus
Copy link
Member

Just a quick thought in between things

@Jenish-1235
Copy link
Author

Sure, I'll fix it. Thanks

@koppor
Copy link
Member

koppor commented Aug 30, 2025

@Jenish-1235 Some small comment on the commit message - a commit message should be able to form a corerct sentence in case following is put BEFORE the message: "If applied, this commit will".

Update: Link: https://www.gitkraken.com/learn/git/best-practices/git-commit-message#using-imperative-verb-form

@Jenish-1235
Copy link
Author

@Jenish-1235 Some small comment on the commit message - a commit message should be able to form a corerct sentence in case following is put BEFORE the message: "If applied, this commit will".

Update: Link: https://www.gitkraken.com/learn/git/best-practices/git-commit-message#using-imperative-verb-form

Sure, I'll take care of this as well.

@Jenish-1235 Jenish-1235 changed the title added assert messages and enabled consistency check test in ArgumentP… add assert messages and enable consistency check test in ArgumentP… Sep 2, 2025
@Jenish-1235 Jenish-1235 force-pushed the task-get-test-of-consistency-check-running-again branch from fa0c7a0 to 52c6ba4 Compare September 2, 2025 21:13
// Validate the produced bib can be parsed and contains at least one entry
BibtexImporter importer = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor());
List<BibEntry> entries = importer.importDatabase(outputBib).getDatabase().getEntries();
assertTrue(entries != null && !entries.isEmpty(), "Expected output bib to contain at least one entry");
Copy link
Member

Choose a reason for hiding this comment

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

Typically, we match List.of(entry, ...) to compare the contents. I can relate that this is not necessary here.

You can keep the idea assertFalse(entries.isEmpty() -- the non-null is implicitly checked.

We typically also do not have assertion text, but since AI always generates it, it is OK to keep.

Copy link
Author

Choose a reason for hiding this comment

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

While, I wrote the initial code as you mentioned as per typical style and upon using AI tools for code review, this changes were suggested. I will be open to learn the nuances of both, and make changes if needed.

Copy link
Author

Choose a reason for hiding this comment

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

Being a new contributor, I wish to learn if this test-style is better in coding practices as entries won't be empty right ?

assertFalse(entries.isEmpty(), "Expected output bib to contain at least one entry");

Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib"))
.toURI()
);
Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib"))
Copy link
Member

Choose a reason for hiding this comment

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

There is also the test at the beginning - not sure why this check is added here again.

@Jenish-1235 Jenish-1235 requested a review from koppor September 3, 2025 19:00
@calixtus calixtus changed the title add assert messages and enable consistency check test in ArgumentP… Enhance consistency check tests Sep 3, 2025
Copy link

trag-bot bot commented Sep 4, 2025

@trag-bot didn't find any issues in the code! ✅✨

@subhramit
Copy link
Member

@Jenish-1235 you don't need to merge main so often on Github. If you see here on GitHub that there is a conflict, that's when you should resolve and merge as soon as feasible.

@Jenish-1235
Copy link
Author

Alright will follow that. While as a practice I was trying to keep the branch updated.

@subhramit
Copy link
Member

Alright will follow that. While as a practice I was trying to keep the branch updated.

That is a good practice, but the people subscribed to the PR will keep receiving emails.
Better way - You can do that on your local with git pull upstream main - that won't create noise here on GitHub. When you are also done with your changes, you can directly push.

@Jenish-1235
Copy link
Author

Ahh got it , thanks for guiding 😄

Comment on lines -76 to +88
void auxImport(@TempDir Path tempDir) throws URISyntaxException {
String fullBib = Path.of(ArgumentProcessorTest.class.getResource("origin.bib").toURI()).toAbsolutePath().toString();
String auxFile = Path.of(ArgumentProcessorTest.class.getResource("paper.aux").toURI()).toAbsolutePath().toString();
void auxImport(@TempDir Path tempDir) throws IOException {
InputStream originIs = ArgumentProcessorTest.class.getResourceAsStream("origin.bib");
InputStream auxIs = ArgumentProcessorTest.class.getResourceAsStream("paper.aux");
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? The tests worked bevor, didn't they?

assertTrue(Files.exists(outputBib));
BibtexImporter importer = new BibtexImporter(importFormatPreferences, new DummyFileUpdateMonitor());
List<BibEntry> entries = importer.importDatabase(outputBib).getDatabase().getEntries();
assertTrue(entries != null && !entries.isEmpty(), "Expected output bib to contain at least one entry");
Copy link
Member

Choose a reason for hiding this comment

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

Do assertNotEquals(List.of(), entries);; -- null check is included in assertNotEquals.

IntelliJ will output the diff better in case of an error.

Comment on lines -95 to +117
Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib"))
.toURI()
);
Objects.requireNonNull(ArgumentProcessorTest.class.getResource("ArgumentProcessorTestExportMatches.bib"))
.toURI());
Copy link
Member

Choose a reason for hiding this comment

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

Also remove requireNonNull - to have the tests as clean as the other ones.

Comment on lines +65 to +69
@ParameterizedTest(name = "Resource {0} is available on classpath")
@CsvSource({"origin.bib", "paper.aux", "ArgumentProcessorTestExportMatches.bib"})
void checkTestResourcesParam(String resource) {
assertNotNull(ArgumentProcessorTest.class.getResource(resource), "Required test resource missing from classpath: " + resource);
}
Copy link
Member

Choose a reason for hiding this comment

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

Hi, FYI: We had some discussion in the devcal about this smoke test.
We came to the conclusion, that usually these tests are not neccessary.
It came down to that: JUnit is for testing code, not your build system: Using JUnit to check whether the resources are placed correctly is redundant as the build tool is already designed to manage that.
And Classpath/resource loading failures will show up anyway: If a test relies on a missing resource, it will throw an exception and fail.
So this is not really a unit test, but probably more of an integration test.
But, as we are always paranoid about our test setup, we will leave it in. 😄

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.

Get test of consistency check running again
4 participants