Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 16th, 2011  |  syntax: None  |  size: 3.17 KB  |  views: 111  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. @Test
  2.    @SuppressWarnings("rawtypes")
  3.    public void testMethodQualifer() throws Exception
  4.    {
  5.       Mockito.when(serviceLoader.all(Configurator.class))
  6.             .thenReturn(Arrays.<Configurator> asList(new MockDroneFactory()));
  7.       Mockito.when(serviceLoader.all(Instantiator.class))
  8.             .thenReturn(Arrays.<Instantiator> asList(new MockDroneFactory()));
  9.       Mockito.when(serviceLoader.all(Destructor.class))
  10.             .thenReturn(Arrays.<Destructor> asList(new MockDroneFactory()));
  11.       Mockito.when(serviceLoader.all(TestEnricher.class))
  12.             .thenReturn(Arrays.<TestEnricher> asList(new DroneTestEnricher()));
  13.  
  14.       manager.fire(new BeforeSuite());
  15.  
  16.       DroneRegistry registry = manager.getContext(SuiteContext.class).getObjectStore().get(DroneRegistry.class);
  17.       Assert.assertNotNull("Drone registry was created in the context", registry);
  18.  
  19.       Assert.assertTrue("Configurator is of mock type", registry.getConfiguratorFor(MockDroneInstance.class) instanceof MockDroneFactory);
  20.  
  21.       manager.fire(new BeforeClass(MethodEnrichedClass.class));
  22.  
  23.       // ??QUESTION??
  24.       // what class is the owner of the class context?
  25.  
  26.       MethodContext mc = manager.getContext(ClassContext.class).getObjectStore().get(MethodContext.class);
  27.       Assert.assertNotNull("Method context object holder was created in the context", mc);
  28.  
  29.       Object instance = new MethodEnrichedClass();
  30.       Method testMethod = MethodEnrichedClass.class.getMethod("testMethodEnrichment", MockDroneInstance.class);
  31.  
  32.       // fire before event, create configuration and instance
  33.       manager.fire(new Before(instance, testMethod));
  34.            
  35.  
  36.       // ??QUESTION??
  37.       // How come I have null there
  38.  
  39.  
  40.       DroneContext context = mc.get(testMethod);
  41.       Assert.assertNotNull("Method context was stored", context);
  42.  
  43.       MockDroneConfiguration configuration = context.get(MockDroneConfiguration.class);
  44.       Assert.assertNull("There is no MockDroneCnfiguration with @Default qualifier", configuration);
  45.  
  46.       configuration = context.get(MockDroneConfiguration.class, MethodArgumentOne.class);
  47.       Assert.assertNotNull("MockDroneConfiguration is stored with @MethodArgumentOne qualifier", configuration);
  48.       Assert.assertEquals("MockDroneConfiguration is set via ArquillianDescriptor", METHOD_ARGUMENT_ONE_FIELD, configuration.getField());
  49.  
  50.       MockDroneInstance mockDrone = context.get(MockDroneInstance.class, MethodArgumentOne.class);
  51.       Assert.assertNotNull("Mock drone instance was created", mockDrone);
  52.       Assert.assertEquals("MockDroneConfiguration is set via ArquillianDescriptor", METHOD_ARGUMENT_ONE_FIELD, mockDrone.getField());
  53.  
  54.       // fire after event, dispose instance
  55.       manager.fire(new After(instance, testMethod));
  56.  
  57.       mockDrone = context.get(MockDroneInstance.class, MethodArgumentOne.class);
  58.       Assert.assertNull("Mock drone instance was destroyed", mockDrone);
  59.  
  60.    }
  61.  
  62.    class EnrichedClass
  63.    {
  64.       @Drone
  65.       @Different
  66.       MockDroneInstance unused;
  67.    }
  68.  
  69.    class MethodEnrichedClass
  70.    {
  71.  
  72.       public void testMethodEnrichment(@Drone @MethodArgumentOne MockDroneInstance unused)
  73.       {
  74.  
  75.       }
  76.    }
clone this paste RAW Paste Data