Search in sources :

Example 41 with Name

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

the class PropertyOrFieldSupport_getValueOf_Test method should_fallback_to_field_if_exception_has_been_thrown_on_property_access.

@Test
public void should_fallback_to_field_if_exception_has_been_thrown_on_property_access() {
    Object extractedValue = propertyOrFieldSupport.getValueOf("name", employeeWithBrokenName("Name"));
    assertThat(extractedValue).isEqualTo(new Name("Name"));
}
Also used : Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 42 with Name

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

the class PropertySupport_propertyValues_Test method setUpOnce.

@Before
public void setUpOnce() {
    yoda = new Employee(6000L, new Name("Yoda"), 800);
    luke = new Employee(8000L, new Name("Luke", "Skywalker"), 26);
    employees = newArrayList(yoda, luke);
}
Also used : Employee(org.assertj.core.test.Employee) Name(org.assertj.core.test.Name) Before(org.junit.Before)

Example 43 with Name

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

the class IterableAssert_extractingResultOf_Test method should_allow_assertions_on_method_invocation_result_extracted_from_given_iterable.

@Test
public void should_allow_assertions_on_method_invocation_result_extracted_from_given_iterable() {
    // extract method result
    assertThat(jedis).extractingResultOf("age").containsOnly(800, 50);
    // extract if method result is primitive
    assertThat(jedis).extractingResultOf("darkSide").containsOnly(false, true);
    // extract if method result is also a property
    assertThat(jedis).extractingResultOf("name").containsOnly(new Name("Yoda"), new Name("Darth Vader"));
    // extract toString method result
    assertThat(jedis).extractingResultOf("toString").containsOnly("Yoda", "Darth Vader");
}
Also used : Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 44 with Name

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

the class IterableAssert_extracting_Test method should_allow_assertions_on_field_values_extracted_from_given_iterable.

@Test
public void should_allow_assertions_on_field_values_extracted_from_given_iterable() {
    assertThat(employees).extracting("id").as("extract field").containsOnly(1L, 2L);
    assertThat(employees).extracting("surname").as("null field").containsNull();
    assertThat(employees).extracting("surname.first").as("null nested field").containsNull();
    yoda.surname = new Name();
    assertThat(employees).extracting("surname.first").as("not null field but null nested field").containsNull();
    yoda.surname = new Name("Master");
    assertThat(employees).extracting("surname.first").as("nested field").containsOnly("Master", null);
    assertThat(employees).extracting("surname", Name.class).as("extract field specifying the extracted type").containsOnly(new Name("Master"), null);
}
Also used : Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 45 with Name

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

the class IterableAssert_extracting_Test method should_allow_assertions_on_property_values_extracted_from_given_iterable.

@Test
public void should_allow_assertions_on_property_values_extracted_from_given_iterable() {
    assertThat(employees).extracting("age").as("extract property backed by a private field").containsOnly(800, 26);
    assertThat(employees).extracting("adult").as("extract pure property").containsOnly(true, true);
    assertThat(employees).extracting("name.first").as("nested property").containsOnly("Yoda", "Luke");
    assertThat(employees).extracting("name").as("extract field that is also a property").containsOnly(new Name("Yoda"), new Name("Luke", "Skywalker"));
    assertThat(employees).extracting("name", Name.class).as("extract field that is also a property but specifying the extracted type").containsOnly(new Name("Yoda"), new Name("Luke", "Skywalker"));
}
Also used : Name(org.assertj.core.test.Name) Test(org.junit.Test)

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