RandomVelocityMovementBehavior extends BehaviorAdapter { @Override public void update(GameObject source, float delta) { timer.update(delta); if (timer.reached(interval) && source.isActive()) { timer.reset(); changeDirection(); changeInterval(); } source.move(direction.x * velocity.x * delta, direction.y * velocity.y * delta); } RandomVelocityMovementBehavior();  RandomVelocityMovementBehavior(Random random); @Override void update(GameObject source, float delta);  }
@Test public void testRandomVelocity() { GameObject obj = mock(GameObject.class); RandomVelocityMovementBehavior behavior = new RandomVelocityMovementBehavior(); behavior.update(obj, 1f); verify(obj).move(xCaptor.capture(), yCaptor.capture()); assertNotSame(xCaptor.getValue(), yCaptor.getValue()); float oldX = xCaptor.getValue(); float oldY = yCaptor.getValue(); behavior.update(obj, 1f); verify(obj, times(2)).move(xCaptor.capture(), yCaptor.capture()); assertNotSame(oldX, xCaptor.getValue()); assertNotSame(oldY, yCaptor.getValue()); assertNotSame(xCaptor.getValue(), yCaptor.getValue()); }