BeanFieldExtractor implements FieldExtractor<P> { @Override public Iterable<Object> extractFields(final P payload) throws Exception { Object[] values = new Object[fields.length]; for (int i = 0; i < fields.length; i++) { Object value = getValue(fields[i], payload); values[i] = format(value); } return Arrays.asList(values); } BeanFieldExtractor(final Class<P> type, final String... fields); @Override Iterable<Object> extractFields(final P payload); void registerTypeConverter(final TypeConverter<?, String> typeConverter);  }
@Test public void whenFieldsIsEmpty_ThenItShouldExtractAllPropertiesValues() throws Exception { fieldExtractor = new BeanFieldExtractor<>(Person.class); Iterable<Object> values = fieldExtractor.extractFields(person); assertThat(values).hasSize(7); assertThat(values).containsOnlyOnce( person.getFirstName(), person.getLastName(), person.getBirthDate(), person.getAge(), person.getGender(), person.isMarried(), person.getMarriageDate()); }
@Test public void whenFieldsIsNotEmpty_ThenItShouldExtractAllPropertiesValuesInRightOrder() throws Exception { fieldExtractor = new BeanFieldExtractor<>(Person.class, "lastName", "age", "married"); Iterable<Object> values = fieldExtractor.extractFields(person); assertThat(values).containsExactly(person.getLastName(), person.getAge(), person.isMarried()); }