ReflectionsTypeScanner implements TypeScanner { @Override public Collection<Class<? extends Saga>> scanForSagas() { Set<Class<? extends Saga>> sagaTypes = reflections.getSubTypesOf(Saga.class); Set<Class<? extends AbstractSaga>> abstractSagaTypes = reflections.getSubTypesOf(AbstractSaga.class); Set<Class<? extends AbstractSingleEventSaga>> singleEventSagaTypes = reflections.getSubTypesOf(AbstractSingleEventSaga.class); Set<Class<? extends Saga>> foundTypes = Sets.union(sagaTypes, abstractSagaTypes); Set<Class<? extends Saga>> mergedSet = Sets.union(foundTypes, copy(singleEventSagaTypes)); return removeAbstractTypes(mergedSet); } ReflectionsTypeScanner();  ReflectionsTypeScanner(final Reflections reflections); @Override Collection<Class<? extends Saga>> scanForSagas();  }
@Test public void scanForSagas_defaultCtor_returnsTestSaga() { ReflectionsTypeScanner sut = new ReflectionsTypeScanner(); Collection<Class<? extends Saga>> foundSagas = sut.scanForSagas(); assertThat("Expected TestSaga from class path to be found.", foundSagas, hasItem((Class<? extends Saga>) TestSaga.class)); }
@Test public void scanForSagas_defaultCtor_doesNotReturnAbstractBaseClass() { ReflectionsTypeScanner sut = new ReflectionsTypeScanner(); Collection<Class<? extends Saga>> foundSagas = sut.scanForSagas(); assertThat("Expected not to find AbstractSaga in returned list.", foundSagas, not(hasItem(AbstractSaga.class))); }
@Test public void scanForSagas_reflectionsCtor_returnsEmptyListFromReflectionsParam() { Reflections reflections = mock(Reflections.class); when(reflections.getSubTypesOf(any(Class.class))).thenReturn(new HashSet<>()); ReflectionsTypeScanner sut = new ReflectionsTypeScanner(reflections); Collection<Class<? extends Saga>> foundSagas = sut.scanForSagas(); assertThat("Expected return value to be an empty list.", foundSagas.size(), equalTo(0)); }