Exemplo n.º 1
0
 /** Test null reference yields error */
 public void testOf_NullPointerException() {
   try {
     EquivalenceTester.of(null);
     fail("Should fail on null reference");
   } catch (NullPointerException expected) {
   }
 }
Exemplo n.º 2
0
  public void testTest() {
    Object group1Item1 = new TestObject(1, 1);
    Object group1Item2 = new TestObject(1, 2);
    Object group2Item1 = new TestObject(2, 1);
    Object group2Item2 = new TestObject(2, 2);

    equivalenceMock.expectEquivalent(group1Item1, group1Item2);
    equivalenceMock.expectDistinct(group1Item1, group2Item1);
    equivalenceMock.expectDistinct(group1Item1, group2Item2);
    equivalenceMock.expectEquivalent(group1Item2, group1Item1);
    equivalenceMock.expectDistinct(group1Item2, group2Item1);
    equivalenceMock.expectDistinct(group1Item2, group2Item2);
    equivalenceMock.expectDistinct(group2Item1, group1Item1);
    equivalenceMock.expectDistinct(group2Item1, group1Item2);
    equivalenceMock.expectEquivalent(group2Item1, group2Item2);
    equivalenceMock.expectDistinct(group2Item2, group1Item1);
    equivalenceMock.expectDistinct(group2Item2, group1Item2);
    equivalenceMock.expectEquivalent(group2Item2, group2Item1);

    equivalenceMock.expectHash(group1Item1, 1);
    equivalenceMock.expectHash(group1Item2, 1);
    equivalenceMock.expectHash(group2Item1, 2);
    equivalenceMock.expectHash(group2Item2, 2);

    equivalenceMock.replay();

    tester
        .addEquivalenceGroup(group1Item1, group1Item2)
        .addEquivalenceGroup(group2Item1, group2Item2)
        .test();
  }
Exemplo n.º 3
0
  public void testTest_hash() {
    Object group1Item1 = new TestObject(1, 1);
    Object group1Item2 = new TestObject(1, 2);

    equivalenceMock.expectEquivalent(group1Item1, group1Item2);
    equivalenceMock.expectEquivalent(group1Item2, group1Item1);

    equivalenceMock.expectHash(group1Item1, 1);
    equivalenceMock.expectHash(group1Item2, 2);

    equivalenceMock.replay();

    try {
      tester.addEquivalenceGroup(group1Item1, group1Item2).test();
    } catch (AssertionFailedError expected) {
      String expectedMessage =
          "the hash (1) of TestObject{group=1, item=1} [group 1, item 1] must be "
              + "equal to the hash (2) of TestObject{group=1, item=2} [group 1, item 2]";
      if (!expected.getMessage().contains(expectedMessage)) {
        fail("<" + expected.getMessage() + "> expected to contain <" + expectedMessage + ">");
      }
      return;
    }
    fail();
  }
Exemplo n.º 4
0
  public void testTest_trasitive() {
    Object group1Item1 = new TestObject(1, 1);
    Object group1Item2 = new TestObject(1, 2);
    Object group1Item3 = new TestObject(1, 3);

    equivalenceMock.expectEquivalent(group1Item1, group1Item2);
    equivalenceMock.expectEquivalent(group1Item1, group1Item3);
    equivalenceMock.expectEquivalent(group1Item2, group1Item1);
    equivalenceMock.expectDistinct(group1Item2, group1Item3);
    equivalenceMock.expectEquivalent(group1Item3, group1Item1);
    equivalenceMock.expectEquivalent(group1Item3, group1Item2);

    equivalenceMock.expectHash(group1Item1, 1);
    equivalenceMock.expectHash(group1Item2, 1);
    equivalenceMock.expectHash(group1Item3, 1);

    equivalenceMock.replay();

    try {
      tester.addEquivalenceGroup(group1Item1, group1Item2, group1Item3).test();
    } catch (AssertionFailedError expected) {
      assertThat(expected.getMessage())
          .contains(
              "TestObject{group=1, item=2} [group 1, item 2] must be equivalent to "
                  + "TestObject{group=1, item=3} [group 1, item 3]");
      return;
    }
    fail();
  }
Exemplo n.º 5
0
  public void testTest_inequivalence() {
    Object group1Item1 = new TestObject(1, 1);
    Object group2Item1 = new TestObject(2, 1);

    equivalenceMock.expectEquivalent(group1Item1, group2Item1);
    equivalenceMock.expectDistinct(group2Item1, group1Item1);

    equivalenceMock.expectHash(group1Item1, 1);
    equivalenceMock.expectHash(group2Item1, 2);

    equivalenceMock.replay();

    try {
      tester.addEquivalenceGroup(group1Item1).addEquivalenceGroup(group2Item1).test();
    } catch (AssertionFailedError expected) {
      assertThat(expected.getMessage())
          .contains(
              "TestObject{group=1, item=1} [group 1, item 1] must not be equivalent to "
                  + "TestObject{group=2, item=1} [group 2, item 1]");
      return;
    }
    fail();
  }
Exemplo n.º 6
0
 public void testTest_NoData() {
   tester.test();
 }
Exemplo n.º 7
0
 @Override
 public void setUp() throws Exception {
   super.setUp();
   this.equivalenceMock = new MockEquivalence();
   this.tester = EquivalenceTester.of(equivalenceMock);
 }