AnnotationDrivenInterfaceConfigFactory implements InterfaceConfigFactory { @SuppressWarnings("unchecked") public InterfaceConfig newConfig(Class<?> interfaze) throws Exception { InterfaceConfigBuilder config = icbf.newInstance(interfaze); for(Annotation annotation : interfaze.getAnnotations()){ handlersRegistry.get(annotation.annotationType()).handleInterfaceAnnotation(annotation, config); } for (Method meth : interfaze.getDeclaredMethods()) { MethodConfigBuilder methodConfigBuilder = config.startMethodConfig(meth); for(Annotation methAnnotation : meth.getAnnotations()){ handlersRegistry.get(methAnnotation.annotationType()).handleMethodAnnotation(methAnnotation, methodConfigBuilder); } Class<?>[] paramTypes = meth.getParameterTypes(); Type[] genParamTypes = meth.getGenericParameterTypes(); Annotation[][] paramAnnotations = meth.getParameterAnnotations(); for (int i = 0, max = paramTypes.length; i < max; i++) { Type pType = genParamTypes[i]; Class<?> pClass = Types.getComponentClass(paramTypes[i], pType); Annotation[] annotations = merge(Annotation.class, pClass.getAnnotations(), paramAnnotations[i]); ParamConfigBuilder methodParamConfigBuilder = methodConfigBuilder.startParamConfig(i); for(Annotation paramAnnotation : annotations){ handlersRegistry.get(paramAnnotation.annotationType()).handleParameterAnnotation(paramAnnotation, methodParamConfigBuilder); } } } return config.build(); } AnnotationDrivenInterfaceConfigFactory(InterfaceConfigBuilderFactory icbf, ComponentRegistry<Class<? extends Annotation>,AnnotationHandler> handlersRegistry); @SuppressWarnings("unchecked") InterfaceConfig newConfig(Class<?> interfaze);  }
@Test public void shouldBuildAnInterfaceConfigByDelegatingToAnnotationHandlersForEachAnnotationsDetected() throws Exception { InterfaceConfig expected = mock(InterfaceConfig.class); when(mockInterfaceConfigBuilder.build()).thenReturn(expected); InterfaceConfig actual = toTest.newConfig(TestInterface.class); assertSame(expected, actual); verify(mockAnn2Handler).handleInterfaceAnnotation(TestInterface.class.getAnnotation(Ann2.class), mockInterfaceConfigBuilder); verify(mockAnn3Handler).handleInterfaceAnnotation(TestInterface.class.getAnnotation(Ann3.class), mockInterfaceConfigBuilder); verify(mockInterfaceConfigBuilder).startMethodConfig(M1); verify(mockAnn1Handler).handleMethodAnnotation(M1.getAnnotation(Ann1.class), mockMethodM1ConfigBuilder); verify(mockAnn2Handler).handleMethodAnnotation(M1.getAnnotation(Ann2.class), mockMethodM1ConfigBuilder); verify(mockDefaultHandler).handleMethodAnnotation(M1.getAnnotation(Ann4Unknown.class), mockMethodM1ConfigBuilder); verify(mockMethodM1ConfigBuilder).startParamConfig(0); verify(mockAnn1Handler).handleParameterAnnotation(Type.class.getAnnotation(Ann1.class), mockParamM1P1ConfigBuilder); verify(mockMethodM1ConfigBuilder).startParamConfig(1); verify(mockAnn1Handler).handleParameterAnnotation(Type.class.getAnnotation(Ann1.class), mockParamM1P2ConfigBuilder); verify(mockAnn1Handler).handleParameterAnnotation((Ann1)M1.getParameterAnnotations()[1][0], mockParamM1P2ConfigBuilder); verify(mockAnn2Handler).handleParameterAnnotation((Ann2)M1.getParameterAnnotations()[1][1], mockParamM1P2ConfigBuilder); verify(mockInterfaceConfigBuilder).startMethodConfig(M2); verify(mockAnn3Handler).handleMethodAnnotation(M2.getAnnotation(Ann3.class), mockMethodM2ConfigBuilder); }