Search in sources :

Example 1 with Descriptor

use of com.buschmais.jqassistant.core.store.api.model.Descriptor in project jqa-core-framework by buschmais.

the class ScannerTest method pluginPipeline.

@Test
public void pluginPipeline() {
    ScannerContext scannerContext = mock(ScannerContext.class);
    Store store = mock(Store.class);
    when(scannerContext.getStore()).thenReturn(store);
    when(store.create(Mockito.any(Class.class))).thenAnswer(new Answer<Descriptor>() {

        @Override
        public Descriptor answer(InvocationOnMock invocation) throws Throwable {
            Class<? extends Descriptor> descriptorType = (Class<? extends Descriptor>) invocation.getArguments()[0];
            return mock(descriptorType);
        }
    });
    when(store.addDescriptorType(Mockito.any(Descriptor.class), Mockito.any(Class.class))).thenAnswer(new Answer<Descriptor>() {

        @Override
        public Descriptor answer(InvocationOnMock invocation) throws Throwable {
            Class<? extends Descriptor> descriptorType = (Class<? extends Descriptor>) invocation.getArguments()[1];
            return mock(descriptorType);
        }
    });
    Map<String, ScannerPlugin<?, ?>> scannerPlugins = new HashMap<>();
    scannerPlugins.put("TestScanner1", new TestScannerPlugin1());
    scannerPlugins.put("TestScanner2", new TestScannerPlugin2());
    scannerPlugins.put("TestScanner2A", new TestScannerPlugin2A());
    Scanner scanner = new ScannerImpl(new ScannerConfiguration(), scannerContext, scannerPlugins, Collections.<String, Scope>emptyMap());
    Descriptor descriptor = scanner.scan(new TestItem(), "/", DefaultScope.NONE);
    assertThat(descriptor, instanceOf(TestDescriptor2.class));
    verify(store).create(Mockito.eq(TestDescriptor1.class));
    verify(store).addDescriptorType(Mockito.any(TestDescriptor1.class), Mockito.eq(TestDescriptor2A.class));
    verify(store).addDescriptorType(Mockito.any(TestDescriptor2A.class), Mockito.eq(TestDescriptor2.class));
    verify(scannerContext).push(Mockito.eq(TestDescriptor1.class), Mockito.any(TestDescriptor1.class));
    verify(scannerContext).peek(TestDescriptor1.class);
    verify(scannerContext).pop(TestDescriptor1.class);
}
Also used : HashMap(java.util.HashMap) Store(com.buschmais.jqassistant.core.store.api.Store) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Descriptor(com.buschmais.jqassistant.core.store.api.model.Descriptor) Test(org.junit.Test)

Aggregations

Store (com.buschmais.jqassistant.core.store.api.Store)1 Descriptor (com.buschmais.jqassistant.core.store.api.model.Descriptor)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1