@Test public void not_equals_to_null_nor_other_type() { assertThat(Health.GREEN).isNotEqualTo(null); assertThat(Health.GREEN).isNotEqualTo(new Object()); assertThat(Health.GREEN).isNotEqualTo(Health.Status.GREEN); }
@Test public void equalsReturnsTrueIfUsernamesAreTheSame() { User user1 = new User("rod", "koala", true, true, true, true, ROLE_12); assertThat(user1).isNotNull(); assertThat(user1).isNotEqualTo("A STRING"); assertThat(user1).isEqualTo(user1); assertThat(user1).isEqualTo((new User("rod", "notthesame", true, true, true, true, ROLE_12))); }
@Test public void testEquals() throws Exception { LineRange range = new LineRange(12, 15); assertThat(range).isEqualTo(range); assertThat(range).isEqualTo(new LineRange(12, 15)); assertThat(range).isNotEqualTo(new LineRange(12, 2000)); assertThat(range).isNotEqualTo(new LineRange(1000, 2000)); assertThat(range).isNotEqualTo(null); assertThat(range).isNotEqualTo(new StringBuffer()); }
@Test public void equals_is_done_on_all_fields() { Period period = new Period(LEAK_PERIOD_MODE_VERSION, "2.3", 1420034400000L, "U10"); assertThat(period).isEqualTo(new Period(LEAK_PERIOD_MODE_VERSION, "2.3", 1420034400000L, "U10")); assertThat(period).isNotEqualTo(null); assertThat(period).isNotEqualTo("sdsd"); assertThat(period).isNotEqualTo(new Period(LEAK_PERIOD_MODE_DAYS, "2.3", 1420034400000L, "U10")); assertThat(period).isNotEqualTo(new Period(LEAK_PERIOD_MODE_VERSION, "2.4", 1420034400000L, "U10")); assertThat(period).isNotEqualTo(new Period(LEAK_PERIOD_MODE_VERSION, "2.3", 555L, "U10")); assertThat(period).isNotEqualTo(new Period(LEAK_PERIOD_MODE_VERSION, "2.3", 1420034400000L, "9632554")); } }
@Test public void equals_is_based_on_all_fields() { assertThat(underTest).isEqualTo(underTest); assertThat(underTest).isEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "value")); assertThat(underTest).isNotEqualTo(null); assertThat(underTest).isNotEqualTo(new Object()); assertThat(underTest).isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", GREATER_THAN, "a"), ERROR, "value")); assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, OK, "value")); assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, null)); assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "other_value")); }
@Test public void verify_equals() { assertThat(QUALITY_PROFILE).isEqualTo(new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE)); assertThat(QUALITY_PROFILE).isEqualTo(QUALITY_PROFILE); assertThat(QUALITY_PROFILE).isNotEqualTo(null); }
@Test public void test_equality() { ClusterProcess clusterProcess = new ClusterProcess("A", ProcessId.WEB_SERVER); assertThat(clusterProcess) .isNotEqualTo(null) .isEqualTo(clusterProcess) .isNotEqualTo(new ClusterProcess("B", ProcessId.WEB_SERVER)) .isNotEqualTo(new ClusterProcess("A", ProcessId.ELASTICSEARCH)) .isEqualTo(new ClusterProcess("A", ProcessId.WEB_SERVER)); } }
@Test public void test_equals() { OpeningHtmlTag openingHtmlTag = new OpeningHtmlTag(3, "tag"); OpeningHtmlTag openingHtmlTagWithSameValues = new OpeningHtmlTag(3, "tag"); OpeningHtmlTag openingHtmlTagWithDifferentValues = new OpeningHtmlTag(5, "tag2"); OpeningHtmlTag openingHtmlTagWithNoCssClass = new OpeningHtmlTag(3, null); assertThat(openingHtmlTag).isEqualTo(openingHtmlTagWithSameValues); assertThat(openingHtmlTag).isEqualTo(openingHtmlTag); assertThat(openingHtmlTag).isNotEqualTo(openingHtmlTagWithDifferentValues); assertThat(openingHtmlTag).isNotEqualTo(openingHtmlTagWithNoCssClass); assertThat(openingHtmlTag).isNotEqualTo(new OpeningHtmlTag(3, "tag"){}); }
@Test public void equals_is_based_on_content() { NodeDetails.Builder builder = testSupport.randomNodeDetailsBuilder(); NodeDetails underTest = builder.build(); assertThat(underTest).isEqualTo(underTest); assertThat(builder.build()) .isEqualTo(underTest) .isNotSameAs(underTest); assertThat(underTest).isNotEqualTo(null); assertThat(underTest).isNotEqualTo(new Object()); }
@Test public void equals_is_based_on_content() { NodeHealth.Builder builder = testSupport.randomBuilder(); NodeHealth underTest = builder.build(); assertThat(underTest).isEqualTo(underTest); assertThat(builder.build()) .isEqualTo(underTest) .isNotSameAs(underTest); assertThat(underTest).isNotEqualTo(null); assertThat(underTest).isNotEqualTo(new Object()); }
@Test public void equals_is_based_on_project_and_previousKey() { Project project = newRandomProject(); String previousKey = randomAlphanumeric(6); RekeyedProject underTest = new RekeyedProject(project, previousKey); assertThat(underTest).isEqualTo(underTest); assertThat(underTest).isEqualTo(new RekeyedProject(project, previousKey)); assertThat(underTest).isNotEqualTo(new RekeyedProject(project, randomAlphanumeric(11))); assertThat(underTest).isNotEqualTo(new RekeyedProject(newRandomProject(), previousKey)); assertThat(underTest).isNotEqualTo(new Object()); assertThat(underTest).isNotEqualTo(null); }
@Test public void test_equals_and_hashCode() { Transition t1 = Transition.create("resolve", "OPEN", "RESOLVED"); Transition t2 = Transition.create("resolve", "REOPENED", "RESOLVED"); Transition t3 = Transition.create("confirm", "OPEN", "CONFIRMED"); assertThat(t1).isNotEqualTo(t2); assertThat(t1).isNotEqualTo(t3); assertThat(t1).isEqualTo(t1); assertThat(t1.hashCode()).isEqualTo(t1.hashCode()); }
@Test public void testEqualityWithDifferentExtendedInformation3() { String key = "key"; long created = new Date().getTime(); DefaultToken t1 = new DefaultToken(key, created, "length1"); DefaultToken t2 = new DefaultToken(key, created, "longerLength2"); assertThat(t1).isNotEqualTo(t2); } }
@Test public void should_generate_unique_key_when_toString_is_not_overridden() { Object key = keys.of(new WrongToStringImpl()); assertThat(key).isNotEqualTo(WrongToStringImpl.KEY); Object key2 = keys.of(new WrongToStringImpl()); assertThat(key2).isNotEqualTo(key); }
@Test public void equals_is_based_on_id() { int id = RANDOM.nextInt(153151); RuleDefinitionDto dto = newRule().setId(id); assertThat(dto).isEqualTo(dto); assertThat(dto).isEqualTo(newRule().setId(id)); assertThat(dto).isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setId(id)); assertThat(dto).isNotEqualTo(null); assertThat(dto).isNotEqualTo(new Object()); assertThat(dto).isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setId(id - 1)); assertThat(dto).isNotEqualTo(newRule().setId(id + 1)); }
@Test public void equals_compares_on_original_and_duplicates() { Duplication duplication = new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1))); assertThat(duplication).isEqualTo(duplication); assertThat(duplication).isEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1)))); assertThat(duplication).isNotEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_2)))); assertThat(duplication).isNotEqualTo(new Duplication(TEXT_BLOCK_1, Arrays.asList(new InnerDuplicate(SOME_ORIGINAL_TEXTBLOCK)))); }
@Test public void shouldEqual() { assertThat(notification.equals("")).isFalse(); assertThat(notification.equals(null)).isFalse(); assertThat(notification.equals(notification)).isTrue(); Notification otherNotif = new Notification("alerts").setDefaultMessage("There are new alerts").setFieldValue("alertCount", "42"); assertThat(otherNotif).isEqualTo(notification); otherNotif = new Notification("alerts").setDefaultMessage("There are new alerts").setFieldValue("alertCount", "15000"); assertThat(otherNotif).isNotEqualTo(notification); }
public void verify(UserDto userDto, boolean root) { Map<String, Object> row = db.selectFirst("select is_root as \"isRoot\", updated_at as \"updatedAt\" from users where login = '" + userDto.getLogin() + "'"); Object isRoot = row.get("isRoot"); assertThat(isRoot) .as("Root flag of user '%s' is '%s'", userDto.getLogin(), root) .isEqualTo(isRoot instanceof Long ? toLong(root) : root); assertThat(row.get("updatedAt")) .as("UpdatedAt of user '%s' has changed since insertion", userDto.getLogin()) .isNotEqualTo(userDto.getUpdatedAt()); }
@Test public void equals_and_hashcode() { ComponentDto dto = new ComponentDto().setUuid("u1"); ComponentDto dtoWithSameUuid = new ComponentDto().setUuid("u1"); ComponentDto dtoWithDifferentUuid = new ComponentDto().setUuid("u2"); assertThat(dto).isEqualTo(dto); assertThat(dto).isEqualTo(dtoWithSameUuid); assertThat(dto).isNotEqualTo(dtoWithDifferentUuid); assertThat(dto.hashCode()).isEqualTo(dto.hashCode()); assertThat(dto.hashCode()).isEqualTo(dtoWithSameUuid.hashCode()); assertThat(dto.hashCode()).isNotEqualTo(dtoWithDifferentUuid.hashCode()); }
@Test public void equals_compares_on_uuid_only() { ComponentImpl.Builder builder = buildSimpleComponent(FILE, "1").setUuid(UUID); assertThat(builder.build()).isEqualTo(builder.build()); assertThat(builder.build()).isEqualTo(buildSimpleComponent(FILE, "2").setUuid(UUID).build()); assertThat(builder.build()).isNotEqualTo(buildSimpleComponent(FILE, "1").setUuid("otherUUid").build()); }