1 /* 2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package test.javafx.animation; 27 28 import javafx.util.Duration; 29 import com.sun.scenario.animation.AbstractMasterTimer; 30 31 import static org.junit.Assert.*; 32 33 public class AnimationMock extends AnimationImpl { 34 35 public static final Duration DEFAULT_DURATION = Duration.seconds(1); 36 public static final double DEFAULT_RATE = 1.0; 37 public static final int DEFAULT_CYCLE_COUNT = 1; 38 public static final boolean DEFAULT_AUTOREVERSE = false; 39 private long lastTimePulse; 40 41 public enum Command {PLAY, JUMP, NONE}; 42 43 private Command lastCommand = Command.NONE; 44 private long lastCurrentTicks = -1; 45 private long lastCycleTicks = -1; 46 private boolean finishFlag; 47 48 public void mockStatus(Status status) { 49 this.setStatus(status); 50 } 51 52 public void mockCycleDuration(Duration duration) { 53 shim_setCycleDuration(duration); 54 } 55 56 public AnimationMock(AbstractMasterTimer timer, Duration cycleDuration, double rate, int cycleCount, boolean autoReverse) { 57 super(timer); 58 shim_setCycleDuration(cycleDuration); 59 setRate(rate); 60 setCycleCount(cycleCount); 61 setAutoReverse(autoReverse); 62 super.setOnFinished(event -> { 63 finishFlag = true; 64 }); 65 } 66 67 public void check(Command lastCommand, long lastCurrentTicks, long lastCycleTicks) { 68 assertEquals(lastCommand, this.lastCommand); 69 if (lastCommand != Command.NONE) { 70 assertEquals(lastCurrentTicks, this.lastCurrentTicks); 71 assertEquals(lastCycleTicks, this.lastCycleTicks); 72 } 73 this.lastCommand = Command.NONE; 74 this.lastCurrentTicks = -1; 75 this.lastCycleTicks = -1; 76 } 77 78 public boolean finishCalled() { 79 final boolean result = finishFlag; 80 finishFlag = false; 81 return result; 82 } 83 84 public long getLastTimePulse() { 85 final long p = lastTimePulse; 86 lastTimePulse = 0L; 87 return p; 88 } 89 90 91 @Override 92 public void impl_playTo(long currentTicks, long cycleTicks) { 93 lastCommand = Command.PLAY; 94 lastCurrentTicks = currentTicks; 95 lastCycleTicks = cycleTicks; 96 } 97 98 @Override 99 public void impl_jumpTo(long currentTicks, long cycleTicks, boolean forceJump) { 100 lastCommand = Command.JUMP; 101 lastCurrentTicks = currentTicks; 102 lastCycleTicks = cycleTicks; 103 } 104 105 @Override 106 public void impl_timePulse(long elapsedTime) { 107 super.impl_timePulse(elapsedTime); 108 lastTimePulse = elapsedTime; 109 } 110 111 }