@Override public ImmutableType call() throws Exception { return fqnIndexer.lookup(fqn); } });
E type = lookup(template); if (null != type) { results = new ArrayList<>(1);
@Test public void find() throws Exception { String fqn = "fqn"; when(fqnIndexer.lookup(fqn)).thenReturn(type); ImmutableType type = lookup.findByFQN(fqn); assertThat((Type) type, is(type)); verify(fqnIndexer, times(1)).lookup(fqn); verify(classCache, times(1)).executeWithReadLock(Matchers.<Callable<?>> anyObject()); verifyNoMoreInteractions(fqnIndexer, classCache); verifyZeroInteractions(hashIndexer); } }
@Test public void sameFqnTwice() { ClassType stringType1 = new ClassType(String.class.getName()); ClassType stringType2 = new ClassType(String.class.getName()); indexer.index(stringType1); indexer.index(stringType2); ClassType lookup = indexer.lookup(String.class.getName()); assertThat(indexer, hasSize(1)); assertThat(lookup == stringType2, is(true)); }
@Test public void notFound() { 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); ClassType lookup = indexer.lookup("nonExistingType"); assertThat(indexer, hasSize(3)); assertThat(lookup, is(nullValue())); }
@Test public void replace() { ClassType stringType = new ClassType(String.class.getName()); ClassType objectType = new ClassType(Object.class.getName()); ClassType thisType = new ClassType(FqnIndexer.class.getName()); ClassType secondObjectType = new ClassType(Object.class.getName()); indexer.index(stringType); indexer.index(thisType); indexer.index(objectType); indexer.index(secondObjectType); ClassType lookup = indexer.lookup(Object.class.getName()); assertThat(indexer, hasSize(3)); assertThat(System.identityHashCode(lookup), is(System.identityHashCode(secondObjectType))); } }
@Test public void lookup() { 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(new ClassType("a")); indexer.index(new ClassType("java.nolang")); indexer.index(objectType); ClassType stringLookup = indexer.lookup(stringType.getFQN()); ClassType objectLookup = indexer.lookup(objectType.getFQN()); ClassType thisTypeLookup = indexer.lookup(thisType.getFQN()); assertThat(indexer, hasSize(5)); assertThat(stringLookup, is(stringType)); assertThat(objectLookup, is(objectType)); assertThat(thisTypeLookup, is(thisType)); }