Class MockProblemChangeDirector
- java.lang.Object
-
- org.optaplanner.test.api.solver.change.MockProblemChangeDirector
-
- All Implemented Interfaces:
ProblemChangeDirector
public class MockProblemChangeDirector extends Object implements ProblemChangeDirector
Use for unit-testingProblemChange
s. Together with Mockito this class makes it possible to verify that aProblemChange
implementation correctly calls methods of theProblemChangeDirector
. 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 Modifier and Type Class Description class
MockProblemChangeDirector.LookUpMockBuilder
-
Constructor Summary
Constructors Constructor Description MockProblemChangeDirector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <Entity> void
addEntity(Entity entity, Consumer<Entity> entityConsumer)
Add a newPlanningEntity
instance 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 aPlanningEntity
or a problem fact.<Entity> void
changeVariable(Entity entity, String variableName, Consumer<Entity> entityConsumer)
Change aPlanningVariable
value 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> void
removeEntity(Entity entity, Consumer<Entity> entityConsumer)
Remove an existingPlanningEntity
instance from theworking solution
.<ProblemFact>
voidremoveProblemFact(ProblemFact problemFact, Consumer<ProblemFact> problemFactConsumer)
Remove an existing problem fact from theworking solution
.MockProblemChangeDirector.LookUpMockBuilder
whenLookingUp(Object forObject)
Defines whatlookUpWorkingObjectOrFail(Object)
returns.
-
-
-
Method Detail
-
addEntity
public <Entity> void addEntity(Entity entity, Consumer<Entity> entityConsumer)
Description copied from interface:ProblemChangeDirector
Add a newPlanningEntity
instance into theworking solution
.- Specified by:
addEntity
in interfaceProblemChangeDirector
- Type Parameters:
Entity
- the planning entity object type- Parameters:
entity
- never null; thePlanningEntity
instanceentityConsumer
- never null; adds the entity to theworking solution
-
removeEntity
public <Entity> void removeEntity(Entity entity, Consumer<Entity> entityConsumer)
Description copied from interface:ProblemChangeDirector
Remove an existingPlanningEntity
instance from theworking solution
. Translates the entity to a working planning entity by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object)
.- Specified by:
removeEntity
in interfaceProblemChangeDirector
- Type Parameters:
Entity
- the planning entity object type- Parameters:
entity
- never null; thePlanningEntity
instanceentityConsumer
- 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:ProblemChangeDirector
Change aPlanningVariable
value of aPlanningEntity
. Translates the entity to a working planning entity by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object)
.- Specified by:
changeVariable
in interfaceProblemChangeDirector
- Type Parameters:
Entity
- the planning entity object type- Parameters:
entity
- never null; thePlanningEntity
instancevariableName
- never null; name of thePlanningVariable
entityConsumer
- never null; updates the value of thePlanningVariable
inside thePlanningEntity
-
addProblemFact
public <ProblemFact> void addProblemFact(ProblemFact problemFact, Consumer<ProblemFact> problemFactConsumer)
Description copied from interface:ProblemChangeDirector
Add a new problem fact into theworking solution
.- Specified by:
addProblemFact
in 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:ProblemChangeDirector
Remove 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:
removeProblemFact
in 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:ProblemChangeDirector
Change a property of either aPlanningEntity
or a problem fact. Translates the entity or the problem fact to itsworking solution
counterpart by performing a lookup as defined byProblemChangeDirector.lookUpWorkingObjectOrFail(Object)
.- Specified by:
changeProblemProperty
in interfaceProblemChangeDirector
- Type Parameters:
EntityOrProblemFact
- the planning entity or problem fact object type- Parameters:
problemFactOrEntity
- never null; thePlanningEntity
or the problem fact instanceproblemFactOrEntityConsumer
- never null; updates the property of thePlanningEntity
or 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:
lookUpWorkingObjectOrFail
in 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:
lookUpWorkingObject
in 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
-
whenLookingUp
public MockProblemChangeDirector.LookUpMockBuilder whenLookingUp(Object forObject)
Defines whatlookUpWorkingObjectOrFail(Object)
returns.
-
-