Search in sources :

Example 11 with Name

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

the class ToStringExtractorTest method should_extract_toString.

@Test
public void should_extract_toString() {
    Employee someEmployee = new Employee(1, new Name("John Doe"), 28);
    String result = toStringExtractor.extract(someEmployee);
    assertThat(result).isEqualTo("Employee[id=1, name=Name[first='John Doe', last='null'], age=28]");
}
Also used : Employee(org.assertj.core.test.Employee) Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 12 with Name

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

the class FieldsOrPropertiesExtractor_extract_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() {
    List<Employee> employees = Arrays.<Employee>asList(new EmployeeWithBrokenName("Name"));
    List<Object> extractedValues = extract(employees, byName("name"));
    assertThat(extractedValues).containsOnly(new Name("Name"));
}
Also used : Employee(org.assertj.core.test.Employee) Extractors.byName(org.assertj.core.extractor.Extractors.byName) Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 13 with Name

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

the class FieldsOrPropertiesExtractor_extract_Test method should_extract_null_valuesfor_null_property_values.

@Test
public void should_extract_null_valuesfor_null_property_values() {
    yoda.setName(null);
    List<Object> extractedValues = extract(employees, byName("name"));
    assertThat(extractedValues).containsOnly(null, new Name("Luke", "Skywalker"));
}
Also used : Extractors.byName(org.assertj.core.extractor.Extractors.byName) Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 14 with Name

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

the class FieldsOrPropertiesExtractor_extract_Test method should_prefer_properties_over_fields.

@Test
public void should_prefer_properties_over_fields() {
    List<Employee> employees = Arrays.<Employee>asList(new EmployeeWithOverriddenName("Overridden Name"));
    List<Object> extractedValues = extract(employees, byName("name"));
    assertThat(extractedValues).containsOnly(new Name("Overridden Name"));
}
Also used : Employee(org.assertj.core.test.Employee) Extractors.byName(org.assertj.core.extractor.Extractors.byName) Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 15 with Name

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

the class BDDSoftAssertionsTest 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.then(name).extracting("first", "last").contains("John").contains("gandalf");
    softly.then(name).extracting(Name::getFirst, Name::getLast).contains("John").contains("frodo");
    softly.then(alphabet).asString().startsWith("abc").startsWith("123");
    softly.then(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)

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