StrategyInstanceResolver implements InstanceResolver { @Override public Collection<SagaInstanceInfo> resolve(final LookupContext context) { Collection<SagaInstanceInfo> allInstances = new ArrayList<>(); Collection<ResolveStrategy> resolveStrategies = strategyFinder.find(context); for (ResolveStrategy strategy : resolveStrategies) { Collection<SagaInstanceInfo> resolvedInstances = strategy.resolve(context); allInstances.addAll(resolvedInstances); } return allInstances; } @Inject  StrategyInstanceResolver(final StrategyFinder strategyFinder); @Override Collection<SagaInstanceInfo> resolve(final LookupContext context);  }
@Test public void resolve_finderReturnsStrategy_callResolveOnStrategy() { LookupContext context = mock(LookupContext.class); ResolveStrategy strategy = mockStrategy(context); sut.resolve(context); verify(strategy).resolve(context); }
@Test public void resolve_strategyReturnsInstance_instanceReturnedWithReturnValue() { ResolveStrategy strategy = mockStrategy(); SagaInstanceInfo instanceInfo = new SagaInstanceInfo(null, true); when(strategy.resolve(any())).thenReturn(Lists.newArrayList(instanceInfo)); Collection<SagaInstanceInfo> instances = sut.resolve(mock(LookupContext.class)); assertThat("Expected instance in result set.", instances, hasItem(instanceInfo)); }
@Test public void resolve_strategyReturnsEmptyList_resolveReturnListIsEmpty() { ResolveStrategy strategy = mockStrategy(); when(strategy.resolve(any(LookupContext.class))).thenReturn(Collections.<SagaInstanceInfo>emptyList()); Collection<SagaInstanceInfo> instances = sut.resolve(null); assertThat("Expected an empty list.", instances, hasSize(0)); }