FrameAnimation extends Animation { @Override public void update() { if (!animationStopped) { timeDifference += System.currentTimeMillis() - lastSystemMilliseconds; lastSystemMilliseconds = System.currentTimeMillis(); while (animationFrames[frame].getDuration() <= timeDifference * speed) { timeDifference -= animationFrames[frame].getDuration() / speed; frame++; if (frame == getAnimationLength()) { frame = 0; if (!looping) { reset(); } } } } } FrameAnimation(Frame[] animationFrames);  FrameAnimation(Frame[] animationFrames, boolean looping,
                          float speed); @Override void update(); @Override void renderAnimation(GraphicsContext graphicsContext, double x,
                                double y); Frame getCurrentFrame();  }
@Test public void testUpdate() throws InterruptedException { animation = new FrameAnimation(frames); animation.start(); Thread.sleep(100); animation.update(); assertTrue(animation.getCurrentFrame().equals(frames[1])); Thread.sleep(150); animation.update(); assertTrue(animation.getCurrentFrame().equals(frames[2])); }
@Test public void testNoLooping() throws Exception{ animation = new FrameAnimation(frames); animation.setLooping(false); animation.start(); Thread.sleep(350); animation.update(); assertTrue(animation.isAnimationStopped()); }