@Override public Collection<Type> call() throws Exception { return fqnIndexer.findAll(); } });
@Override public Collection<ImmutableType> call() throws Exception { Collection<ImmutableType> result = new ArrayList<>(); for (ImmutableType type : fqnIndexer.findAll()) { if (type.isClass() && type.isInitialized()) { if (type.castToClass().hasInstrumentationPoints()) { result.add(type); } } } return result; } });
@Test @SuppressWarnings("unchecked") public void exceptionInCallable() throws Exception { when(fqnIndexer.findAll()).thenThrow(RuntimeException.class); Collection<? extends ImmutableType> result = lookup.findInstrumentedTypes(); verify(classCache).executeWithReadLock(any(Callable.class)); verify(fqnIndexer).findAll(); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); assertThat(result, hasSize(0)); } }
@Test @SuppressWarnings("unchecked") public void typeNotAClass() throws Exception { when(fqnIndexer.findAll()).thenReturn(Arrays.asList(type)); when(type.isClass()).thenReturn(false); Collection<? extends ImmutableType> result = lookup.findInstrumentedTypes(); verify(classCache).executeWithReadLock(any(Callable.class)); verify(fqnIndexer).findAll(); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); assertThat(result, hasSize(0)); }
@Test @SuppressWarnings("unchecked") public void typeNotInitialized() throws Exception { when(fqnIndexer.findAll()).thenReturn(Arrays.asList(type)); when(type.isClass()).thenReturn(true); when(type.isInitialized()).thenReturn(false); Collection<? extends ImmutableType> result = lookup.findInstrumentedTypes(); verify(classCache).executeWithReadLock(any(Callable.class)); verify(fqnIndexer).findAll(); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); assertThat(result, hasSize(0)); }
@Test @SuppressWarnings("unchecked") public void noClassesLoaded() throws Exception { Collection<? extends ImmutableType> result = lookup.findInstrumentedTypes(); verify(classCache).executeWithReadLock(any(Callable.class)); verify(fqnIndexer).findAll(); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); assertThat(result, hasSize(0)); }
@Test @SuppressWarnings("unchecked") public void noInstrumentedTypes() throws Exception { when(fqnIndexer.findAll()).thenReturn(Arrays.asList(type)); when(type.isClass()).thenReturn(true); when(type.isInitialized()).thenReturn(true); when(type.castToClass()).thenReturn(classType); when(classType.hasInstrumentationPoints()).thenReturn(false); Collection<? extends ImmutableType> result = lookup.findInstrumentedTypes(); verify(classCache).executeWithReadLock(any(Callable.class)); verify(fqnIndexer).findAll(); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); assertThat(result, hasSize(0)); }
@Test @SuppressWarnings("unchecked") public void find() throws Exception { when(fqnIndexer.findAll()).thenReturn(Arrays.asList(type)); when(type.isClass()).thenReturn(true); when(type.isInitialized()).thenReturn(true); when(type.castToClass()).thenReturn(classType); when(classType.hasInstrumentationPoints()).thenReturn(true); Collection<ImmutableType> result = (Collection<ImmutableType>) lookup.findInstrumentedTypes(); verify(classCache).executeWithReadLock(any(Callable.class)); verify(fqnIndexer).findAll(); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); assertThat(result, hasSize(1)); assertThat(result, hasItem(type)); }
@Test public void findAll() { ClassType stringType = new ClassType(String.class.getName()); ClassType objectType = new ClassType(Object.class.getName()); ClassType thisType = new ClassType(FqnIndexer.class.getName()); indexer.index(stringType); indexer.index(thisType); indexer.index(objectType); Collection<ClassType> types = indexer.findAll(); assertThat(types, hasSize(3)); assertThat(types, hasItem(stringType)); assertThat(types, hasItem(objectType)); assertThat(types, hasItem(thisType)); } }