Skip to content

Conversation

@marko-kriskovic
Copy link
Owner

Summary

This PR fixes issue #18 where tests were failing due to an inverted null check in the mapToJson method.

Problem

The mapToJson method in JsonMapConverter.java had a logic error on line 41:

if (map != null) {
    throw new IllegalArgumentException("Map cannot be null");
}

This condition was backwards - it was throwing an exception when the map was NOT null, instead of when it WAS null.

Impact

This bug caused 5 test failures:

  1. testMapToJson_SimpleMap (line 78) - Failed because valid map triggered exception
  2. testMapToJson_NestedMap (line 97) - Failed because valid map triggered exception
  3. testMapToJson_EmptyMap (line 110) - Failed because valid empty map triggered exception
  4. testMapToJson_NullInput (line 118) - Failed because null input did NOT trigger exception
  5. testRoundTrip_JsonToMapToJson (line 144) - Failed because valid map triggered exception

Solution

Changed line 41 from:

if (map != null) {

To:

if (map == null) {

This simple fix corrects the logic so that:

  • ✅ Valid maps are processed normally
  • ✅ Null maps throw IllegalArgumentException as expected

Testing

All 5 previously failing tests should now pass with this fix.

Fixes #18

The mapToJson method had an inverted null check condition on line 41.
It was throwing an exception when map != null instead of when map == null.

This caused all tests with valid maps to fail, and the null input test
to fail because no exception was thrown for null input.

Changed: if (map != null) to if (map == null)

Fixes #18
@marko-kriskovic
Copy link
Owner Author

Please fill the body of the Pull Request

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.

Testovi padaju, ne znam zašto

2 participants