@Test public void TimestampedAnnotation_equals_returns_true_and_hashCode_same_if_same_instance() { // given TimestampedAnnotation instance = new TimestampedAnnotation(42, "foo"); // expect //noinspection EqualsWithItself assertThat(instance.equals(instance)).isTrue(); assertThat(instance.hashCode()).isEqualTo(instance.hashCode()); }
@Test public void TimestampedAnnotation_equals_returns_false_and_hashCode_different_if_other_is_not_a_TimestampedAnnotation() { // given TimestampedAnnotation annotation = new TimestampedAnnotation(42, "foo"); String notAnAnnotation = "notAnAnnotation"; // expect //noinspection EqualsBetweenInconvertibleTypes assertThat(annotation.equals(notAnAnnotation)).isFalse(); assertThat(annotation.hashCode()).isNotEqualTo(notAnAnnotation.hashCode()); }
@Test public void TimestampedAnnotation_equals_returns_true_and_hashCode_same_if_all_fields_are_equal() { // given TimestampedAnnotation annotation1 = new TimestampedAnnotation(42, "foo"); TimestampedAnnotation annotation2 = new TimestampedAnnotation( annotation1.getTimestampEpochMicros(), annotation1.getValue() ); // expect assertThat(annotation1.equals(annotation2)).isTrue(); assertThat(annotation1.hashCode()).isEqualTo(annotation2.hashCode()); }
@Test public void TimestampedAnnotation_equals_returns_false_and_hashCode_different_if_timestamp_is_different() { // given TimestampedAnnotation annotation1 = new TimestampedAnnotation(42, "foo"); TimestampedAnnotation annotation2 = new TimestampedAnnotation( annotation1.getTimestampEpochMicros() + 1234, annotation1.getValue() ); // expect assertThat(annotation1.equals(annotation2)).isFalse(); assertThat(annotation1.hashCode()).isNotEqualTo(annotation2.hashCode()); }
@Test public void TimestampedAnnotation_equals_returns_false_and_hashCode_different_if_value_is_different() { // given TimestampedAnnotation annotation1 = new TimestampedAnnotation(42, "foo"); TimestampedAnnotation annotation2 = new TimestampedAnnotation( annotation1.getTimestampEpochMicros(), annotation1.getValue() + "_nope" ); // expect assertThat(annotation1.equals(annotation2)).isFalse(); assertThat(annotation1.hashCode()).isNotEqualTo(annotation2.hashCode()); }