EntityDescriptor entityDescriptor = TestdataChainedEntity.buildEntityDescriptor();
GenuineVariableDescriptor variableDescriptor = entityDescriptor.getGenuineVariableDescriptor("chainedObject");
TestdataChainedAnchor a0 = new TestdataChainedAnchor("a0");
TestdataChainedEntity a1 = new TestdataChainedEntity("a1");
TestdataChainedEntity a2 = new TestdataChainedEntity("a2");
ValueSelector childValueSelector = SelectorTestUtils.mockValueSelector(variableDescriptor,
a0, a1, a2);
ValueSelector valueSelector = new InitializedValueSelector(childValueSelector);
verify(childValueSelector, times(1)).isNeverEnding();
DefaultSolverScope solverScope = mock(DefaultSolverScope.class);
valueSelector.solvingStarted(solverScope);
AbstractPhaseScope phaseScopeA = mock(AbstractPhaseScope.class);
when(phaseScopeA.getSolverScope()).thenReturn(solverScope);
valueSelector.phaseStarted(phaseScopeA);
AbstractStepScope stepScopeA1 = mock(AbstractStepScope.class);
when(stepScopeA1.getPhaseScope()).thenReturn(phaseScopeA);
valueSelector.stepStarted(stepScopeA1);
assertAllCodesOfValueSelectorForEntity(valueSelector, a1, PlannerAssert.DO_NOT_ASSERT_SIZE, "a0");
a1.setChainedObject(a0);
valueSelector.stepEnded(stepScopeA1);
AbstractStepScope stepScopeA2 = mock(AbstractStepScope.class);
when(stepScopeA2.getPhaseScope()).thenReturn(phaseScopeA);
valueSelector.stepStarted(stepScopeA2);
assertAllCodesOfValueSelectorForEntity(valueSelector, a2, PlannerAssert.DO_NOT_ASSERT_SIZE, "a0", "a1");
a2.setChainedObject(a1);
valueSelector.stepEnded(stepScopeA2);
valueSelector.phaseEnded(phaseScopeA);
AbstractPhaseScope phaseScopeB = mock(AbstractPhaseScope.class);
when(phaseScopeB.getSolverScope()).thenReturn(solverScope);
valueSelector.phaseStarted(phaseScopeB);
AbstractStepScope stepScopeB1 = mock(AbstractStepScope.class);
when(stepScopeB1.getPhaseScope()).thenReturn(phaseScopeB);
valueSelector.stepStarted(stepScopeB1);
assertAllCodesOfValueSelectorForEntity(valueSelector, a1, PlannerAssert.DO_NOT_ASSERT_SIZE, "a0", "a1", "a2");
valueSelector.stepEnded(stepScopeB1);
AbstractStepScope stepScopeB2 = mock(AbstractStepScope.class);
when(stepScopeB2.getPhaseScope()).thenReturn(phaseScopeB);
valueSelector.stepStarted(stepScopeB2);
assertAllCodesOfValueSelectorForEntity(valueSelector, a2, PlannerAssert.DO_NOT_ASSERT_SIZE, "a0", "a1", "a2");
valueSelector.stepEnded(stepScopeB2);
valueSelector.phaseEnded(phaseScopeB);
valueSelector.solvingEnded(solverScope);
verifyPhaseLifecycle(childValueSelector, 1, 2, 4);
verify(childValueSelector, times(4)).iterator(any());
}