Search in sources :

Example 6 with Employee

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

the class ByNameMultipleExtractorTest method should_extract_tuples_from_fields_or_properties.

@Test
public void should_extract_tuples_from_fields_or_properties() {
    Extractor<Employee, Tuple> extractor = new ByNameMultipleExtractor<>("id", "age");
    Tuple extractedValue = extractor.extract(yoda);
    assertThat(extractedValue).isEqualTo(tuple(1L, 800));
}
Also used : Employee(org.assertj.core.test.Employee) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.Test)

Example 7 with Employee

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

the class ByNameMultipleExtractorTest method should_extract_tuples_with_consistent_iteration_order.

@Test
public void should_extract_tuples_with_consistent_iteration_order() {
    Extractor<Employee, Tuple> extractor = new ByNameMultipleExtractor<>("id", "name.first", "age");
    Tuple extractedValues = extractor.extract(yoda);
    assertThat(extractedValues).isEqualTo(tuple(1L, "Yoda", 800));
}
Also used : Employee(org.assertj.core.test.Employee) Tuple(org.assertj.core.groups.Tuple) Test(org.junit.Test)

Example 8 with Employee

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

the class ByNameSingleExtractorTest method should_extract_single_value_from_maps_by_key.

@Test
public void should_extract_single_value_from_maps_by_key() {
    String key1 = "key1";
    String key2 = "key2";
    Map<String, Employee> map1 = new HashMap<>();
    map1.put(key1, yoda);
    Employee luke = new Employee(2L, new Name("Luke"), 22);
    map1.put(key2, luke);
    Map<String, Employee> map2 = new HashMap<>();
    map2.put(key1, yoda);
    Employee han = new Employee(3L, new Name("Han"), 31);
    map2.put(key2, han);
    List<Map<String, Employee>> maps = asList(map1, map2);
    assertThat(maps).extracting(key2).containsExactly(luke, han);
    assertThat(maps).extracting(key2, Employee.class).containsExactly(luke, han);
    assertThat(maps).extracting(key1).containsExactly(yoda, yoda);
    assertThat(maps).extracting("bad key").containsExactly(null, null);
}
Also used : Employee(org.assertj.core.test.Employee) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Extractors.byName(org.assertj.core.extractor.Extractors.byName) Name(org.assertj.core.test.Name) Test(org.junit.Test)

Example 9 with Employee

use of org.assertj.core.test.Employee 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 10 with Employee

use of org.assertj.core.test.Employee 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)

Aggregations

Employee (org.assertj.core.test.Employee)27 Name (org.assertj.core.test.Name)21 Test (org.junit.Test)17 Before (org.junit.Before)9 Extractors.byName (org.assertj.core.extractor.Extractors.byName)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ObjectsBaseTest (org.assertj.core.internal.ObjectsBaseTest)3 Jedi (org.assertj.core.test.Jedi)3 Tuple (org.assertj.core.groups.Tuple)2 BeforeClass (org.junit.BeforeClass)1