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

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


   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 com.sun.javafx.animation.TickCalculation;
  29 import javafx.animation.Animation.Status;






  30 import javafx.beans.property.LongProperty;
  31 import javafx.beans.property.SimpleLongProperty;
  32 import javafx.util.Duration;
  33 import org.junit.Before;
  34 import org.junit.Test;
  35 import static org.junit.Assert.*;
  36 
  37 public class SequentialTransitionPlayTest {
  38 
  39     public static final double TICK_MILLIS = TickCalculation.toMillis(100);
  40     public static final long TICK_STEP = Math.round(TICK_MILLIS);
  41 
  42     LongProperty xProperty = new SimpleLongProperty();
  43     LongProperty yProperty = new SimpleLongProperty();
  44     AbstractMasterTimerMock amt;
  45     SequentialTransition st;
  46     Transition child1X;
  47     Transition child1Y;
  48     Transition childByX;
  49     Transition childByX2;
  50 
  51     @Before
  52     public void setUp() {
  53         amt = new AbstractMasterTimerMock();
  54         st = new SequentialTransition(amt);
  55         child1X = new Transition() {
  56             {
  57                 setCycleDuration(Duration.minutes(1));
  58                 setInterpolator(Interpolator.LINEAR);
  59             }
  60 
  61             @Override
  62             protected void interpolate(double d) {
  63                 xProperty.set(Math.round(d * 60000));
  64             }
  65         };
  66         child1Y = new Transition() {
  67             {
  68                 setCycleDuration(Duration.seconds(10));
  69                 setInterpolator(Interpolator.LINEAR);
  70             }
  71 
  72             @Override
  73             protected void interpolate(double d) {
  74                 yProperty.set(Math.round(d * 10000));
  75             }
  76         };
  77         childByX = createByXChild();
  78         childByX2 = createByXChild();
  79     }
  80 
  81     private Transition createByXChild() {
  82         return new Transition() {
  83             {
  84                 setCycleDuration(Duration.seconds(1));
  85                 setInterpolator(Interpolator.LINEAR);
  86             }
  87 
  88             long lastX;
  89 
  90             @Override
  91             protected void interpolate(double frac) {
  92                 xProperty.set(Math.round(lastX + frac * 1000));
  93             }
  94 
  95             @Override
  96             void impl_sync(boolean forceSync) {
  97                 super.impl_sync(forceSync);
  98                 if (forceSync) {
  99                     lastX = xProperty.get();
 100                 }
 101             }
 102 
 103 
 104         };
 105     }
 106 
 107     @Test
 108     public void testSimplePlay() {
 109         st.getChildren().addAll(child1X, child1Y);
 110 
 111         st.play();
 112         assertEquals(Status.RUNNING, st.getStatus());
 113         assertEquals(Status.STOPPED, child1X.getStatus());
 114         assertEquals(Status.STOPPED, child1Y.getStatus());
 115 
 116         amt.pulse();




   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 com.sun.javafx.animation.TickCalculation;
  29 import javafx.animation.Animation.Status;
  30 import javafx.animation.AnimationShim;
  31 import javafx.animation.Interpolator;
  32 import javafx.animation.SequentialTransition;
  33 import javafx.animation.SequentialTransitionShim;
  34 import javafx.animation.Transition;
  35 import javafx.animation.TransitionShim;
  36 import javafx.beans.property.LongProperty;
  37 import javafx.beans.property.SimpleLongProperty;
  38 import javafx.util.Duration;
  39 import org.junit.Before;
  40 import org.junit.Test;
  41 import static org.junit.Assert.*;
  42 
  43 public class SequentialTransitionPlayTest {
  44 
  45     public static final double TICK_MILLIS = TickCalculation.toMillis(100);
  46     public static final long TICK_STEP = Math.round(TICK_MILLIS);
  47 
  48     LongProperty xProperty = new SimpleLongProperty();
  49     LongProperty yProperty = new SimpleLongProperty();
  50     AbstractMasterTimerMock amt;
  51     SequentialTransition st;
  52     Transition child1X;
  53     Transition child1Y;
  54     Transition childByX;
  55     Transition childByX2;
  56 
  57     @Before
  58     public void setUp() {
  59         amt = new AbstractMasterTimerMock();
  60         st = SequentialTransitionShim.getSequentialTransition(amt);
  61         child1X = new TransitionShim() {
  62             {
  63                 setCycleDuration(Duration.minutes(1));
  64                 setInterpolator(Interpolator.LINEAR);
  65             }
  66 
  67             @Override
  68             protected void interpolate(double d) {
  69                 xProperty.set(Math.round(d * 60000));
  70             }
  71         };
  72         child1Y = new TransitionShim() {
  73             {
  74                 setCycleDuration(Duration.seconds(10));
  75                 setInterpolator(Interpolator.LINEAR);
  76             }
  77 
  78             @Override
  79             protected void interpolate(double d) {
  80                 yProperty.set(Math.round(d * 10000));
  81             }
  82         };
  83         childByX = createByXChild();
  84         childByX2 = createByXChild();
  85     }
  86 
  87     private Transition createByXChild() {
  88         return new TransitionShim() {
  89             {
  90                 setCycleDuration(Duration.seconds(1));
  91                 setInterpolator(Interpolator.LINEAR);
  92             }
  93 
  94             long lastX;
  95 
  96             @Override
  97             protected void interpolate(double frac) {
  98                 xProperty.set(Math.round(lastX + frac * 1000));
  99             }
 100 
 101             @Override
 102             public void impl_sync(boolean forceSync) {
 103                 super.impl_sync(forceSync);
 104                 if (forceSync) {
 105                     lastX = xProperty.get();
 106                 }
 107             }
 108 
 109 
 110         };
 111     }
 112 
 113     @Test
 114     public void testSimplePlay() {
 115         st.getChildren().addAll(child1X, child1Y);
 116 
 117         st.play();
 118         assertEquals(Status.RUNNING, st.getStatus());
 119         assertEquals(Status.STOPPED, child1X.getStatus());
 120         assertEquals(Status.STOPPED, child1Y.getStatus());
 121 
 122         amt.pulse();