ClassFieldsExcelExport implements ClassFields { @Override public Iterator<Field> getFields() { final Iterable<Field> originalFields = () -> this.original.getFields(); final Iterator<Field> fields = StreamSupport.stream(originalFields.spliterator(), false) .filter(field -> field.getAnnotation(ExcelExport.class) != null) .filter(this::filterByClass) .iterator(); return fields; } ClassFieldsExcelExport(final ClassFields classFields); @Override Iterator<Field> getFields(); @Override Class getClazz();  }
@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("Check declared @ExcelExport fields", 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("Check declared & inherited @ExcelExport fields", expectedFields, actualFields.toArray()); }