ClassFieldsExcelExport implements ClassFields { @Override public Iterator<Field> getFields() { final Iterable<Field> originalFields = () -> this.original.getFields(); final Stream<Field> stream = StreamSupport.stream(originalFields.spliterator(), false) .filter(field -> field.getAnnotation(ExcelExport.class) != null); return stream.iterator(); } ClassFieldsExcelExport(final ClassFields classFields); @Override Iterator<Field> getFields();  }
@Test public void getFields() throws Exception { final String[] expectedFields = {"id", "label"}; final ClassFields classFields = new ClassFieldsExcelExport( new ClassFieldsDefault(TestClass.class) ); final Iterator<Field> fields = classFields.getFields(); final List<String> actualFields = new ArrayList<>(); while (fields.hasNext()) { final Field f = fields.next(); actualFields.add(f.getName()); } Assert.assertArrayEquals(expectedFields, actualFields.toArray()); }
@Test public void getInheritedFields() throws Exception { final String[] expectedFields = {"id", "label", "valid"}; final ClassFields classFields = new ClassFieldsExcelExport( new ClassFieldsDefault(TestClassImproved.class, true) ); final Iterator<Field> fields = classFields.getFields(); final List<String> actualFields = new ArrayList<>(); while (fields.hasNext()) { final Field f = fields.next(); actualFields.add(f.getName()); } Assert.assertArrayEquals(expectedFields, actualFields.toArray()); }