Skip to content

Add unit test for Mandrel.getPkgFromJson#148

Open
zakkak wants to merge 1 commit intofoojayio:mainfrom
zakkak:2026-03-26-mandrel-unittests
Open

Add unit test for Mandrel.getPkgFromJson#148
zakkak wants to merge 1 commit intofoojayio:mainfrom
zakkak:2026-03-26-mandrel-unittests

Conversation

@zakkak
Copy link
Copy Markdown

@zakkak zakkak commented Mar 26, 2026

Test parsing of GitHub release JSON using 5 representative Mandrel
releases (JDK 17/21/23/24/25). Verifies asset filtering, platform
detection, archive types, JDK version extraction, prerelease skipping,
and non-matching filename handling.

Requires FOOJAY_API_ENVIRONMENT=test to avoid MQTT initialization.

Summary by CodeRabbit

  • Tests
    • Added end-to-end tests for Mandrel distribution parsing: verifies release parsing produces the expected number of packages per release, skips prerelease releases, ignores non-matching asset filenames, and validates package metadata (distribution, package type, release status, Java version, filename prefix, download URI, resolved OS/architecture) and expected platform/archive counts.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d118c65-a0a9-4e05-af48-da4647780271

📥 Commits

Reviewing files that changed from the base of the PR and between 8bdd409 and c350f13.

📒 Files selected for processing (1)
  • src/test/java/io/foojay/api/distribution/MandrelTest.java
✅ Files skipped from review due to trivial changes (1)
  • src/test/java/io/foojay/api/distribution/MandrelTest.java

📝 Walkthrough

Walkthrough

Adds a new JUnit 5 test class MandrelTest that exercises Mandrel.getPkgFromJson(...) using synthetic GitHub release JSON; tests verify parsing of releases, prerelease filtering, and filename-matching behavior, and assert package fields, platform counts, and archive types.

Changes

Cohort / File(s) Summary
Mandrel Distribution Tests
src/test/java/io/foojay/api/distribution/MandrelTest.java
New JUnit 5 test class. Adds three public test methods (getPkgFromJsonParsesReleases, getPkgFromJsonSkipsPrerelease, getPkgFromJsonSkipsNonMatchingFilenames), helper methods (buildReleaseJson, buildStandardAssets), and a private static MANDREL instance. Tests build synthetic GitHub release JSON with assets and assert package counts, distro/type/status, JDK versions, filenames, download URIs, architectures/OS, platform totals, and archive-type totals. Skips prerelease and non-matching filename cases are verified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 I hop through JSON, sniff each release,
I count the platforms, make the noise cease.
Prereleases stay out, filenames must fit,
Four packages found — that's a lovely bit.
Cheers from a rabbit, testing is lit!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add unit test for Mandrel.getPkgFromJson' is concise, clear, and directly describes the main change: adding a new test class with comprehensive tests for the Mandrel.getPkgFromJson method.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/test/java/io/foojay/api/distribution/MandrelTest.java (1)

150-153: Consider using assertNotEquals for better failure diagnostics.

Using assertNotEquals is more idiomatic for JUnit and provides better failure messages by showing the actual value.

Proposed fix
-                assertTrue(pkg.getArchitecture() != Architecture.NONE,
-                        "Architecture should be resolved for " + pkg.getFilename());
-                assertTrue(pkg.getOperatingSystem() != OperatingSystem.NONE,
-                        "OS should be resolved for " + pkg.getFilename());
+                assertNotEquals(Architecture.NONE, pkg.getArchitecture(),
+                        "Architecture should be resolved for " + pkg.getFilename());
+                assertNotEquals(OperatingSystem.NONE, pkg.getOperatingSystem(),
+                        "OS should be resolved for " + pkg.getFilename());

This would require adding:

import static org.junit.jupiter.api.Assertions.assertNotEquals;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/io/foojay/api/distribution/MandrelTest.java` around lines 150 -
153, Replace the two negative assertions in MandrelTest
(assertTrue(pkg.getArchitecture() != Architecture.NONE, ...) and
assertTrue(pkg.getOperatingSystem() != OperatingSystem.NONE, ...)) with positive
JUnit assertions using assertNotEquals to improve failure messages; import
static org.junit.jupiter.api.Assertions.assertNotEquals and call
assertNotEquals(Architecture.NONE, pkg.getArchitecture(), "Architecture should
be resolved for " + pkg.getFilename()) and assertNotEquals(OperatingSystem.NONE,
pkg.getOperatingSystem(), "OS should be resolved for " + pkg.getFilename()) to
preserve messages while exposing actual values on failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/test/java/io/foojay/api/distribution/MandrelTest.java`:
- Around line 97-98: The test method name getPkgFromJsonParsesLatest10Releases
in MandrelTest is misleading because it asserts 5 releases; rename the method to
getPkgFromJsonParsesLatest5Releases (or alternatively update the test data to
include 10 releases) and update any test references or documentation accordingly
so the method name matches the asserted behavior.

---

Nitpick comments:
In `@src/test/java/io/foojay/api/distribution/MandrelTest.java`:
- Around line 150-153: Replace the two negative assertions in MandrelTest
(assertTrue(pkg.getArchitecture() != Architecture.NONE, ...) and
assertTrue(pkg.getOperatingSystem() != OperatingSystem.NONE, ...)) with positive
JUnit assertions using assertNotEquals to improve failure messages; import
static org.junit.jupiter.api.Assertions.assertNotEquals and call
assertNotEquals(Architecture.NONE, pkg.getArchitecture(), "Architecture should
be resolved for " + pkg.getFilename()) and assertNotEquals(OperatingSystem.NONE,
pkg.getOperatingSystem(), "OS should be resolved for " + pkg.getFilename()) to
preserve messages while exposing actual values on failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9eafa19-d395-4f0e-a54d-7f059eb05b28

📥 Commits

Reviewing files that changed from the base of the PR and between f3ccc80 and 8bdd409.

📒 Files selected for processing (1)
  • src/test/java/io/foojay/api/distribution/MandrelTest.java

Comment on lines +97 to +98
@Test
public void getPkgFromJsonParsesLatest10Releases() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Misleading test method name: says "10Releases" but tests 5.

The method tests 5 releases (JDK 17, 21, 23, 24, 25), not 10. This mismatch can confuse future maintainers.

Proposed fix
     `@Test`
-    public void getPkgFromJsonParsesLatest10Releases() {
+    public void getPkgFromJsonParsesReleases() {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Test
public void getPkgFromJsonParsesLatest10Releases() {
`@Test`
public void getPkgFromJsonParsesReleases() {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/io/foojay/api/distribution/MandrelTest.java` around lines 97 -
98, The test method name getPkgFromJsonParsesLatest10Releases in MandrelTest is
misleading because it asserts 5 releases; rename the method to
getPkgFromJsonParsesLatest5Releases (or alternatively update the test data to
include 10 releases) and update any test references or documentation accordingly
so the method name matches the asserted behavior.

Test parsing of GitHub release JSON using 5 representative Mandrel
releases (JDK 17/21/23/24/25). Verifies asset filtering, platform
detection, archive types, JDK version extraction, prerelease skipping,
and non-matching filename handling.

Requires FOOJAY_API_ENVIRONMENT=test to avoid MQTT initialization.
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.

1 participant