@Test public void testAppliesTo() throws Exception { GameScene theScene = mock(GameScene.class); Property theLayoutProperty = mock(Property.class); when(theScene.layoutBoundsProperty()).thenReturn(theLayoutProperty); GameObjectInstanceLeftLayoutCondition theCondition = new GameObjectInstanceLeftLayoutCondition(); assertSame(ConditionResult.NOT_FULFILLED, theCondition.appliesTo(theScene, null)); Property theProperty = mock(Property.class); when(theProperty.get()).thenReturn(new Position(10, 10)); PropertyChanged theChanged = new PropertyChanged(theProperty, null); assertSame(ConditionResult.NOT_FULFILLED, theCondition.appliesTo(theScene, theChanged)); GameObject theObject = mock(GameObject.class); GameObjectInstance theInstance = mock(GameObjectInstance.class); when(theInstance.getOwnerGameObject()).thenReturn(theObject); when(theProperty.getName()).thenReturn(GameObjectInstance.POSITION_PROPERTY); when(theProperty.getOwner()).thenReturn(theInstance); theCondition.gameObjectProperty().set(theObject); when(theLayoutProperty.get()).thenReturn(new Rectangle(new Position(0, 0), new Size(50,50))); assertSame(ConditionResult.NOT_FULFILLED, theCondition.appliesTo(theScene, theChanged)); verify(theProperty).getOwner(); verify(theInstance).getOwnerGameObject(); when(theLayoutProperty.get()).thenReturn(new Rectangle(new Position(100, 100), new Size(50,50))); ConditionResult theResult = theCondition.appliesTo(theScene, theChanged); assertNotSame(ConditionResult.NOT_FULFILLED, theResult); assertTrue(theResult.isConditionTrue()); assertSame(theChanged, theResult.getEvent()); assertEquals(1, theResult.getAffectedInstances().length); assertSame(theInstance,theResult.getAffectedInstances()[0]); }
@Override public ConditionResult appliesTo(GameScene aScene, GameEvent aEvent) { if (aEvent instanceof PropertyChanged) { PropertyChanged theChanged = (PropertyChanged) aEvent; if (GameObjectInstance.POSITION_PROPERTY.equals(theChanged.property.getName())) { Object theChangedObject = theChanged.getOwner(); if (theChangedObject instanceof GameObjectInstance) { GameObjectInstance theInstance = (GameObjectInstance) theChangedObject; if (theInstance.getOwnerGameObject() == gameObject.get()) { Rectangle theLayoutBounds = aScene.layoutBoundsProperty().get(); Position theNewPosition = (Position) theChanged.property.get(); if (!theLayoutBounds.contains(theNewPosition)) { return new ConditionResult(true, aEvent, new GameObjectInstance[] {theInstance}); } } } } } return ConditionResult.NOT_FULFILLED; }
GameObjectInstanceLeftLayoutCondition implements Condition { @Override public ConditionResult appliesTo(GameScene aScene, GameEvent aEvent) { if (aEvent instanceof PropertyChanged) { PropertyChanged theChanged = (PropertyChanged) aEvent; if (GameObjectInstance.POSITION_PROPERTY.equals(theChanged.property.getName())) { Object theChangedObject = theChanged.getOwner(); if (theChangedObject instanceof GameObjectInstance) { GameObjectInstance theInstance = (GameObjectInstance) theChangedObject; if (theInstance.getOwnerGameObject() == gameObject.get()) { Rectangle theLayoutBounds = aScene.layoutBoundsProperty().get(); Position theNewPosition = (Position) theChanged.property.get(); if (!theLayoutBounds.contains(theNewPosition)) { return new ConditionResult(true, aEvent, new GameObjectInstance[] {theInstance}); } } } } } return ConditionResult.NOT_FULFILLED; } }
GameObjectInstanceLeftLayoutCondition implements Condition { @Override public ConditionResult appliesTo(GameScene aScene, GameEvent aEvent) { if (aEvent instanceof PropertyChanged) { PropertyChanged theChanged = (PropertyChanged) aEvent; if (GameObjectInstance.POSITION_PROPERTY.equals(theChanged.property.getName())) { Object theChangedObject = theChanged.getOwner(); if (theChangedObject instanceof GameObjectInstance) { GameObjectInstance theInstance = (GameObjectInstance) theChangedObject; if (theInstance.getOwnerGameObject() == gameObject.get()) { Rectangle theLayoutBounds = aScene.layoutBoundsProperty().get(); Position theNewPosition = (Position) theChanged.property.get(); if (!theLayoutBounds.contains(theNewPosition)) { return new ConditionResult(true, aEvent, new GameObjectInstance[] {theInstance}); } } } } } return ConditionResult.NOT_FULFILLED; } @UsedByReflection  GameObjectInstanceLeftLayoutCondition(); }
GameObjectInstanceLeftLayoutCondition implements Condition { @Override public ConditionResult appliesTo(GameScene aScene, GameEvent aEvent) { if (aEvent instanceof PropertyChanged) { PropertyChanged theChanged = (PropertyChanged) aEvent; if (GameObjectInstance.POSITION_PROPERTY.equals(theChanged.property.getName())) { Object theChangedObject = theChanged.getOwner(); if (theChangedObject instanceof GameObjectInstance) { GameObjectInstance theInstance = (GameObjectInstance) theChangedObject; if (theInstance.getOwnerGameObject() == gameObject.get()) { Rectangle theLayoutBounds = aScene.layoutBoundsProperty().get(); Position theNewPosition = (Position) theChanged.property.get(); if (!theLayoutBounds.contains(theNewPosition)) { return new ConditionResult(true, aEvent, new GameObjectInstance[] {theInstance}); } } } } } return ConditionResult.NOT_FULFILLED; } @UsedByReflection  GameObjectInstanceLeftLayoutCondition(); Property<GameObject> gameObjectProperty(); @Override ConditionResult appliesTo(GameScene aScene, GameEvent aEvent); @Override Map<String, Object> serialize(); static GameObjectInstanceLeftLayoutCondition unmarshall(GameScene aGameScene, Map<String, Object> aSerializedData); }
GameObjectInstanceLeftLayoutCondition implements Condition { @Override public ConditionResult appliesTo(GameScene aScene, GameEvent aEvent) { if (aEvent instanceof PropertyChanged) { PropertyChanged theChanged = (PropertyChanged) aEvent; if (GameObjectInstance.POSITION_PROPERTY.equals(theChanged.property.getName())) { Object theChangedObject = theChanged.getOwner(); if (theChangedObject instanceof GameObjectInstance) { GameObjectInstance theInstance = (GameObjectInstance) theChangedObject; if (theInstance.getOwnerGameObject() == gameObject.get()) { Rectangle theLayoutBounds = aScene.layoutBoundsProperty().get(); Position theNewPosition = (Position) theChanged.property.get(); if (!theLayoutBounds.contains(theNewPosition)) { return new ConditionResult(true, aEvent, new GameObjectInstance[] {theInstance}); } } } } } return ConditionResult.NOT_FULFILLED; } @UsedByReflection  GameObjectInstanceLeftLayoutCondition(); Property<GameObject> gameObjectProperty(); @Override ConditionResult appliesTo(GameScene aScene, GameEvent aEvent); @Override Map<String, Object> serialize(); static GameObjectInstanceLeftLayoutCondition unmarshall(GameScene aGameScene, Map<String, Object> aSerializedData); static final String GAME_OBJECT_PROPERTY; }