- @Test
- @SuppressWarnings("rawtypes")
- public void testMethodQualifer() throws Exception
- {
- Mockito.when(serviceLoader.all(Configurator.class))
- .thenReturn(Arrays.<Configurator> asList(new MockDroneFactory()));
- Mockito.when(serviceLoader.all(Instantiator.class))
- .thenReturn(Arrays.<Instantiator> asList(new MockDroneFactory()));
- Mockito.when(serviceLoader.all(Destructor.class))
- .thenReturn(Arrays.<Destructor> asList(new MockDroneFactory()));
- Mockito.when(serviceLoader.all(TestEnricher.class))
- .thenReturn(Arrays.<TestEnricher> asList(new DroneTestEnricher()));
- manager.fire(new BeforeSuite());
- DroneRegistry registry = manager.getContext(SuiteContext.class).getObjectStore().get(DroneRegistry.class);
- Assert.assertNotNull("Drone registry was created in the context", registry);
- Assert.assertTrue("Configurator is of mock type", registry.getConfiguratorFor(MockDroneInstance.class) instanceof MockDroneFactory);
- manager.fire(new BeforeClass(MethodEnrichedClass.class));
- // ??QUESTION??
- // what class is the owner of the class context?
- MethodContext mc = manager.getContext(ClassContext.class).getObjectStore().get(MethodContext.class);
- Assert.assertNotNull("Method context object holder was created in the context", mc);
- Object instance = new MethodEnrichedClass();
- Method testMethod = MethodEnrichedClass.class.getMethod("testMethodEnrichment", MockDroneInstance.class);
- // fire before event, create configuration and instance
- manager.fire(new Before(instance, testMethod));
- // ??QUESTION??
- // How come I have null there
- DroneContext context = mc.get(testMethod);
- Assert.assertNotNull("Method context was stored", context);
- MockDroneConfiguration configuration = context.get(MockDroneConfiguration.class);
- Assert.assertNull("There is no MockDroneCnfiguration with @Default qualifier", configuration);
- configuration = context.get(MockDroneConfiguration.class, MethodArgumentOne.class);
- Assert.assertNotNull("MockDroneConfiguration is stored with @MethodArgumentOne qualifier", configuration);
- Assert.assertEquals("MockDroneConfiguration is set via ArquillianDescriptor", METHOD_ARGUMENT_ONE_FIELD, configuration.getField());
- MockDroneInstance mockDrone = context.get(MockDroneInstance.class, MethodArgumentOne.class);
- Assert.assertNotNull("Mock drone instance was created", mockDrone);
- Assert.assertEquals("MockDroneConfiguration is set via ArquillianDescriptor", METHOD_ARGUMENT_ONE_FIELD, mockDrone.getField());
- // fire after event, dispose instance
- manager.fire(new After(instance, testMethod));
- mockDrone = context.get(MockDroneInstance.class, MethodArgumentOne.class);
- Assert.assertNull("Mock drone instance was destroyed", mockDrone);
- }
- class EnrichedClass
- {
- @Drone
- @Different
- MockDroneInstance unused;
- }
- class MethodEnrichedClass
- {
- public void testMethodEnrichment(@Drone @MethodArgumentOne MockDroneInstance unused)
- {
- }
- }