项目作者: poblish

项目描述 :
Tests your Java equals() and hashCode() easily and thoroughly
高级语言: Java
项目地址: git://github.com/poblish/EqHash.git
创建时间: 2014-05-13T22:27:59Z
项目社区:https://github.com/poblish/EqHash

开源协议:Apache License 2.0

下载


EqHash

Build Status codecov.io Maven Central

The one Java class / method you need to test your objects’ equals() and hashCode() methods.

  • Save boilerplate code
  • Get code coverage closer to 100%
  • Best of all, get better mutation testing scores when using PIT et al.
  1. public class EqHashTest {
  2. @Test
  3. public void testCustomObject() {
  4. final TestContainer orig = new TestContainer( 1, "a", new byte[]{46});
  5. // Assert that copy has same hashCode(), is equal etc.
  6. final TestContainer copy = new TestContainer( 1, "a", new byte[]{46});
  7. // Test all permutations for different hashCode(), not equal etc.
  8. final TestContainer diff1 = new TestContainer( 1, "a", new byte[]{46,47});
  9. final TestContainer diff2 = new TestContainer( 2, "a", new byte[]{46});
  10. final TestContainer diff3 = new TestContainer( 1, "b", new byte[]{46,47});
  11. EqHash.testEqualsHashcode( orig, copy, diff1, diff2, diff3);
  12. }
  13. [...]
  14. private static class TestContainer {
  15. private int x;
  16. private String y;
  17. private byte[] z;
  18. public TestContainer(int x, String y, byte[] z) {
  19. // Set fields etc.
  20. }