Exemplo n.º 1
0
  @Test
  public void equalsHashcodeTest() {
    UnmodSortedIterable<Integer> a = () -> FunctionUtils.emptyUnmodSortedIterator();
    UnmodSortedIterable<Integer> b = () -> FunctionUtils.emptyUnmodSortedIterator();
    UnmodSortedIterable<Integer> c =
        () ->
            new UnmodSortedIterator<Integer>() {
              private final Iterator<Integer> intern = Arrays.asList(1).iterator();

              @Override
              public boolean hasNext() {
                return intern.hasNext();
              }

              @Override
              public Integer next() {
                return intern.next();
              }
            };

    assertEquals(UnmodIterable.hashCode(a), UnmodIterable.hashCode(a));
    assertEquals(UnmodIterable.hashCode(a), UnmodIterable.hashCode(b));
    assertNotEquals(UnmodIterable.hashCode(a), UnmodIterable.hashCode(c));

    assertEquals(0, UnmodIterable.hashCode(Arrays.asList(new String[] {null})));

    assertTrue(UnmodSortedIterable.equals(a, a));
    assertTrue(UnmodSortedIterable.equals(a, b));
    assertTrue(UnmodSortedIterable.equals(b, a));
    assertTrue(UnmodSortedIterable.equals(null, null));
    assertFalse(UnmodSortedIterable.equals(a, null));
    assertFalse(UnmodSortedIterable.equals(null, a));
    assertFalse(UnmodSortedIterable.equals(a, c));
    assertFalse(UnmodSortedIterable.equals(c, a));
  }
Exemplo n.º 2
0
  @Test
  public void equalsHashcode() {
    UnmodSortedIterable<Integer> a =
        () ->
            new UnmodSortedIterator<Integer>() {
              private final Iterator<Integer> intern = Arrays.asList(1, 2, 3).iterator();

              @Override
              public boolean hasNext() {
                return intern.hasNext();
              }

              @Override
              public Integer next() {
                return intern.next();
              }
            };
    UnmodSortedIterable<Integer> b =
        () ->
            new UnmodSortedIterator<Integer>() {
              private final Iterator<Integer> intern = Arrays.asList(1, 2, 3).iterator();

              @Override
              public boolean hasNext() {
                return intern.hasNext();
              }

              @Override
              public Integer next() {
                return intern.next();
              }
            };
    UnmodSortedIterable<Integer> c =
        () ->
            new UnmodSortedIterator<Integer>() {
              private final Iterator<Integer> intern = Arrays.asList(1, 2, 3, 4).iterator();

              @Override
              public boolean hasNext() {
                return intern.hasNext();
              }

              @Override
              public Integer next() {
                return intern.next();
              }
            };
    UnmodSortedIterable<Integer> d =
        () ->
            new UnmodSortedIterator<Integer>() {
              private final Iterator<Integer> intern = Arrays.asList(1, 2, 2).iterator();

              @Override
              public boolean hasNext() {
                return intern.hasNext();
              }

              @Override
              public Integer next() {
                return intern.next();
              }
            };

    assertEquals(UnmodIterable.hashCode(a), UnmodIterable.hashCode(a));
    assertEquals(UnmodIterable.hashCode(a), UnmodIterable.hashCode(b));
    assertNotEquals(UnmodIterable.hashCode(a), UnmodIterable.hashCode(c));
    assertNotEquals(UnmodIterable.hashCode(b), UnmodIterable.hashCode(d));

    assertTrue(UnmodSortedIterable.equals(a, a));
    assertTrue(UnmodSortedIterable.equals(a, b));
    assertTrue(UnmodSortedIterable.equals(b, a));
    assertFalse(UnmodSortedIterable.equals(a, c));
    assertFalse(UnmodSortedIterable.equals(c, a));
    assertFalse(UnmodSortedIterable.equals(b, d));
    assertFalse(UnmodSortedIterable.equals(d, b));
  }