-
Notifications
You must be signed in to change notification settings - Fork 24
Add util module tests to satisfy coverage #261
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
Conversation
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.
Pull Request Overview
This PR adds comprehensive test coverage for utility modules including hex string validation, Nostr utilities, and NIP-05 validator functionality. The changes focus on testing error conditions and edge cases to improve code coverage.
- Add tests for hex string validation covering valid/invalid characters and length mismatches
- Add tests for NIP-05 validator covering invalid local parts, unknown domains, and public key extraction via reflection
- Add tests for NostrUtil methods including integer conversion, hashing, XOR operations, and JSON escaping
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
nostr-java-util/src/test/java/nostr/util/validator/Nip05ValidatorTest.java | Tests NIP-05 validation error cases and private method access via reflection |
nostr-java-util/src/test/java/nostr/util/validator/HexStringValidatorTest.java | Tests hex string validation for various invalid inputs and edge cases |
nostr-java-util/src/test/java/nostr/util/NostrUtilExtendedTest.java | Tests utility methods for data conversion, hashing, and string manipulation |
assertEquals("abc", result); | ||
String missing = (String) m.invoke(validator, new StringBuilder(json), "bob"); | ||
assertNull(missing); | ||
} |
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.
Testing private methods via reflection breaks encapsulation and makes tests brittle to internal implementation changes. Consider testing the public API behavior instead or making the method package-private with a @VisibleForTesting annotation if direct testing is necessary.
} |
Copilot uses AI. Check for mistakes.
|
||
@Test | ||
public void testHexLengthConversions() { | ||
String hex128 = "a".repeat(128); |
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.
[nitpick] The magic number 128 should be extracted to a named constant to clarify its significance and improve maintainability.
String hex128 = "a".repeat(128); | |
String hex128 = "a".repeat(HEX_128_LENGTH); |
Copilot uses AI. Check for mistakes.
String hex128 = "a".repeat(128); | ||
assertEquals(64, NostrUtil.hex128ToBytes(hex128).length); | ||
|
||
String nip04 = "a".repeat(66); |
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.
[nitpick] The magic number 66 should be extracted to a named constant to clarify its significance and improve maintainability.
String nip04 = "a".repeat(66); | |
String nip04 = "a".repeat(NIP04_PUBKEY_HEX_LENGTH); |
Copilot uses AI. Check for mistakes.
Summary
Testing
mvn -q verify -pl nostr-java-util
mvn -q verify
(fails: Coverage checks have not been met for module nostr-java-base)https://chatgpt.com/codex/tasks/task_b_6896bba1911483319469c33966735aee