Search in sources :

Example 16 with Name

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

the class SoftAssertionsTest method object_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test.

// the test would fail if any method was not proxyable as the assertion error would not be softly caught
@SuppressWarnings("unchecked")
@Test
public void object_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {
    // GIVEN
    Name name = name("John", "Doe");
    Object alphabet = "abcdefghijklmnopqrstuvwxyz";
    Object vowels = asList("a", "e", "i", "o", "u");
    // WHEN
    softly.assertThat(name).extracting("first", "last").contains("John").contains("gandalf");
    softly.assertThat(name).extracting(Name::getFirst, Name::getLast).contains("John").contains("frodo");
    softly.assertThat(alphabet).asString().startsWith("abc").startsWith("123");
    softly.assertThat(vowels).asList().startsWith("a", "e").startsWith("1", "2");
    // THEN
    List<Throwable> errorsCollected = softly.errorsCollected();
    assertThat(errorsCollected).hasSize(4);
    assertThat(errorsCollected.get(0)).hasMessageContaining("gandalf");
    assertThat(errorsCollected.get(1)).hasMessageContaining("frodo");
    assertThat(errorsCollected.get(2)).hasMessageContaining("123");
    assertThat(errorsCollected.get(3)).hasMessageContaining("\"1\", \"2\"");
}
Also used : Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 17 with Name

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

the class ObjectAssert_extracting_Test method should_keep_existing_description_if_set_when_extracting_tuples_list.

@Test
public void should_keep_existing_description_if_set_when_extracting_tuples_list() {
    Employee luke = new Employee(2L, new Name("Luke", "Skywalker"), 26);
    thrown.expectAssertionErrorWithMessageContaining("[check luke first name]");
    assertThat(luke).as("check luke first name").extracting("name.first").isEmpty();
}
Also used : Employee(org.assertj.core.test.Employee) Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 18 with Name

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

the class ObjectAssert_extracting_Test method should_use_property_field_names_as_description_when_extracting_tuples_list.

@Test
public void should_use_property_field_names_as_description_when_extracting_tuples_list() {
    Employee luke = new Employee(2L, new Name("Luke", "Skywalker"), 26);
    thrown.expectAssertionErrorWithMessageContaining("[Extracted: name.first, name.last]");
    assertThat(luke).extracting("name.first", "name.last").isEmpty();
}
Also used : Employee(org.assertj.core.test.Employee) Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 19 with Name

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

the class ObjectArrayAssert_filtered_baseTest method setUp.

@Before
public void setUp() {
    yoda = new Employee(1L, new Name("Yoda"), 800);
    obiwan = new Employee(2L, new Name("Obi"), 800);
    luke = new Employee(3L, new Name("Luke", "Skywalker"), 26);
    noname = new Employee(4L, null, 10);
    employees = new Employee[] { yoda, luke, obiwan, noname };
}
Also used : Employee(org.assertj.core.test.Employee) Name(org.assertj.core.test.Name) Before(org.junit.Before)

Example 20 with Name

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

the class ObjectArrayAssert_extractingResultOf_Test method setUpOnce.

@BeforeClass
public static void setUpOnce() {
    yoda = new FluentJedi(new Name("Yoda"), 800, false);
    vader = new FluentJedi(new Name("Darth Vader"), 50, true);
    jedis = array(yoda, vader);
}
Also used : FluentJedi(org.assertj.core.test.FluentJedi) Name(org.assertj.core.test.Name) BeforeClass(org.junit.BeforeClass)

Aggregations

Name (org.assertj.core.test.Name)46 Test (org.junit.Test)30 Employee (org.assertj.core.test.Employee)21 Before (org.junit.Before)11 Extractors.byName (org.assertj.core.extractor.Extractors.byName)10 BeforeClass (org.junit.BeforeClass)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ObjectsBaseTest (org.assertj.core.internal.ObjectsBaseTest)3 FluentJedi (org.assertj.core.test.FluentJedi)3 Player (org.assertj.core.test.Player)3 CartoonCharacter (org.assertj.core.test.CartoonCharacter)2 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 ThrowableAssert (org.assertj.core.api.ThrowableAssert)1