atomashpolskiy / bt

BitTorrent library and client with DHT, magnet links, encryption and more
https://atomashpolskiy.github.io/bt/
Apache License 2.0
2.42k stars 381 forks source link

Removed the conditional operator (test smell) #144

Closed eas5 closed 3 years ago

eas5 commented 4 years ago

This is a test refactoring.

Problem: Conditions within the test method will alter the behavior of the test and its expected output, leading to situations where the test fails to detect defects in the production method since test statements were not executed as a condition was not met.

Solution: Instead of using a conditional to control the test execution, we use the proper JUnit API with assumeNotNull(). If the initial assumption is not met, the test will be ignored instead of passed without actually testing the code under test.

Result: Before: if(KBucketEntry.crc32c == null) return; After assumeNotNull(KBucketEntry.crc32c);

atomashpolskiy commented 3 years ago

Sorry, but this code is maintained in a different repo: https://github.com/the8472/mldht