Search in sources :

Example 46 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class Objects_assertIsEqualToIgnoringGivenFields_Test method should_fail_when_some_field_values_differ.

@Test
public void should_fail_when_some_field_values_differ() {
    AssertionInfo info = someInfo();
    Jedi actual = new Jedi("Yoda", "Green");
    Jedi other = new Jedi("Yoda", "Blue");
    try {
        objects.assertIsEqualToIgnoringGivenFields(info, actual, other, noFieldComparators(), defaultTypeComparators(), "name");
    } catch (AssertionError err) {
        verify(failures).failure(info, shouldBeEqualToIgnoringGivenFields(actual, newArrayList("lightSaberColor"), newArrayList((Object) "Green"), newArrayList((Object) "Blue"), newArrayList("name")));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 47 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class Objects_assertIsEqualToIgnoringNullFields_Test method should_fail_when_some_actual_field_is_null_but_not_other.

@Test
public void should_fail_when_some_actual_field_is_null_but_not_other() {
    AssertionInfo info = someInfo();
    Jedi actual = new Jedi("Yoda", null);
    Jedi other = new Jedi("Yoda", "Green");
    try {
        objects.assertIsEqualToIgnoringNullFields(info, actual, other, noFieldComparators(), defaultTypeComparators());
    } catch (AssertionError err) {
        verify(failures).failure(info, shouldBeEqualToIgnoringGivenFields(actual, newArrayList("lightSaberColor"), newArrayList((Object) null), newArrayList((Object) "Green"), newArrayList("strangeNotReadablePrivateField")));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 48 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class ObjectAssert_hasFieldOrPropertyWithValue_Test method should_fail_if_field_or_property_value_is_not_null_when_expected_value_is.

@Test
public void should_fail_if_field_or_property_value_is_not_null_when_expected_value_is() {
    thrown.expectAssertionError("%nExpecting%n  <Yoda the Jedi>%nto have a property or a field named <\"name\"> with value%n  <null>%nbut value was:%n  <\"Yoda\">");
    Jedi jedi = new Jedi("Yoda", "Blue");
    assertThat(jedi).hasFieldOrPropertyWithValue(FIELD_NAME, null);
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest) Test(org.junit.Test)

Example 49 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class ObjectAssert_hasFieldOrPropertyWithValue_Test method should_fail_when_property_or_field_value_is_null_and_expected_value_is_not.

@Test
public void should_fail_when_property_or_field_value_is_null_and_expected_value_is_not() {
    thrown.expectAssertionError("%nExpecting%n  <null the Jedi>%nto have a property or a field named <\"name\"> with value%n  <\"Yoda\">%nbut value was:%n  <null>");
    Jedi jedi = new Jedi(null, "Blue");
    assertThat(jedi).hasFieldOrPropertyWithValue(FIELD_NAME, FIELD_VALUE);
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest) Test(org.junit.Test)

Example 50 with Jedi

use of org.assertj.core.test.Jedi in project assertj-core by joel-costigliola.

the class ObjectAssert_hasFieldOrProperty_Test method should_fail_if_given_field_or_property_name_is_null.

@Test
public void should_fail_if_given_field_or_property_name_is_null() {
    thrown.expectIllegalArgumentException("The name of the property/field to read should not be null");
    Jedi jedi = new Jedi("Yoda", "Blue");
    assertThat(jedi).hasFieldOrProperty(null);
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectAssertBaseTest(org.assertj.core.api.ObjectAssertBaseTest) Test(org.junit.Test)

Aggregations

Jedi (org.assertj.core.test.Jedi)108 Test (org.junit.Test)104 ObjectsBaseTest (org.assertj.core.internal.ObjectsBaseTest)30 ObjectAssertBaseTest (org.assertj.core.api.ObjectAssertBaseTest)26 Comparator (java.util.Comparator)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 ALWAY_EQUALS_STRING (org.assertj.core.test.AlwaysEqualComparator.ALWAY_EQUALS_STRING)13 Before (org.junit.Before)13 AssertionInfo (org.assertj.core.api.AssertionInfo)10 AtomicReferenceArrayAssertBaseTest (org.assertj.core.api.AtomicReferenceArrayAssertBaseTest)9 IterableAssertBaseTest (org.assertj.core.api.IterableAssertBaseTest)9 ObjectArrayAssertBaseTest (org.assertj.core.api.ObjectArrayAssertBaseTest)9 ComparatorBasedComparisonStrategy (org.assertj.core.internal.ComparatorBasedComparisonStrategy)9 Lists.newArrayList (org.assertj.core.util.Lists.newArrayList)7 TextDescription (org.assertj.core.description.TextDescription)6 ExtendedByTypesComparator (org.assertj.core.internal.ExtendedByTypesComparator)6 ObjectArrays (org.assertj.core.internal.ObjectArrays)6 StandardRepresentation (org.assertj.core.presentation.StandardRepresentation)6 List (java.util.List)5 TypeComparators.defaultTypeComparators (org.assertj.core.internal.TypeComparators.defaultTypeComparators)5