Point implements Comparable<Point> { public void moveToward(Point point, double distance) { if (distance(point) < distance) { this.x = point.x; this.y = point.y; if (path.peek() == point) { path.remove(); } return; } double deltaX = this.x - point.x; double deltaY = this.y - point.y; double angle; angle = Math.atan2(deltaY, deltaX) + Math.PI; double xShift = Math.cos(angle) * distance; double yShift = Math.sin(angle) * distance; this.x += xShift; this.y += yShift; } Point(double x, double y);  Point(Point point);  Point(String point); double getX(); double getY(); double distance(Point point); void moveToward(Point point, double distance); void pathToward(Point destination, double distance); boolean nextStep(Point point, double distance); @Override String toString(); String toNeatString(); @Override boolean equals(Object object); boolean lazyEquals(Object object); @Override int hashCode(); @Override int compareTo(Point point);  }
@Test public void moveTowardTest() { WorldManager mockWorldManager = PowerMockito.mock(WorldManager.class); World mockWorld = mock(World.class); Tile mockTile = mock(Tile.class); when(mockTile.getTileEntity()).thenReturn(null); when(mockTile.getTileType()).thenReturn(1); PowerMockito.mockStatic(WorldManager.class); PowerMockito.when(WorldManager.getInstance()).thenReturn(mockWorldManager); when(mockWorldManager.getWorld()).thenReturn(mockWorld); when(mockWorld.getTile(anyObject())).thenReturn(mockTile); when(mockTile.getProperty(TileProperty.PASSABLE)).thenReturn(true); Point point = new Point(1.1, 2); Assert.assertEquals("Distance calculation error.", 0.1, point.distance(testPoint2), 0.0001); point.moveToward(testPoint2, 3); Assert.assertEquals("Distance calculation error.", 0, point.distance(testPoint2), 0.0001); Point target = new Point(5, 5); double distanceToMove = 1; double distanceToTarget = point.distance(target); point.moveToward(target, distanceToMove); Assert.assertEquals("Move toward error.", distanceToMove, distanceToTarget - point.distance(target), 0.0001); distanceToTarget = point.distance(target); point.moveToward(target, distanceToMove); Assert.assertEquals("Move toward error.", distanceToMove, distanceToTarget - point.distance(target), 0.0001); distanceToTarget = point.distance(target); point.moveToward(target, distanceToMove); Assert.assertEquals("Move toward error.", distanceToMove, distanceToTarget - point.distance(target), 0.0001); distanceToTarget = point.distance(target); }