@Test void testCollectPropertyAnnotationChecks(){ ValidationContext context = spy(new ValidationContext()); PropertyDescriptor propertyDescriptor = mock(PropertyDescriptor.class); List<Check> list = new ArrayList<>(); context.collectPropertyAnnotationChecks(list, propertyDescriptor); verify(context, never()).collectAnnotationChecks(any(List.class), any(Class.class),any(String.class), any(Annotation[].class)); }
/** * Parses class annotations and adds all checks. * @see #resolveFor(Class) */ public void addClassChecks(final Class target) { final List<Check> list = cache.get(target, () -> { final List<Check> newList = new ArrayList<>(); final ClassDescriptor cd = ClassIntrospector.get().lookup(target); final PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : allProperties) { collectPropertyAnnotationChecks(newList, propertyDescriptor); } return newList; }); addAll(list); }
@Test void testAddClassChecksWithCache() throws Exception { ValidationContext context = spy(new ValidationContext()); try { context.addClassChecks(ClassForCheck1.class); context.addClassChecks(ClassForCheck1.class); } finally { context.clearCache(); } //collectProperty must be invoked only for first call of addClassChecks. Two calls for two annotations verify(context, times(2)).collectPropertyAnnotationChecks(any(List.class), any(PropertyDescriptor.class)); }