@Override public Collection<Type> call() throws Exception { return fqnIndexer.findByPattern(pattern); } });
@Test public void equalsPatternNonExistingElement() { EqualsMatchPattern equalsMatchPattern = new EqualsMatchPattern("whatever"); Collection<ClassType> results = indexer.findByPattern(equalsMatchPattern); assertThat(results, is(empty())); } }
@Test public void notFound() throws Exception { when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenReturn(Collections.<Type> emptyList()); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableType> types = lookup.findByPattern("somethingElse", false); assertThat(types, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); } }
@Test public void initializedAllTypes() throws Exception { String pattern = "pattern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableType> nonInitializedTypes = lookup.findByPattern(pattern, false); assertThat(nonInitializedTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void initializedOnlyInitializedTypes() throws Exception { String pattern = "pattern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableType> intializedTypes = lookup.findByPattern(pattern, true); assertThat(intializedTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void notInitializedOnlyInitializedTypes() throws Exception { String pattern = "pattern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.isInitialized()).thenReturn(false); Collection<? extends ImmutableType> intializedTypes = lookup.findByPattern(pattern, true); assertThat(intializedTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void notInitializedAllTypes() throws Exception { String pattern = "pattern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.isInitialized()).thenReturn(false); Collection<? extends ImmutableType> nonInitializedTypes = lookup.findByPattern(pattern, false); assertThat(nonInitializedTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void notFoundOnlyInitializedTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isClass()).thenReturn(false); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableClassType> initializedTypes = lookup.findClassTypesByPattern(pattern, true); assertThat(initializedTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void notFoundOnlyInitializedTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isAnnotation()).thenReturn(false); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableAnnotationType> initializedTypes = lookup.findAnnotationTypesByPattern(pattern, true); assertThat(initializedTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void notFoundAllTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isInterface()).thenReturn(false); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableInterfaceType> allTypes = lookup.findInterfaceTypesByPattern(pattern, false); assertThat(allTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); } }
@Test public void notFoundAllTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isAnnotation()).thenReturn(false); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableAnnotationType> allTypes = lookup.findAnnotationTypesByPattern(pattern, false); assertThat(allTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); } }
@Test public void notFoundOnlyInitializedTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isInterface()).thenReturn(false); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableInterfaceType> initializedTypes = lookup.findInterfaceTypesByPattern(pattern, true); assertThat(initializedTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void initializedOnlyInitializedTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isClass()).thenReturn(true); when(type.castToClass()).thenReturn(classType); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableClassType> initializedTypes = lookup.findClassTypesByPattern(pattern, true); assertThat(initializedTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void notInitializedOnlyInitializedTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isClass()).thenReturn(true); when(type.castToClass()).thenReturn(classType); when(type.isInitialized()).thenReturn(false); Collection<? extends ImmutableClassType> initializedTypes = lookup.findClassTypesByPattern(pattern, true); assertThat(initializedTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void nonInitializedAllTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isAnnotation()).thenReturn(true); when(type.castToAnnotation()).thenReturn(annotationType); when(type.isInitialized()).thenReturn(false); Collection<? extends ImmutableAnnotationType> allTypes = lookup.findAnnotationTypesByPattern(pattern, false); assertThat(allTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void initializedOnlyInitializedTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isInterface()).thenReturn(true); when(type.castToInterface()).thenReturn(interfaceType); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableInterfaceType> initializedTypes = lookup.findInterfaceTypesByPattern(pattern, true); assertThat(initializedTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void initializedAllTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isInterface()).thenReturn(true); when(type.castToInterface()).thenReturn(interfaceType); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableInterfaceType> allTypes = lookup.findInterfaceTypesByPattern(pattern, false); assertThat(allTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void nonInitializedOnlyInitializedTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isAnnotation()).thenReturn(true); when(type.castToAnnotation()).thenReturn(annotationType); when(type.isInitialized()).thenReturn(false); Collection<? extends ImmutableAnnotationType> initializedTypes = lookup.findAnnotationTypesByPattern(pattern, true); assertThat(initializedTypes, is(empty())); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void notInitializedAllTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isInterface()).thenReturn(true); when(type.castToInterface()).thenReturn(interfaceType); when(type.isInitialized()).thenReturn(false); Collection<? extends ImmutableInterfaceType> allTypes = lookup.findInterfaceTypesByPattern(pattern, false); assertThat(allTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }
@Test public void initializedAllTypes() throws Exception { String pattern = "pat*tern"; when(fqnIndexer.findByPattern(Matchers.<IMatchPattern> any())).thenAnswer(typeSearchAnswer); when(type.getFQN()).thenReturn("pattttern"); when(type.isAnnotation()).thenReturn(true); when(type.castToAnnotation()).thenReturn(annotationType); when(type.isInitialized()).thenReturn(true); Collection<? extends ImmutableAnnotationType> initializedTypes = lookup.findAnnotationTypesByPattern(pattern, true); assertThat(initializedTypes, hasSize(1)); verify(fqnIndexer, times(1)).findByPattern(Matchers.<IMatchPattern> any()); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); }