Search in sources :

Example 41 with Jedi

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

the class Objects_assertIsEqualToComparingOnlyGivenFields_Test method should_fail_when_selected_field_does_not_exist.

@Test
public void should_fail_when_selected_field_does_not_exist() {
    thrown.expect(IntrospectionError.class, "%nCan't find any field or property with name 'age'.%n" + "Error when introspecting properties was :%n" + "- No getter for property 'age' in org.assertj.core.test.Jedi %n" + "Error when introspecting fields was :%n" + "- Unable to obtain the value of the field <'age'> from <Yoda the Jedi>");
    Jedi actual = new Jedi("Yoda", "Green");
    Jedi other = new Jedi("Yoda", "Blue");
    objects.assertIsEqualToComparingOnlyGivenFields(someInfo(), actual, other, noFieldComparators(), defaultTypeComparators(), "age");
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 42 with Jedi

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

the class Objects_assertIsEqualToComparingOnlyGivenFields_Test method should_fail_when_some_selected_field_values_differ.

@Test
public void should_fail_when_some_selected_field_values_differ() {
    AssertionInfo info = someInfo();
    Jedi actual = new Jedi("Yoda", "Green");
    Jedi other = new Jedi("Yoda", "Blue");
    try {
        objects.assertIsEqualToComparingOnlyGivenFields(info, actual, other, noFieldComparators(), defaultTypeComparators(), "name", "lightSaberColor");
    } catch (AssertionError err) {
        List<Object> expected = newArrayList((Object) "Blue");
        List<Object> rejected = newArrayList((Object) "Green");
        verify(failures).failure(info, shouldBeEqualComparingOnlyGivenFields(actual, newArrayList("lightSaberColor"), rejected, expected, newArrayList("name", "lightSaberColor")));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) Jedi(org.assertj.core.test.Jedi) List(java.util.List) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 43 with Jedi

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

the class Objects_assertIsEqualToIgnoringGivenFields_Test method should_pass_when_field_values_are_null.

@Test
public void should_pass_when_field_values_are_null() {
    Jedi actual = new Jedi("Yoda", null);
    Jedi other = new Jedi("Yoda", null);
    objects.assertIsEqualToIgnoringGivenFields(someInfo(), actual, other, noFieldComparators(), defaultTypeComparators(), "name");
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 44 with Jedi

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

the class Objects_assertIsEqualToIgnoringGivenFields_Test method should_pass_when_not_ignored_inherited_fields_are_equal.

@Test
public void should_pass_when_not_ignored_inherited_fields_are_equal() {
    Jedi actual = new Jedi("Yoda", "Green");
    Jedi other = new Jedi("Luke", "Green");
    objects.assertIsEqualToIgnoringGivenFields(someInfo(), actual, other, noFieldComparators(), defaultTypeComparators(), "name");
}
Also used : Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Test(org.junit.Test)

Example 45 with Jedi

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

the class Objects_assertIsEqualToIgnoringGivenFields_Test method should_be_able_to_use_a_comparator_for_specified_fields.

@Test
public void should_be_able_to_use_a_comparator_for_specified_fields() {
    Comparator<String> alwaysEqual = (s1, s2) -> 0;
    Jedi actual = new Jedi("Yoda", "Green");
    Jedi other = new Jedi("Luke", "Green");
    assertThat(actual).usingComparatorForFields(alwaysEqual, "name").isEqualToComparingFieldByField(other);
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) TypeComparators(org.assertj.core.internal.TypeComparators) CartoonCharacter(org.assertj.core.test.CartoonCharacter) ArrayList(java.util.ArrayList) Jedi(org.assertj.core.test.Jedi) Map(java.util.Map) Assertions(org.assertj.core.api.Assertions) Person(org.assertj.core.test.Person) Objects(org.assertj.core.internal.Objects) TestClassWithRandomId(org.assertj.core.test.TestClassWithRandomId) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) FieldSupport(org.assertj.core.util.introspection.FieldSupport) TestFailures.failBecauseExpectedAssertionErrorWasNotThrown(org.assertj.core.test.TestFailures.failBecauseExpectedAssertionErrorWasNotThrown) List(java.util.List) Employee(org.assertj.core.test.Employee) TypeComparators.defaultTypeComparators(org.assertj.core.internal.TypeComparators.defaultTypeComparators) InnerClass(org.assertj.core.internal.objects.Objects_assertIsEqualToIgnoringGivenFields_Test.OuterClass.InnerClass) ShouldBeEqualToIgnoringFields.shouldBeEqualToIgnoringGivenFields(org.assertj.core.error.ShouldBeEqualToIgnoringFields.shouldBeEqualToIgnoringGivenFields) Comparator(java.util.Comparator) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) TestData.someInfo(org.assertj.core.test.TestData.someInfo) Jedi(org.assertj.core.test.Jedi) ObjectsBaseTest(org.assertj.core.internal.ObjectsBaseTest) 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