@Before public void setUp() { builder = new DefaultModulesBuilder(); resolver = mock(ApplicationContext.class); invocationMetadataFactory = mock(InvocationMetadataFactory.class); invokerFactory = mock(InvokerFactory.class); containerAdaptorFactory = mock(ContainerAdaptorFactory.class); containerAdaptor = mock(ContainerAdaptor.class); when(containerAdaptorFactory.createContainerAdaptor(resolver)).thenReturn(containerAdaptor); invocationFactory = mock(InvocationFactory.class); directionResolver = mock(RenderableResolver.class); directiontHandler = mock(ResponseHandler.class); invocationProcessor = mock(ApplicationProcessor.class); invocationInterceptor = mock(InvocationInterceptor.class); attributesHandler = mock(AttributesHandler.class); exceptionHandler = mock(ExceptionHandler.class); typeMapperContext = mock(TypeMapperContext.class); typeMapper = mock(TypeMapper.class); directionFormatter = mock(ResponseFormatter.class); adaptor.register(invocationMetadataFactory.getClass(), invocationMetadataFactory); adaptor.register(invokerFactory.getClass(), invokerFactory); adaptor.register(containerAdaptorFactory.getClass(), containerAdaptorFactory); adaptor.register(invocationFactory.getClass(), invocationFactory); adaptor.register(directionResolver.getClass(), directionResolver); adaptor.register(directiontHandler.getClass(), directiontHandler); adaptor.register(invocationProcessor.getClass(), invocationProcessor); adaptor.register(invocationInterceptor.getClass(), invocationInterceptor); adaptor.register(attributesHandler.getClass(), attributesHandler); adaptor.register(exceptionHandler.getClass(), exceptionHandler); adaptor.register(typeMapperContext.getClass(), typeMapperContext); adaptor.register(typeMapper.getClass(), typeMapper); adaptor.register(directionFormatter.getClass(), directionFormatter); }
@SuppressWarnings("unchecked") @Test public void testBuildModules() { builder.setModulesProviderClass(MockModulesProvidingContainerAdaptorFactory.class); builder.setInvocationFactoryClass(invocationFactory.getClass()); builder.setInvocationInstanceProviderClass( (Class<? extends ContainerAdaptorFactory<? extends ContainerAdaptor>>) containerAdaptorFactory.getClass()); builder.setInvokerFactoryClass(invokerFactory.getClass()); builder.setResponseHandlerClass(directiontHandler.getClass()); builder.setRenderableResolverClass(directionResolver.getClass()); builder.addApplicationProcessorClass(invocationProcessor.getClass()); builder.addInvocationInterceptorClass(invocationInterceptor.getClass()); builder.addInvocationMetadataFactoriesClass(invocationMetadataFactory.getClass()); builder.addAttributesHandlerClass(attributesHandler.getClass()); builder.setExceptionHandlerClass(exceptionHandler.getClass()); builder.setTypeMapperContextClass(typeMapperContext.getClass()); Renderable mapToResponse = mock(Renderable.class); builder.addResponseFormatterClass(mapToResponse.getClass(), directionFormatter.getClass()); Modules modules = builder.buildModules(resolver, adaptor); assertSame(modules.getInvocationMetadataFactories().get(0), invocationMetadataFactory); assertSame(modules.getInvocationInstanceProvider(), containerAdaptor); // same instance. assertSame(modules.getInvocationInstanceProvider(), containerAdaptor); assertSame(modules.getInvocationFactory(), invocationFactory); assertSame(modules.getResponseResolver(), directionResolver); assertSame(modules.getResponseHandler(), directiontHandler); assertSame(modules.getApplicationProcessors().get(0), invocationProcessor); assertSame(modules.getInvocationInterceptors().get(0), invocationInterceptor); assertSame(modules.getExceptionHandler(), exceptionHandler); assertSame(modules.getTypeMapperContext(), typeMapperContext); assertSame(modules.findResponseFormatter(mapToResponse.getClass()), directionFormatter); }
@Test @SuppressWarnings("unchecked") public void testOptionalModuleFound() { ContainerAdaptor defaultAdaptor = mock(ContainerAdaptor.class); Invoker foundInvoker = mock(Invoker.class); InvokerFactory factory = mock(InvokerFactory.class); when(factory.createInvoker(isA(List.class))).thenReturn(foundInvoker); when(defaultAdaptor.getInstanceOfType(InvokerFactory.class)).thenReturn(factory); builder.setInvokerFactoryClass(InvokerFactory.class); builder.setModulesProviderClass(MockModulesProvidingContainerAdaptorFactory.class); Modules modules = builder.buildModules(resolver, defaultAdaptor); adaptor.unregister(Invoker.class); builder.setTypeMapperContextClass(typeMapperContext.getClass()); Invoker actual = modules.getInvoker(); log.debug(actual.toString()); assertThat(actual, is(foundInvoker)); }