modules/graphics/src/test/java/test/javafx/animation/FillTransitionTest.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:

*** 21,32 **** * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package javafx.animation; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import javafx.scene.Group; --- 21,37 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package test.javafx.animation; + import javafx.animation.AnimationShim; + import javafx.animation.FillTransition; + import javafx.animation.Interpolator; + import javafx.animation.ParallelTransition; + import javafx.animation.TransitionShim; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import javafx.scene.Group;
*** 119,137 **** public void testInterpolate() { final Color fromValue = Color.color(0.2, 0.3, 0.7, 0.1); final Color toValue = Color.color(0.8, 0.4, 0.2, 0.9); final FillTransition t0 = new FillTransition(ONE_SEC, shape, fromValue, toValue); ! assertTrue(t0.impl_startable(false)); ! t0.impl_start(false); ! t0.interpolate(0.0); assertColorEquals(Color.color(0.2, 0.3, 0.7, 0.1), shape.getFill()); ! t0.interpolate(0.4); assertColorEquals(Color.color(0.44, 0.34, 0.5, 0.42), shape.getFill()); ! t0.interpolate(1.0); assertColorEquals(Color.color(0.8, 0.4, 0.2, 0.9), shape.getFill()); ! t0.impl_finished(); } @Test public void testValueCombinations() { final FillTransition t0 = new FillTransition(ONE_SEC, shape, null, Color.WHITE); --- 124,142 ---- public void testInterpolate() { final Color fromValue = Color.color(0.2, 0.3, 0.7, 0.1); final Color toValue = Color.color(0.8, 0.4, 0.2, 0.9); final FillTransition t0 = new FillTransition(ONE_SEC, shape, fromValue, toValue); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! AnimationShim.impl_start(t0,false); ! TransitionShim.interpolate(t0,0.0); assertColorEquals(Color.color(0.2, 0.3, 0.7, 0.1), shape.getFill()); ! TransitionShim.interpolate(t0,0.4); assertColorEquals(Color.color(0.44, 0.34, 0.5, 0.42), shape.getFill()); ! TransitionShim.interpolate(t0,1.0); assertColorEquals(Color.color(0.8, 0.4, 0.2, 0.9), shape.getFill()); ! AnimationShim.impl_finished(t0); } @Test public void testValueCombinations() { final FillTransition t0 = new FillTransition(ONE_SEC, shape, null, Color.WHITE);
*** 141,164 **** final Color fromValue = Color.color(from, from, from); // no from value set shape.setFill(originalValue); t0.setFromValue(null); ! assertTrue(t0.impl_startable(false)); ! t0.impl_start(false); ! t0.interpolate(0.0); assertColorEquals(originalValue, shape.getFill()); ! t0.impl_finished(); // from-value set shape.setFill(originalValue); t0.setFromValue(fromValue); ! assertTrue(t0.impl_startable(true)); ! t0.impl_start(true); ! t0.interpolate(0.0); assertColorEquals(fromValue, shape.getFill()); ! t0.impl_finished(); } @Test public void testGetTargetNode() { final Color fromValue = Color.color(0.0, 0.4, 0.8, 1.0); --- 146,169 ---- final Color fromValue = Color.color(from, from, from); // no from value set shape.setFill(originalValue); t0.setFromValue(null); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! AnimationShim.impl_start(t0,false); ! TransitionShim.interpolate(t0,0.0); assertColorEquals(originalValue, shape.getFill()); ! AnimationShim.impl_finished(t0); // from-value set shape.setFill(originalValue); t0.setFromValue(fromValue); ! assertTrue(AnimationShim.impl_startable(t0,true)); ! AnimationShim.impl_start(t0,true); ! TransitionShim.interpolate(t0,0.0); assertColorEquals(fromValue, shape.getFill()); ! AnimationShim.impl_finished(t0); } @Test public void testGetTargetNode() { final Color fromValue = Color.color(0.0, 0.4, 0.8, 1.0);
*** 171,356 **** pt.setNode(shape2); shape.setFill(Color.WHITE); shape2.setFill(Color.WHITE); // node set, parent set ! assertTrue(ft.impl_startable(false)); ! ft.impl_start(false); ! ft.interpolate(0.5); assertColorEquals(Color.color(0.5, 0.6, 0.7, 0.7), shape.getFill()); assertColorEquals(Color.WHITE, shape2.getFill()); ! ft.impl_finished(); // node null, parent set ft.setShape(null); ! assertTrue(ft.impl_startable(true)); ! ft.impl_start(true); ! ft.interpolate(0.4); assertColorEquals(Color.color(0.5, 0.6, 0.7, 0.7), shape.getFill()); assertColorEquals(Color.color(0.4, 0.56, 0.72, 0.76), shape2.getFill()); ! ft.impl_finished(); // node null, parent not shape set pt.setNode(new Group()); ! assertFalse(ft.impl_startable(true)); // node null, parent null pt.setNode(null); ! assertFalse(ft.impl_startable(true)); } @Test public void testCachedValues() { final Color fromValue = Color.color(0.0, 0.4, 0.8, 0.2); final Color toValue = Color.color(1.0, 0.8, 0.6, 0.4); final FillTransition ft = new FillTransition(ONE_SEC, shape, fromValue, toValue); ft.setInterpolator(Interpolator.LINEAR); // start ! assertTrue(ft.impl_startable(false)); ! ft.impl_start(false); ft.setFromValue(Color.WHITE); ! ft.interpolate(0.5); assertColorEquals(Color.color(0.5, 0.6, 0.7, 0.3), shape.getFill()); ! ft.impl_finished(); ft.setFromValue(fromValue); // end ! assertTrue(ft.impl_startable(true)); ! ft.impl_start(true); ft.setToValue(Color.BLACK); ! ft.interpolate(0.2); assertColorEquals(Color.color(0.2, 0.48, 0.76, 0.24), shape.getFill()); ! ft.impl_finished(); ft.setToValue(toValue); // shape ! assertTrue(ft.impl_startable(true)); ! ft.impl_start(true); ft.setShape(null); ! ft.interpolate(0.7); assertColorEquals(Color.color(0.7, 0.68, 0.66, 0.34), shape.getFill()); ! ft.impl_finished(); ft.setShape(shape); // interpolator ! assertTrue(ft.impl_startable(true)); ! ft.impl_start(true); ft.setInterpolator(null); ! ft.interpolate(0.1); assertColorEquals(Color.color(0.1, 0.44, 0.78, 0.22), shape.getFill()); ! ft.impl_finished(); ft.setInterpolator(Interpolator.LINEAR); } @Test public void testStartable_unsynchronized() { final FillTransition t0 = new FillTransition(Duration.ONE, shape, Color.WHITE, Color.BLACK); final Paint paint2 = new LinearGradient(0, 0, 1, 1, false, null, new Stop[] { new Stop(0, Color.RED) }); ! assertTrue(t0.impl_startable(true)); // duration is 0 t0.setDuration(Duration.ZERO); ! assertFalse(t0.impl_startable(true)); t0.setDuration(Duration.ONE); ! assertTrue(t0.impl_startable(true)); // interpolator is null t0.setInterpolator(null); ! assertFalse(t0.impl_startable(true)); t0.setInterpolator(Interpolator.LINEAR); ! assertTrue(t0.impl_startable(true)); // shape is null t0.setShape(null); ! assertFalse(t0.impl_startable(false)); ! assertFalse(t0.impl_startable(true)); t0.setShape(shape); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); // fromValue t0.setFromValue(null); shape.setFill(paint2); ! assertFalse(t0.impl_startable(false)); ! assertFalse(t0.impl_startable(true)); shape.setFill(Color.BLACK); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); t0.setFromValue(Color.WHITE); shape.setFill(paint2); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); // toValue t0.setToValue(null); ! assertFalse(t0.impl_startable(false)); ! assertFalse(t0.impl_startable(true)); t0.setToValue(Color.BLACK); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); } @Test public void testStartable_synchronized() { final FillTransition t0 = new FillTransition(Duration.ONE, shape, Color.WHITE, Color.BLACK); final Paint paint2 = new LinearGradient(0, 0, 1, 1, false, null, new Stop[] { new Stop(0, Color.RED) }); ! assertTrue(t0.impl_startable(true)); ! t0.impl_start(true); ! t0.impl_finished(); // shape is null t0.setShape(null); ! assertTrue(t0.impl_startable(false)); ! assertFalse(t0.impl_startable(true)); t0.setShape(shape); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); // fromValue t0.setFromValue(null); shape.setFill(paint2); ! assertTrue(t0.impl_startable(false)); ! assertFalse(t0.impl_startable(true)); shape.setFill(Color.BLACK); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); t0.setFromValue(Color.WHITE); shape.setFill(paint2); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); // toValue t0.setToValue(null); ! assertTrue(t0.impl_startable(false)); ! assertFalse(t0.impl_startable(true)); t0.setToValue(Color.BLACK); ! assertTrue(t0.impl_startable(false)); ! assertTrue(t0.impl_startable(true)); } @Test public void testEvaluateStartValue() { final FillTransition t0 = new FillTransition(Duration.INDEFINITE, shape, null, Color.WHITE); // first run shape.setFill(Color.GREY); ! assertTrue(t0.impl_startable(false)); ! t0.impl_start(false); shape.setFill(Color.TRANSPARENT); ! t0.interpolate(0.0); assertColorEquals(Color.GREY, shape.getFill()); ! t0.impl_finished(); // second run shape.setFill(Color.BLACK); ! assertTrue(t0.impl_startable(true)); ! t0.impl_start(true); shape.setFill(Color.WHITE); ! t0.interpolate(0.0); assertColorEquals(Color.BLACK, shape.getFill()); ! t0.impl_finished(); } } --- 176,361 ---- pt.setNode(shape2); shape.setFill(Color.WHITE); shape2.setFill(Color.WHITE); // node set, parent set ! assertTrue(AnimationShim.impl_startable(ft,false)); ! AnimationShim.impl_start(ft,false); ! TransitionShim.interpolate(ft,0.5); assertColorEquals(Color.color(0.5, 0.6, 0.7, 0.7), shape.getFill()); assertColorEquals(Color.WHITE, shape2.getFill()); ! AnimationShim.impl_finished(ft); // node null, parent set ft.setShape(null); ! assertTrue(AnimationShim.impl_startable(ft,true)); ! AnimationShim.impl_start(ft,true); ! TransitionShim.interpolate(ft,0.4); assertColorEquals(Color.color(0.5, 0.6, 0.7, 0.7), shape.getFill()); assertColorEquals(Color.color(0.4, 0.56, 0.72, 0.76), shape2.getFill()); ! AnimationShim.impl_finished(ft); // node null, parent not shape set pt.setNode(new Group()); ! assertFalse(AnimationShim.impl_startable(ft,true)); // node null, parent null pt.setNode(null); ! assertFalse(AnimationShim.impl_startable(ft,true)); } @Test public void testCachedValues() { final Color fromValue = Color.color(0.0, 0.4, 0.8, 0.2); final Color toValue = Color.color(1.0, 0.8, 0.6, 0.4); final FillTransition ft = new FillTransition(ONE_SEC, shape, fromValue, toValue); ft.setInterpolator(Interpolator.LINEAR); // start ! assertTrue(AnimationShim.impl_startable(ft,false)); ! AnimationShim.impl_start(ft,false); ft.setFromValue(Color.WHITE); ! TransitionShim.interpolate(ft,0.5); assertColorEquals(Color.color(0.5, 0.6, 0.7, 0.3), shape.getFill()); ! AnimationShim.impl_finished(ft); ft.setFromValue(fromValue); // end ! assertTrue(AnimationShim.impl_startable(ft,true)); ! AnimationShim.impl_start(ft,true); ft.setToValue(Color.BLACK); ! TransitionShim.interpolate(ft,0.2); assertColorEquals(Color.color(0.2, 0.48, 0.76, 0.24), shape.getFill()); ! AnimationShim.impl_finished(ft); ft.setToValue(toValue); // shape ! assertTrue(AnimationShim.impl_startable(ft,true)); ! AnimationShim.impl_start(ft,true); ft.setShape(null); ! TransitionShim.interpolate(ft,0.7); assertColorEquals(Color.color(0.7, 0.68, 0.66, 0.34), shape.getFill()); ! AnimationShim.impl_finished(ft); ft.setShape(shape); // interpolator ! assertTrue(AnimationShim.impl_startable(ft,true)); ! AnimationShim.impl_start(ft,true); ft.setInterpolator(null); ! TransitionShim.interpolate(ft,0.1); assertColorEquals(Color.color(0.1, 0.44, 0.78, 0.22), shape.getFill()); ! AnimationShim.impl_finished(ft); ft.setInterpolator(Interpolator.LINEAR); } @Test public void testStartable_unsynchronized() { final FillTransition t0 = new FillTransition(Duration.ONE, shape, Color.WHITE, Color.BLACK); final Paint paint2 = new LinearGradient(0, 0, 1, 1, false, null, new Stop[] { new Stop(0, Color.RED) }); ! assertTrue(AnimationShim.impl_startable(t0,true)); // duration is 0 t0.setDuration(Duration.ZERO); ! assertFalse(AnimationShim.impl_startable(t0,true)); t0.setDuration(Duration.ONE); ! assertTrue(AnimationShim.impl_startable(t0,true)); // interpolator is null t0.setInterpolator(null); ! assertFalse(AnimationShim.impl_startable(t0,true)); t0.setInterpolator(Interpolator.LINEAR); ! assertTrue(AnimationShim.impl_startable(t0,true)); // shape is null t0.setShape(null); ! assertFalse(AnimationShim.impl_startable(t0,false)); ! assertFalse(AnimationShim.impl_startable(t0,true)); t0.setShape(shape); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); // fromValue t0.setFromValue(null); shape.setFill(paint2); ! assertFalse(AnimationShim.impl_startable(t0,false)); ! assertFalse(AnimationShim.impl_startable(t0,true)); shape.setFill(Color.BLACK); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); t0.setFromValue(Color.WHITE); shape.setFill(paint2); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); // toValue t0.setToValue(null); ! assertFalse(AnimationShim.impl_startable(t0,false)); ! assertFalse(AnimationShim.impl_startable(t0,true)); t0.setToValue(Color.BLACK); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); } @Test public void testStartable_synchronized() { final FillTransition t0 = new FillTransition(Duration.ONE, shape, Color.WHITE, Color.BLACK); final Paint paint2 = new LinearGradient(0, 0, 1, 1, false, null, new Stop[] { new Stop(0, Color.RED) }); ! assertTrue(AnimationShim.impl_startable(t0,true)); ! AnimationShim.impl_start(t0,true); ! AnimationShim.impl_finished(t0); // shape is null t0.setShape(null); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertFalse(AnimationShim.impl_startable(t0,true)); t0.setShape(shape); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); // fromValue t0.setFromValue(null); shape.setFill(paint2); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertFalse(AnimationShim.impl_startable(t0,true)); shape.setFill(Color.BLACK); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); t0.setFromValue(Color.WHITE); shape.setFill(paint2); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); // toValue t0.setToValue(null); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertFalse(AnimationShim.impl_startable(t0,true)); t0.setToValue(Color.BLACK); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! assertTrue(AnimationShim.impl_startable(t0,true)); } @Test public void testEvaluateStartValue() { final FillTransition t0 = new FillTransition(Duration.INDEFINITE, shape, null, Color.WHITE); // first run shape.setFill(Color.GREY); ! assertTrue(AnimationShim.impl_startable(t0,false)); ! AnimationShim.impl_start(t0,false); shape.setFill(Color.TRANSPARENT); ! TransitionShim.interpolate(t0,0.0); assertColorEquals(Color.GREY, shape.getFill()); ! AnimationShim.impl_finished(t0); // second run shape.setFill(Color.BLACK); ! assertTrue(AnimationShim.impl_startable(t0,true)); ! AnimationShim.impl_start(t0,true); shape.setFill(Color.WHITE); ! TransitionShim.interpolate(t0,0.0); assertColorEquals(Color.BLACK, shape.getFill()); ! AnimationShim.impl_finished(t0); } }