Skip to content

Add unit tests - #412

Open
sean-g-rae wants to merge 7 commits into
dnsjava:masterfrom
sean-g-rae:srae/add-unit-tests
Open

sean-g-rae wants to merge 7 commits into
dnsjava:masterfrom
sean-g-rae:srae/add-unit-tests

Conversation

@sean-g-rae

@sean-g-rae sean-g-rae commented Jul 27, 2026

Copy link
Copy Markdown

What: Add unit tests to cover some small gaps that existing in test coverage
How: Making no changes to non-test code, this PR is strictly for adding unit tests.

Note: there is no associated issue.

What: Add unit tests to cover some small gaps that existing in test coverage
How: Making no changes to non-test code, this PR is strictly for adding unit tests.
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.81%. Comparing base (8bed725) to head (a622dc7).

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #412      +/-   ##
============================================
+ Coverage     66.97%   69.81%   +2.84%     
- Complexity     3085     3242     +157     
============================================
  Files           198      198              
  Lines         13691    13691              
  Branches       2140     2140              
============================================
+ Hits           9170     9559     +389     
+ Misses         3941     3545     -396     
- Partials        580      587       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sean-g-rae

Copy link
Copy Markdown
Author

@ibauersachs should I submit this PR to the dnsjava developers for evaluation? No rush just didn't want to miss something on my end. Thanks!

@ibauersachs

Copy link
Copy Markdown
Member

Nothing missed on your end, I just haven't been working on dnsjava this summer and pursued outdoor activities. Come fall, I assume this will change again.

Without having looked at the content yet, thanks a lot for your contribution!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove; this test isn't worth adding as it only covers an irrelevant implementation detail.

Name name = Name.fromString("example.com.");
Cache cache = new Cache();
Record a = new ARecord(name, DClass.IN, 3600, InetAddress.getByName("127.0.0.1"));
cache.addRecord(a, Credibility.AUTH_ANSWER, null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't use deprecated methods

// Since we don't have a network, it should eventually fail with "network error" or "host not
// found"
// but without a resolver it throws NPE.
l.run();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test doesn't do what it promises: the lookup is successful. Both GitHub runners as wells as running the tests locally do have network access. The result is an NXDOMAIN because of the query to a non-existent subdomain.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove; this isn't worth adding.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove:

  • please no reflection
  • create test that don't just cover one case, but all paths (at least of one method)

}

private static class TestZoneTransferIn extends ZoneTransferIn {
private List<byte[]> responses;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

make final


private static class TestZoneTransferIn extends ZoneTransferIn {
private List<byte[]> responses;
private MockTCPClient mockClient;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove


@Override
TCPClient createTcpClient(Duration timeout) throws IOException {
mockClient = new MockTCPClient(timeout, responses);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return directly, remove intermediate variable

}

@Test
void testGetters() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove, identical to testNewAXFR

private static class MockTCPClient extends TCPClient {
private List<byte[]> responses;
private int responseIndex = 0;
private byte[] sentData;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems unused; remove

@sean-g-rae

Copy link
Copy Markdown
Author

I really appreciate the detailed feedback, @ibauersachs ! I think I followed up and resolved all of the issues, but please let me know if I missed anything. Thank you!

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.

2 participants