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 javafx.animation;
27
28 import javafx.event.ActionEvent;
29 import javafx.event.EventHandler;
30 import javafx.util.Duration;
31 import com.sun.scenario.animation.AbstractMasterTimer;
32
33 import static org.junit.Assert.*;
34
35 public class AnimationMock extends Animation {
36
37 public static final Duration DEFAULT_DURATION = Duration.seconds(1);
38 public static final double DEFAULT_RATE = 1.0;
39 public static final int DEFAULT_CYCLE_COUNT = 1;
40 public static final boolean DEFAULT_AUTOREVERSE = false;
41 private long lastTimePulse;
42
43 public enum Command {PLAY, JUMP, NONE};
44
45 private Command lastCommand = Command.NONE;
46 private long lastCurrentTicks = -1;
47 private long lastCycleTicks = -1;
48 private boolean finishFlag;
49
50 public void mockStatus(Status status) {
51 this.setStatus(status);
52 }
53
54 public void mockCycleDuration(Duration duration) {
55 this.setCycleDuration(duration);
56 }
57
58 public AnimationMock(AbstractMasterTimer timer, Duration cycleDuration, double rate, int cycleCount, boolean autoReverse) {
59 super(timer);
60 setCycleDuration(cycleDuration);
61 setRate(rate);
62 setCycleCount(cycleCount);
63 setAutoReverse(autoReverse);
64 super.setOnFinished(event -> {
65 finishFlag = true;
66 });
67 }
68
69 public void check(Command lastCommand, long lastCurrentTicks, long lastCycleTicks) {
70 assertEquals(lastCommand, this.lastCommand);
71 if (lastCommand != Command.NONE) {
72 assertEquals(lastCurrentTicks, this.lastCurrentTicks);
73 assertEquals(lastCycleTicks, this.lastCycleTicks);
74 }
75 this.lastCommand = Command.NONE;
76 this.lastCurrentTicks = -1;
77 this.lastCycleTicks = -1;
78 }
79
80 public boolean finishCalled() {
88 lastTimePulse = 0L;
89 return p;
90 }
91
92
93 @Override
94 public void impl_playTo(long currentTicks, long cycleTicks) {
95 lastCommand = Command.PLAY;
96 lastCurrentTicks = currentTicks;
97 lastCycleTicks = cycleTicks;
98 }
99
100 @Override
101 public void impl_jumpTo(long currentTicks, long cycleTicks, boolean forceJump) {
102 lastCommand = Command.JUMP;
103 lastCurrentTicks = currentTicks;
104 lastCycleTicks = cycleTicks;
105 }
106
107 @Override
108 void impl_timePulse(long elapsedTime) {
109 super.impl_timePulse(elapsedTime);
110 lastTimePulse = elapsedTime;
111 }
112
113 }
|
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() {
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 }
|