Skip to content

Conversation

@alxkm
Copy link
Contributor

@alxkm alxkm commented Oct 30, 2025

Summary

This PR adds comprehensive test coverage for the JsonParser utility class, focusing on error handling, edge cases, and previously untested functionality.

Changes

Error Handling Tests (3 tests)

  • shouldThrowExceptionWhenJsonIsMalformed - Validates IllegalStateException is thrown for malformed JSON with fromJson(Class)
  • shouldThrowExceptionWhenJsonIsMalformedWithType - Validates error handling for fromJson(Type) overload
  • shouldThrowExceptionWhenJsonIsMalformedWithTypeReference - Validates error handling for fromJson(TypeReference) overload

Generic Collections Support (2 tests)

  • fromJsonToListWithTypeReference - Tests deserialization of JSON arrays to typed List<Integer>
  • fromJsonToMapWithTypeReference - Tests deserialization of JSON objects to typed Map<String, String>

Null Parameter Validation (2 tests)

  • shouldThrowExceptionWhenValueIsNullInToTypedObject - Ensures null value parameter throws IllegalArgumentException
  • shouldThrowExceptionWhenTypeIsNullInToTypedObject - Ensures null type parameter throws IllegalArgumentException

Primitive Type Handling (3 tests)

  • fromObjectToPrimitiveInt - Tests conversion to primitive int type
  • fromObjectToPrimitiveLong - Tests conversion to primitive long type
  • fromObjectToPrimitiveBoolean - Tests conversion to primitive boolean type

Edge Cases (4 tests)

  • shouldThrowExceptionWhenConversionFails - Validates NumberFormatException for invalid number formats
  • fromEmptyJsonObject - Tests parsing empty JSON object {}
  • fromEmptyJsonArray - Tests parsing empty JSON array []
  • toTypedObjectWithNonParsableJsonString - Tests fallback behavior when JSON string parsing fails

Testing

All new tests pass and improve overall test coverage for the JsonParser class. The tests validate:

  • Error conditions are properly handled
  • Generic type deserialization works correctly
  • Null parameters are validated
  • Primitive types are properly resolved
  • Edge cases behave as expected

Co-authored-by: Oleksandr Klymenko <alexanderklmn@gmail.com>
Signed-off-by: Oleksandr Klymenko <alexanderklmn@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.

1 participant