-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend test coverage #406
Extend test coverage #406
Conversation
* Add more tests for JSON and XML
📝 WalkthroughWalkthroughThe pull request introduces several updates across multiple files, primarily enhancing the test coverage for serialization of various data types, including Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (15)
src/test/resources/org/joda/beans/ser/Address.simplejson (1)
19-32
: Consider reducing data duplication in address objects.The same address data appears multiple times in the file (e.g., the OpenGamma office address). While this might be intentional for testing, consider using references or a more concise structure if the testing framework supports it.
src/test/resources/org/joda/beans/ser/Collections.json (1)
55-64
: The multiset data structure looks good but could benefit from additional test cases.The implementation correctly represents the multiset with proper type annotations and count values. The progressive counts (1, 2, 3) provide good basic coverage.
Consider adding test cases for:
- Empty strings to verify handling of edge cases
- Larger counts to ensure no integer overflow issues
- Unicode characters to validate proper string encoding
"multiset": [[{ "@type": "String", "value": "A" }, 1], [{ "@type": "String", "value": "B" }, 2], [{ "@type": "String", "value": "C" }, 3], [{ + "@type": "String", + "value": "" + }, 1], [{ + "@type": "String", + "value": "🦊" + }, 100]]src/test/resources/org/joda/beans/ser/ImmAddress.simplejson (5)
12-14
: Consider expanding addressList test dataThe addressList contains only a single simple object with just a number field. Consider adding more complex address objects to better test nested object serialisation.
15-15
: Consider documenting magic numbers in codeCountsThe codeCounts array contains pairs of codes and numbers (
["A", 2], ["B", 1]
) without context. Consider adding a comment explaining what these numbers represent for better test maintainability.
63-63
: Consider adding test data to mapInMapThe mapInMap is currently empty ({}). Consider adding nested map structures to improve test coverage of map serialisation.
85-101
: Consider adding grid boundary test casesThe grid structures test typical cases well, but consider adding edge cases:
- Grid coordinates at maximum bounds
- Empty grids
- Single-cell grids
104-104
: Consider using array structure for matrix dataThe matrix currently uses comma-separated strings ("1.1,2.2", "3.2") which might be fragile due to:
- Potential parsing issues with different locale settings
- Less explicit data structure compared to nested arrays
Consider using a nested array structure instead:
-"matrix": ["1.1,2.2", "3.2"] +"matrix": [[1.1, 2.2], [3.2]]src/test/resources/org/joda/beans/ser/Collections.xml (2)
3-15
: Consider expanding test data varietyWhilst the current test data is consistent, consider adding:
- Empty elements
- Null values (if supported)
- Special characters
- Longer strings
This would provide more comprehensive coverage of edge cases.
49-53
: Well-structured Multiset implementationGood use of the count attribute for repeated elements. Consider adding a comment in the corresponding test class to document this XML structure for future maintainers.
src/test/resources/org/joda/beans/ser/ImmAddress.xml (3)
5-6
: Consider improving the formatting of the city fieldThe city value spans multiple lines with escaped characters. For better readability, consider consolidating it onto a single line:
-<city>London & Capital of the World <!> -</city> +<city>London & Capital of the World <!></city>
31-34
: Ensure consistent usage of attributes in codeCountsThe
count
attribute is present in one item but missing in another. For consistent test data, consider either:
- Adding the count attribute to all items
- Removing it entirely if not required for testing
187-194
: Consider adding more test cases to sparse gridThe sparse grid is defined with 5x5 dimensions but only contains a single item. Consider adding more test cases to verify:
- Edge cases (e.g., items at grid boundaries)
- Multiple sparse entries
- Empty rows/columns handling
src/test/java/org/joda/beans/ser/json/TestSerializeJsonSimple.java (2)
94-101
: Consider enhancing test coverage and documentationWhilst the basic test case is well-structured, consider these improvements:
- Add test cases for error scenarios (e.g., malformed addresses)
- Expand the comment "no round trip with simple JSON" to explain why round-trip testing isn't possible
Consider adding:
@Test public void test_writeAddress_withNullFields() throws IOException { Address address = new Address(); // All fields null String json = JodaBeanSer.PRETTY.simpleJsonWriter().write(address); assertEqualsSerialization(json, "/org/joda/beans/ser/AddressNull.simplejson"); }
103-113
: Consider adding edge case testsThe test effectively covers the happy path, but consider adding tests for:
- Edge cases with empty/null optional fields
- Maximum-size maps
- Special characters in map keys/values
Also, consider extracting the map initialisation to a helper method for reuse:
private ImmAddress createTestImmAddress() { return SerTestHelper.testImmAddress().toBuilder() .mapInMap(new HashMap<>()) .beanBeanMap(new HashMap<>()) .build(); }src/test/java/org/joda/beans/ser/xml/TestSerializeXml.java (1)
135-140
: Consider adding documentation for line ending normalisationThe method effectively handles XML comparison with proper line ending normalisation for cross-platform compatibility. Consider adding a brief comment explaining why the line ending normalisation is necessary.
private void assertEqualsSerialization(String xml, String expectedResource) throws IOException { + // Normalise line endings to \n for cross-platform comparison var url = TestSerializeJson.class.getResource(expectedResource); var expected = Resources.asCharSource(url, StandardCharsets.UTF_8).read(); assertThat(xml.trim().replace(System.lineSeparator(), "\n")) .isEqualTo(expected.trim().replace(System.lineSeparator(), "\n")); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (12)
src/test/java/org/joda/beans/ser/SerTestHelper.java
(3 hunks)src/test/java/org/joda/beans/ser/json/TestSerializeJsonSimple.java
(3 hunks)src/test/java/org/joda/beans/ser/xml/TestSerializeXml.java
(4 hunks)src/test/resources/org/joda/beans/ser/Address.simplejson
(1 hunks)src/test/resources/org/joda/beans/ser/Address.xml
(1 hunks)src/test/resources/org/joda/beans/ser/Collections.json
(1 hunks)src/test/resources/org/joda/beans/ser/Collections.simplejson
(1 hunks)src/test/resources/org/joda/beans/ser/Collections.xml
(1 hunks)src/test/resources/org/joda/beans/ser/ImmAddress.json
(1 hunks)src/test/resources/org/joda/beans/ser/ImmAddress.simplejson
(1 hunks)src/test/resources/org/joda/beans/ser/ImmAddress.xml
(1 hunks)src/test/resources/org/joda/beans/ser/ImmOptional.xml
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- src/test/resources/org/joda/beans/ser/Address.xml
- src/test/resources/org/joda/beans/ser/ImmOptional.xml
🧰 Additional context used
📓 Path-based instructions (3)
src/test/java/org/joda/beans/ser/SerTestHelper.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Allow use of
var
keyword when value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/test/java/**/*.java
: For test code, focus on:
- Correctness of test assertions
- Test coverage of edge cases
- Clear test naming and documentation
- Be more lenient with code style and minor optimisations
src/test/java/org/joda/beans/ser/json/TestSerializeJsonSimple.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Allow use of
var
keyword when value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/test/java/**/*.java
: For test code, focus on:
- Correctness of test assertions
- Test coverage of edge cases
- Clear test naming and documentation
- Be more lenient with code style and minor optimisations
src/test/java/org/joda/beans/ser/xml/TestSerializeXml.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Allow use of
var
keyword when value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/test/java/**/*.java
: For test code, focus on:
- Correctness of test assertions
- Test coverage of edge cases
- Clear test naming and documentation
- Be more lenient with code style and minor optimisations
🔇 Additional comments (25)
src/test/resources/org/joda/beans/ser/Collections.simplejson (1)
21-21
: Proper representation of multiset data structure.
The updated multiset value properly represents frequency-based collection data, which enhances the test coverage for serialisation scenarios.
Let's verify consistency with related files:
✅ Verification successful
Multiset representation is consistent across test resources
The multiset structure in Collections.simplejson aligns perfectly with:
- The fully-typed representation in Collections.json
- The test helper's initialisation using ImmutableMultiset.of("A", "B", "C", "B", "C", "C")
The simplified format [["A", 1], ["B", 2], ["C", 3]] correctly represents the same frequency counts as the test helper's implementation, where B appears twice and C appears thrice.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that the multiset representation is consistent across JSON test files
# and that the test helper properly initialises this structure
# Check the corresponding standard JSON file
echo "Checking Collections.json for consistent multiset structure:"
rg -A 3 '"multiset":' src/test/resources/org/joda/beans/ser/Collections.json
# Check the test helper implementation
echo "Checking SerTestHelper for multiset initialisation:"
rg -A 5 'multiset' src/test/java/org/joda/beans/ser/SerTestHelper.java
Length of output: 928
Script:
#!/bin/bash
# Let's get more context from Collections.json to see the complete multiset structure
echo "Full multiset structure from Collections.json:"
rg -A 15 '"multiset":' src/test/resources/org/joda/beans/ser/Collections.json
# Let's also check if there are any other test files that might use multiset
echo "\nSearching for other test files with multiset:"
fd -e json -e simplejson . src/test/resources | xargs rg "multiset"
Length of output: 964
src/test/resources/org/joda/beans/ser/Address.simplejson (5)
9-18
: Good use of null values for testing edge cases.
The addressList
array appropriately includes a null value between two valid addresses, which is excellent for testing null handling in serialization/deserialization.
49-56
: Good variety of data types in extensions object.
The extensions object effectively tests different data types (string, integer, single character, nested object), which is excellent for comprehensive serialization testing.
1-58
: Well-structured test data covering multiple scenarios.
The JSON structure effectively tests:
- Nested objects and arrays
- Null values
- Different data types
- Complex object relationships
- Deep nesting scenarios
This provides good coverage for serialization testing.
4-4
: Consider escaping special characters in the city name.
The city name contains special characters (&
and <!>
). While this is valid JSON, it might cause issues with certain parsers or when the JSON is embedded in XML. Consider using escaped Unicode characters for better compatibility.
33-42
: Verify the necessity of double-nested arrays.
The addressesList
contains an array within an array. Ensure this level of nesting is intentionally testing a specific serialization scenario.
✅ Verification successful
The double-nested array structure is intentionally testing serialization of nested collections.
The codebase shows this is a deliberate design:
- The
addressesList
property is consistently defined asList<List<Address>>
across multiple bean classes (Person, SimplePerson, ImmPerson, etc.) - It has proper validation, getters/setters and builder methods specifically handling the nested list structure
- The test class
TestJodaBeanUtils
explicitly tests serialization of this nested collection type - The property is used to verify JodaBeanUtils' collection type handling capabilities
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if there are test cases specifically testing nested array serialization
# Search for test files that might be using this nested array structure
ast-grep --pattern 'test_$_($$$) {
$$$
addressesList
$$$
}'
Length of output: 67
Script:
#!/bin/bash
# Let's try a different approach to find relevant test files and their content
# First, find the test files
fd "Test.*\.java" src/test
# Then search for any references to addressesList in the codebase
rg "addressesList" -A 5 -B 5
# Also check the actual test resource file content
cat src/test/resources/org/joda/beans/ser/Address.simplejson
Length of output: 118086
src/test/resources/org/joda/beans/ser/ImmAddress.simplejson (2)
64-84
: Well-structured table test data
The table structures provide excellent coverage of both simple and compound data types, with good variation in the test data.
4-4
: Consider sanitising special characters in the city field
The city field contains characters that might cause issues during cross-format serialisation (XML/JSON):
- The ampersand (
&
) might need XML escaping - The
<!>
sequence resembles XML markup - The explicit newline (
\n
) might affect parsing
✅ Verification successful
Special characters are properly handled - no action needed
The XML test file already properly handles the special characters in the city field:
- The ampersand is correctly escaped as
&
- The angle brackets are properly escaped as
<!>
- The newline character is preserved as expected
The JSON and XML test files are consistent and demonstrate correct cross-format serialisation handling.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if there are corresponding XML test files that might be affected
fd -e xml ImmAddress
Length of output: 75
Script:
#!/bin/bash
# Check the content of the XML file to see how special characters are handled
cat src/test/resources/org/joda/beans/ser/ImmAddress.xml
Length of output: 5780
src/test/resources/org/joda/beans/ser/Collections.xml (4)
1-2
: LGTM: Proper XML structure and bean declaration
The XML declaration and bean type specification are correctly formatted.
55-102
: LGTM: Comprehensive interface coverage
Excellent parallel structure between concrete implementations and their interfaces, providing good test coverage for both scenarios.
103-113
: Verify empty wildcard collections testing
The wildcard collections are empty. Please verify that there are corresponding test cases that validate type bounds with actual data.
✅ Verification successful
Let me search for the actual test cases to verify if there are tests with non-empty wildcard collections.
Empty wildcard collections in XML are properly tested with actual data
The empty collections in the XML file are just serialisation templates. The actual test cases in TestImmutable.java
demonstrate proper testing with non-empty collections, including:
- Lists of Calendar objects (
listCal
,listGcal
) - Lists of mixed number types (
2d, 5, 3f
) - Lists of integers (
listInts
) - Lists implementing Comparable interface
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for wildcard-related test cases
rg "WildExtendsT|WildExtendsNumber|WildExtendsComparable" --type java src/test/
Length of output: 29360
Script:
#!/bin/bash
# Search for test cases in TestImmutable.java with context
rg -A 5 "listWildExtendsT|listWildExtendsNumber|listWildExtendsComparable" src/test/java/org/joda/beans/TestImmutable.java
Length of output: 526
36-45
: Verify BiMap value uniqueness constraints
BiMap requires unique values as well as unique keys. The current test data follows this pattern, but we should verify that the test suite includes cases that validate this constraint.
src/test/resources/org/joda/beans/ser/ImmAddress.json (2)
136-136
: LGTM: Enhanced test coverage with additional table entry
The expansion of the simpleTable
array to include multiple entries provides better test coverage whilst maintaining consistent structure and data types.
Line range hint 1-190
: Verify JSON structure validity
The JSON structure is well-formed and maintains proper hierarchical relationships. However, it's worth validating the JSON against the bean's schema to ensure all required fields are present and correctly typed.
✅ Verification successful
JSON structure is valid and matches bean definition
The JSON structure in ImmAddress.json
is valid and correctly represents the ImmAddress
bean class, as evidenced by:
- The JSON is well-formed (confirmed by
jq type
returning "object") - All required properties from
@PropertyDefinition
annotations are present - The file is actively used in serialisation tests that pass validation
- The structure is verified through round-trip testing in
TestSerializeJson
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Validate JSON structure against potential schema files
# and check for consistent formatting
# Look for schema files
fd -e schema.json
# Verify JSON formatting
jq '.' src/test/resources/org/joda/beans/ser/ImmAddress.json > /dev/null
Length of output: 80
Script:
#!/bin/bash
# Let's verify the JSON structure and its relationship with the bean class
# First, find the corresponding bean class
fd -e java "ImmAddress.java"
# Then check the content of the bean class to understand the expected structure
rg -A 5 "class ImmAddress"
# Also check if there are any test files validating this JSON
fd -e java -e groovy "test" | rg -i "immaddress"
# Finally verify if the JSON is well-formed
jq 'type' src/test/resources/org/joda/beans/ser/ImmAddress.json
Length of output: 706
Script:
#!/bin/bash
# Let's examine the bean class properties and test cases
# Check the bean class properties
rg -A 2 "@PropertyDefinition" src/test/java/org/joda/beans/sample/ImmAddress.java
# Look for serialization test cases
rg -A 5 "ImmAddress" src/test/java/org/joda/beans/ser/
# Check if there are any JSON-specific test cases
rg -A 5 "ImmAddress.json" src/test/java/org/joda/beans/
Length of output: 16313
src/test/resources/org/joda/beans/ser/ImmAddress.xml (3)
247-250
: Verify handling of irregular matrix dimensions
The matrix contains rows of different lengths (2 elements vs 1 element). Ensure the serialization tests verify:
- Proper handling of irregular matrices
- Error cases for malformed matrices
- Consistent deserialization behaviour
#!/bin/bash
# Search for matrix-related test cases
rg -A 5 "test.*Matrix"
236-242
: Verify empty collection handling
Multiple collections are defined as empty. Ensure the serialization tests properly verify:
- Null vs empty collection handling
- Deserialization behaviour with empty collections
- Proper initialisation of collections in the bean
#!/bin/bash
# Search for collection handling in tests
ast-grep --pattern 'void test$_(empty|null)$_($$$) {
$$$
}'
47-47
: Verify the currency code usage
Let's ensure the currency code "GBP" is valid and consistently used across the test data.
✅ Verification successful
Let me search for currency-related content to verify the usage of "GBP" in the codebase. The previous command might have failed due to incorrect piping, so I'm breaking it down into more specific searches.
Currency code "GBP" is valid and consistently used
The currency code "GBP" is properly used across the codebase:
- It appears in test XML serialisation files (
ImmAddress.xml
) - It's correctly instantiated using
Currency.getInstance("GBP")
in test helper classes - The usage is consistent between XML serialisation and Java test code
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for currency codes in the codebase to verify consistency
rg -l "Currency" | xargs rg "GBP"
Length of output: 63
Script:
#!/bin/bash
# Search for currency codes in XML files
fd -e xml | xargs rg "Currency.*GBP"
# Search for currency codes in Java files
fd -e java | xargs rg "Currency.*GBP"
# Search for any currency-related test files
fd -e java | xargs rg -l "Currency"
Length of output: 974
src/test/java/org/joda/beans/ser/json/TestSerializeJsonSimple.java (2)
33-33
: LGTM: Import statement is correctly placed
The import for ImmAddress is properly organised and necessary for the new test methods.
123-123
: LGTM: Simplified type casting
Good improvement - removing the redundant cast makes the code cleaner whilst maintaining type safety.
src/test/java/org/joda/beans/ser/xml/TestSerializeXml.java (4)
24-24
: LGTM: Appropriate imports added for XML comparison functionality
The new imports support the XML comparison functionality and are suitable choices for test code.
Also applies to: 52-52
60-60
: LGTM: Enhanced test with proper exception handling and XML comparison
The test now properly declares potential IOExceptions and uses file-based comparison for more robust XML validation.
Also applies to: 64-64
83-87
: LGTM: Consistent improvements across test methods
The changes follow a consistent pattern across all test methods, properly handling IOExceptions and implementing file-based XML comparison.
Also applies to: 97-101, 109-113
Line range hint 60-113
: Verify XML test resources exist
The tests now depend on XML resource files for comparison. Let's verify these files exist.
✅ Verification successful
Let me search for these XML files in the test resources directory specifically, as they might be under src/test/resources
:
All required XML test resources are present and properly structured
All XML test resources referenced in the test methods are present in the correct location under src/test/resources/org/joda/beans/ser/
:
- Address.xml
- Collections.xml
- ImmAddress.xml
- ImmOptional.xml
Each file contains valid XML with the expected bean type declarations, confirming they are properly set up for the serialisation tests.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all referenced XML test resources exist
echo "Checking for required XML test resources..."
for resource in \
"org/joda/beans/ser/Address.xml" \
"org/joda/beans/ser/ImmAddress.xml" \
"org/joda/beans/ser/ImmOptional.xml" \
"org/joda/beans/ser/Collections.xml"
do
if ! fd -t f "${resource##*/}" | grep -q "$resource"; then
echo "Missing resource: $resource"
fi
done
Length of output: 1014
Script:
#!/bin/bash
# Check in test resources directory specifically
echo "Checking test resources directory..."
fd -t f -e xml . src/test/resources/org/joda/beans/ser/
# Also check the content of any found files
for xml in $(fd -t f -e xml . src/test/resources/org/joda/beans/ser/); do
echo "Found file: $xml"
head -n 3 "$xml" 2>/dev/null
done
Length of output: 1952
src/test/java/org/joda/beans/ser/SerTestHelper.java (2)
183-186
: LGTM! Enhanced test coverage with additional table entry.
The change from ImmutableTable.of()
to the builder pattern improves readability and extends test coverage by adding another entry to the table.
211-211
: LGTM! Comprehensive multiset test data added.
The addition of multiset
with varying element frequencies (A×1, B×2, C×3) provides thorough coverage for testing multiset serialisation.
Also applies to: 225-225
Summary by CodeRabbit
New Features
Address
andImmAddress
objects.ImmAddress
,Address
, andImmOptional
, enhancing data representation.Bug Fixes
throws IOException
to relevant methods.Documentation
Chores