AnnotationSagaAnalyzer implements SagaAnalyzer { @Override public Map<Class<? extends Saga>, SagaHandlersMap> scanHandledMessageTypes() { if (scanResult == null) { populateSagaHandlers(); } return scanResult; } @Inject  AnnotationSagaAnalyzer(final TypeScanner typeScanner); @Override Map<Class<? extends Saga>, SagaHandlersMap> scanHandledMessageTypes(); void addStartSagaAnnotation(final Class<? extends Annotation> annotationClass); void addHandlerAnnotation(final Class<? extends Annotation> annotationClass);  }
@Test public void scanHandledMessageTypes_noTypesFound_returnsEmptyMap() { sagaTypes.clear(); Map<Class<? extends Saga>, SagaHandlersMap> scanResult = sut.scanHandledMessageTypes(); assertThat("Expected empty map if no data present.", scanResult, not(nullValue())); }
@Test public void scanHandledMessageTypes_testSagaFound_returnsEntryWithHandlers() { sagaTypes.add(TestSaga.class); Map<Class<? extends Saga>, SagaHandlersMap> scanResult = sut.scanHandledMessageTypes(); assertThat("Expected one entry in scan result.", scanResult.size(), equalTo(1)); assertThat("Expected entry of key TestSage.class", scanResult.containsKey(TestSaga.class), is(true)); SagaHandlersMap handlers = scanResult.get(TestSaga.class); assertThat("Expected three total message handlers for saga.", handlers.messageHandlers(), hasSize(3)); }
@Test public void scanHandledMessageTypes_testSagaFound_returnsStartHandlerOfTypeString() throws NoSuchMethodException { sagaTypes.add(TestSaga.class); Map<Class<? extends Saga>, SagaHandlersMap> scanResult = sut.scanHandledMessageTypes(); SagaHandlersMap handlers = scanResult.get(TestSaga.class); assertThat( "Handler has entry with start saga flag set.", handlers.messageHandlers(), hasItem(samePropertyValuesAs(new MessageHandler(String.class, TestSaga.startupMethod(), true)))); }
@Test public void scanHandledMessageTypes_testSagaFound_returnsNormalHandlerOfTypeFinishedMessage() throws NoSuchMethodException { sagaTypes.add(TestSaga.class); Map<Class<? extends Saga>, SagaHandlersMap> scanResult = sut.scanHandledMessageTypes(); SagaHandlersMap handlers = scanResult.get(TestSaga.class); assertThat( "Handler has entry with start saga flag set.", handlers.messageHandlers(), hasItem(samePropertyValuesAs(new MessageHandler(FinishMessage.class, TestSaga.handlerMethod(), false)))); }