FieldScanner { public FieldData scanAnnotations(Class modelClass) { FieldData.Builder builder = FieldData.builder(); ImmutableMap.Builder<String,Field> fieldMap = ImmutableMap.builder(); Map<Class,Field> found = new HashMap<>(); Set<String> scannedFields = new HashSet<>(); for (java.lang.reflect.Field field : modelClass.getDeclaredFields()) { String fieldName = field.getName(); addToMap(builder, fieldMap, found, fieldName, field, isFieldOptional(field)); scannedFields.add(fieldName); } for (Method method : modelClass.getDeclaredMethods()) { String fieldName = toFieldName(method); if (fieldName != null && !scannedFields.contains(fieldName)) { addToMap(builder, fieldMap, found, fieldName, method, isMethodFieldOptional(method)); } } builder.map(fieldMap.build()); return builder.build(); }  FieldData scanAnnotations(Class modelClass);  }
@Test public void testScanAnnotations() throws Exception { FieldScanner scanner = new FieldScanner(); FieldData data = scanner.scanAnnotations(TestModel.class); assertEquals("id", data.getId().getName()); assertEquals("updateId", data.getUpdatedBy().getName()); assertEquals("updateAt", data.getUpdatedAt().getName()); assertEquals("createId", data.getCreatedBy().getName()); assertEquals("createAt", data.getCreatedAt().getName()); }