@Override @SuppressWarnings("unchecked") protected void configure() { // Bind mock controllet to this instance, to automatically replay/verify all mocks created by // runner. bind(MockController.class).toInstance(this); // map field values by type for (Field field : fields.keySet()) { TypeLiteral literal = TypeLiteral.get(field.getGenericType()); AnnotatedBindingBuilder builder = bind(literal); // Check field annotations. Annotation[] fieldAnnotations = field.getAnnotations(); for (Annotation annotation : fieldAnnotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if ( /* annotationType.isAnnotationPresent(Qualifier.class)|| */ annotationType .isAnnotationPresent(BindingAnnotation.class)) { builder.annotatedWith(annotation); } if (annotationType.isAnnotationPresent(ScopeAnnotation.class)) { builder.in(annotationType); } } Binding binding = fields.get(field); if (null != binding.getValue()) { builder.toInstance(binding.getValue()); } else if (null != binding.getImplementation()) { builder.to(binding.getImplementation()); } else if (null != binding.getProvider()) { builder.toProvider(binding.getProvider()); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) @Before public void before() { binder = mock(PrivateBinder.class); AnnotatedBindingBuilder ab = mock(AnnotatedBindingBuilder.class); when(binder.bind(any(Class.class))).thenReturn(ab); when(ab.annotatedWith(any(Annotation.class))).thenReturn(ab); AnnotatedElementBuilder aeb = mock(AnnotatedElementBuilder.class); when(binder.expose(any(Class.class))).thenReturn(aeb); ScopedBindingBuilder sb = mock(ScopedBindingBuilder.class); when(ab.toProvider(any(Class.class))).thenReturn(sb); when(binder.bind(any(TypeLiteral.class))).thenReturn(ab); when(binder.skipSources(any(Class.class), any(Class.class))).thenReturn(binder); securityConfigurer = mock(SeedSecurityConfigurer.class); underTest = new SecurityInternalModule( securityConfigurer, new HashMap<String, Class<? extends Scope>>()); Whitebox.setInternalState(underTest, "binder", binder); }