コード例 #1
0
  @Test
  public void should_return_null_elements_for_null_property_value() {
    List<Employee> list = newArrayList(null, null);
    Iterable<Integer> ages = PropertySupport.instance().propertyValues("ages", Integer.class, list);
    assertThat(ages).containsExactly(null, null);

    list = newArrayList(yoda, luke, null, null);
    ages = PropertySupport.instance().propertyValues("age", Integer.class, list);
    assertThat(ages).containsExactly(800, 26, null, null);
  }
コード例 #2
0
 @Test
 public void should_return_values_of_simple_property_as_objects() {
   Iterable<Integer> ages =
       PropertySupport.instance().propertyValues("age", Integer.class, employees);
   Iterable<Object> agesAsObjects = PropertySupport.instance().propertyValues("age", employees);
   assertEquals(agesAsObjects, ages);
   Iterable<String> firstNames =
       PropertySupport.instance().propertyValues("name.first", String.class, employees);
   Iterable<Object> firstNamesAsObjects =
       PropertySupport.instance().propertyValues("name.first", employees);
   assertEquals(firstNamesAsObjects, firstNames);
 }
コード例 #3
0
  @Test
  public void should_extract_nested_property() {
    String firstName = PropertySupport.instance().propertyValueOf("name.first", String.class, yoda);
    assertThat(firstName).isEqualTo("Yoda");

    yoda.name.first = null;
    firstName = PropertySupport.instance().propertyValueOf("name.first", String.class, yoda);
    assertThat(firstName).isNull();

    yoda.name = null;
    firstName = PropertySupport.instance().propertyValueOf("name.first", String.class, yoda);
    assertThat(firstName).isNull();
  }
コード例 #4
0
 @Test
 public void should_return_values_of_property() {
   List<Long> ids = new ArrayList<Long>();
   ids.add(yoda.getId());
   when(propertySupport.propertyValues(propertyName, Long.class, employees)).thenReturn(ids);
   assertSame(ids, properties.from(employees));
 }
コード例 #5
0
 @Test
 public void should_return_properties_of_inner_class() {
   VehicleFactory vehicleFactory = new VehicleFactory();
   List<String> names =
       PropertySupport.instance()
           .propertyValues("name", String.class, vehicleFactory.getVehicles());
   assertThat(names).containsExactly("Toyota", "Honda", "Audi");
 }
コード例 #6
0
 @Test
 public void should_return_values_of_simple_property() {
   Iterable<Integer> ages =
       PropertySupport.instance().propertyValues("age", Integer.class, employees);
   assertThat(ages).containsExactly(800, 26);
 }
コード例 #7
0
 @Test
 public void should_return_empty_List_if_given_Iterable_is_empty() {
   Iterable<Integer> ages =
       PropertySupport.instance().propertyValues("ages", Integer.class, emptySet());
   assertThat(ages).isEmpty();
 }
コード例 #8
0
 @Test
 public void should_return_property_from_superclass() {
   assertThat(PropertySupport.instance().propertyValues("class", Class.class, employees))
       .containsExactly(Employee.class, Employee.class);
 }
コード例 #9
0
 @Test
 public void should_extract_property() {
   Integer age = PropertySupport.instance().propertyValue("age", Integer.class, yoda);
   assertThat(age).isEqualTo(800);
 }
コード例 #10
0
 @Test
 public void should_throw_error_if_property_not_found() {
   thrown.expect(IntrospectionError.class);
   PropertySupport.instance().propertyValues("foo", Integer.class, employees);
 }
コード例 #11
0
 @Test
 public void should_return_values_of_nested_property() {
   Iterable<String> firstNames =
       PropertySupport.instance().propertyValues("name.first", String.class, employees);
   assertThat(firstNames).containsExactly("Yoda", "Luke");
 }