### Question:
Fields { private Fields() {} private  Fields(); static boolean has(Field field, Class<? extends Annotation> annotationType); static String alias(AnnotatedElement element, Function<Alias, String> property); static String propertyKey(Field field); @SneakyThrows static Object propertyValue(Field field, Object instance); static Field field(E element, String fieldName); static Field field(Class<E> elementType, String fieldName); static List<Field> fields(E element); static List<Field> fields(E element, Predicate<Field> predicate); static List<Field> fields(Class<E> elementType); static List<Field> fields(Class<E> elementType,
      Predicate<Field> predicate); static Class<?> listType(Field field); static boolean isSimple(Field field); static long elementCacheSize; static final Comparator<Field> BY_NAME; static final Comparator<Field> BY_KEYS; }### Answer:
@Test public void testGetAllFields() { assertEquals( Arrays.asList("name", "age", "locations", "titles"), fields(marko).stream().map(Field::getName).collect(Collectors.toList())); }
@Test public void testFieldCacheEnabled() { assertEquals(fields(marko), fields(marko)); List<Field> first = fields(marko); List<Field> second = fields(marko); assertEquals(first.size(), second.size()); for (int index = 0; index < first.size(); index++) { assertTrue(first.get(index) == second.get(index)); } }
@Test public void testFieldCacheDisabled() { try { Fields.elementCacheSize = 0; List<Field> first = fields(marko); List<Field> second = fields(marko); assertEquals(first.size(), second.size()); for (int index = 0; index < first.size(); index++) { assertFalse(first.get(index) == second.get(index)); } } finally { Fields.elementCacheSize = 100L; } }
@Test public void testGetPrimaryKeyFields() { assertEquals( Arrays.asList("name"), fields(marko, Keys::isPrimaryKey).stream() .map(Field::getName).collect(Collectors.toList())); }
@Test public void testGetNonKeyFields() { assertEquals( Arrays.asList("locations", "titles"), fields(marko, field -> !Keys.isKey(field)).stream() .map(Field::getName).collect(Collectors.toList())); }