Class MockProblemChangeDirector
java.lang.Object
org.optaplanner.test.api.solver.change.MockProblemChangeDirector
- All Implemented Interfaces:
ProblemChangeDirector
Use for unit-testing
ProblemChanges.
Together with Mockito this class makes it possible to verify that a
ProblemChange implementation correctly calls methods of
the ProblemChangeDirector.
Example of usage:
java
MockProblemChangeDirector mockProblemChangeDirector = spy(new MockProblemChangeDirector());
ProblemChange problemChange = new MyProblemChange(removedEntity);
problemChange.doChange(solution, mockProblemChangeDirector);
verify(mockProblemChangeDirector).removeEntity(same(removedEntity), any());
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<Entity> voidAdd a newPlanningEntityinstance into theworking solution.<ProblemFact>
voidaddProblemFact(ProblemFact problemFact, Consumer<ProblemFact> problemFactConsumer) Add a new problem fact into theworking solution.<EntityOrProblemFact>
voidchangeProblemProperty(EntityOrProblemFact problemFactOrEntity, Consumer<EntityOrProblemFact> problemFactOrEntityConsumer) Change a property of either aPlanningEntityor a problem fact.<Entity> voidchangeVariable(Entity entity, String variableName, Consumer<Entity> entityConsumer) Change aPlanningVariablevalue of aPlanningEntity.<EntityOrProblemFact>
Optional<EntityOrProblemFact>lookUpWorkingObject(EntityOrProblemFact externalObject) If the look-up result has been provided by awhenLookingUp(Object)call, returns the defined object.<EntityOrProblemFact>
EntityOrProblemFactlookUpWorkingObjectOrFail(EntityOrProblemFact externalObject) If the look-up result has been provided by awhenLookingUp(Object)call, returns the defined object.<Entity> voidremoveEntity(Entity entity, Consumer<Entity> entityConsumer) Remove an existingPlanningEntityinstance from theworking solution.<ProblemFact>
voidremoveProblemFact(ProblemFact problemFact, Consumer<ProblemFact> problemFactConsumer) Remove an existing problem fact from theworking solution.voidCalls variable listeners on the external changes submitted so far.whenLookingUp(Object forObject) Defines whatlookUpWorkingObjectOrFail(Object)returns.
-
Constructor Details
-
MockProblemChangeDirector
public MockProblemChangeDirector()
-
-
Method Details
-
addEntity
Description copied from interface:ProblemChangeDirectorAdd a newPlanningEntityinstance into theworking solution.- Specified by:
addEntityin interfaceProblemChangeDirector- Type Parameters:
Entity- the planning entity object type- Parameters:
entity- never null; thePlanningEntityinstanceentityConsumer- never null; adds the entity to theworking solution
-
removeEntity
Description copied from interface:ProblemChangeDirectorRemove an existingPlanningEntityinstance from theworking solution. Translates the entity to a working planning entity by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
removeEntityin interfaceProblemChangeDirector- Type Parameters:
Entity- the planning entity object type- Parameters:
entity- never null; thePlanningEntityinstanceentityConsumer- never null; removes the working entity from theworking solution
-
changeVariable
public <Entity> void changeVariable(Entity entity, String variableName, Consumer<Entity> entityConsumer) Description copied from interface:ProblemChangeDirectorChange aPlanningVariablevalue of aPlanningEntity. Translates the entity to a working planning entity by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
changeVariablein interfaceProblemChangeDirector- Type Parameters:
Entity- the planning entity object type- Parameters:
entity- never null; thePlanningEntityinstancevariableName- never null; name of thePlanningVariableentityConsumer- never null; updates the value of thePlanningVariableinside thePlanningEntity
-
addProblemFact
public <ProblemFact> void addProblemFact(ProblemFact problemFact, Consumer<ProblemFact> problemFactConsumer) Description copied from interface:ProblemChangeDirectorAdd a new problem fact into theworking solution.- Specified by:
addProblemFactin interfaceProblemChangeDirector- Type Parameters:
ProblemFact- the problem fact object type- Parameters:
problemFact- never null; the problem fact instanceproblemFactConsumer- never null; removes the working problem fact from theworking solution
-
removeProblemFact
public <ProblemFact> void removeProblemFact(ProblemFact problemFact, Consumer<ProblemFact> problemFactConsumer) Description copied from interface:ProblemChangeDirectorRemove an existing problem fact from theworking solution. Translates the problem fact to a working problem fact by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
removeProblemFactin interfaceProblemChangeDirector- Type Parameters:
ProblemFact- the problem fact object type- Parameters:
problemFact- never null; the problem fact instanceproblemFactConsumer- never null; removes the working problem fact from theworking solution
-
changeProblemProperty
public <EntityOrProblemFact> void changeProblemProperty(EntityOrProblemFact problemFactOrEntity, Consumer<EntityOrProblemFact> problemFactOrEntityConsumer) Description copied from interface:ProblemChangeDirectorChange a property of either aPlanningEntityor a problem fact. Translates the entity or the problem fact to itsworking solutioncounterpart by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object).- Specified by:
changeProblemPropertyin interfaceProblemChangeDirector- Type Parameters:
EntityOrProblemFact- the planning entity or problem fact object type- Parameters:
problemFactOrEntity- never null; thePlanningEntityor the problem fact instanceproblemFactOrEntityConsumer- never null; updates the property of thePlanningEntityor the problem fact
-
lookUpWorkingObjectOrFail
public <EntityOrProblemFact> EntityOrProblemFact lookUpWorkingObjectOrFail(EntityOrProblemFact externalObject) If the look-up result has been provided by awhenLookingUp(Object)call, returns the defined object. Otherwise, returns the original externalObject.- Specified by:
lookUpWorkingObjectOrFailin interfaceProblemChangeDirector- Type Parameters:
EntityOrProblemFact- the object type- Parameters:
externalObject- entity or problem fact to look up- Returns:
- null if externalObject is null
-
lookUpWorkingObject
public <EntityOrProblemFact> Optional<EntityOrProblemFact> lookUpWorkingObject(EntityOrProblemFact externalObject) If the look-up result has been provided by awhenLookingUp(Object)call, returns the defined object. Otherwise, returns null.- Specified by:
lookUpWorkingObjectin interfaceProblemChangeDirector- Type Parameters:
EntityOrProblemFact- the object type- Parameters:
externalObject- entity or problem fact to look up- Returns:
Optional.empty()if externalObject is null or if there is no workingObject for externalObject
-
updateShadowVariables
public void updateShadowVariables()Description copied from interface:ProblemChangeDirectorCalls variable listeners on the external changes submitted so far.- Specified by:
updateShadowVariablesin interfaceProblemChangeDirector
-
whenLookingUp
Defines whatlookUpWorkingObjectOrFail(Object)returns.
-