modules/graphics/src/test/java/test/com/sun/scenario/animation/shared/TimelineClipCoreTest.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 com.sun.scenario.animation.shared;
  27 

  28 import static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.assertFalse;
  30 import static org.junit.Assert.assertTrue;
  31 import javafx.animation.KeyFrame;
  32 import javafx.animation.KeyValue;
  33 import javafx.animation.Timeline;
  34 import javafx.animation.TimelineHelper;
  35 import javafx.beans.property.IntegerProperty;
  36 import javafx.beans.property.SimpleIntegerProperty;
  37 import javafx.event.ActionEvent;
  38 import javafx.event.EventHandler;
  39 import javafx.util.Duration;
  40 
  41 import org.junit.Before;
  42 import org.junit.Ignore;
  43 import org.junit.Test;
  44 
  45 import java.io.IOException;
  46 import java.io.OutputStream;
  47 import java.io.PrintStream;

  48 
  49 public class TimelineClipCoreTest {
  50     private Timeline timeline;
  51 
  52     private KeyFrame start;
  53     private KeyFrame middle;
  54     private KeyFrame end;
  55     private IntegerProperty target;
  56 
  57     private TimelineClipCore core;
  58 
  59     private boolean tmpBool;
  60 
  61     @Before
  62     public void setUp() {
  63         target = new SimpleIntegerProperty();
  64 
  65         start = new KeyFrame(Duration.ZERO, new KeyValue(target, 10));
  66         middle = new KeyFrame(new Duration(500));
  67         end = new KeyFrame(new Duration(1000), new KeyValue(target, 20));
  68 
  69         timeline = new Timeline();
  70         timeline.getKeyFrames().setAll(start, middle, end);
  71         timeline.setRate(1.0);
  72         timeline.setCycleCount(1);
  73         timeline.setAutoReverse(false);
  74         core = TimelineHelper.getClipCore(timeline);
  75     }
  76 
  77     @Test
  78     public void testPlayTo() {
  79         //forward
  80         timeline.play();
  81         timeline.pause();
  82         core.playTo(6 * 500);
  83         assertEquals(15, target.get());
  84 
  85         //to the end
  86         core.playTo(6 * 1000);
  87         assertEquals(20, target.get());
  88 
  89         //backwards
  90         core.playTo(6 * 200);
  91         assertEquals(12, target.get());
  92 
  93         //back to start
  94         core.playTo(0);




   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.com.sun.scenario.animation.shared;
  27 
  28 import com.sun.scenario.animation.shared.TimelineClipCore;
  29 import static org.junit.Assert.assertEquals;
  30 import static org.junit.Assert.assertFalse;
  31 import static org.junit.Assert.assertTrue;
  32 import javafx.animation.KeyFrame;
  33 import javafx.animation.KeyValue;
  34 import javafx.animation.Timeline;

  35 import javafx.beans.property.IntegerProperty;
  36 import javafx.beans.property.SimpleIntegerProperty;
  37 import javafx.event.ActionEvent;
  38 import javafx.event.EventHandler;
  39 import javafx.util.Duration;
  40 
  41 import org.junit.Before;
  42 import org.junit.Ignore;
  43 import org.junit.Test;
  44 
  45 import java.io.IOException;
  46 import java.io.OutputStream;
  47 import java.io.PrintStream;
  48 import javafx.animation.TimelineShim;
  49 
  50 public class TimelineClipCoreTest {
  51     private Timeline timeline;
  52 
  53     private KeyFrame start;
  54     private KeyFrame middle;
  55     private KeyFrame end;
  56     private IntegerProperty target;
  57 
  58     private TimelineClipCore core;
  59 
  60     private boolean tmpBool;
  61 
  62     @Before
  63     public void setUp() {
  64         target = new SimpleIntegerProperty();
  65 
  66         start = new KeyFrame(Duration.ZERO, new KeyValue(target, 10));
  67         middle = new KeyFrame(new Duration(500));
  68         end = new KeyFrame(new Duration(1000), new KeyValue(target, 20));
  69 
  70         timeline = new Timeline();
  71         timeline.getKeyFrames().setAll(start, middle, end);
  72         timeline.setRate(1.0);
  73         timeline.setCycleCount(1);
  74         timeline.setAutoReverse(false);
  75         core = TimelineShim.getClipCore(timeline);
  76     }
  77 
  78     @Test
  79     public void testPlayTo() {
  80         //forward
  81         timeline.play();
  82         timeline.pause();
  83         core.playTo(6 * 500);
  84         assertEquals(15, target.get());
  85 
  86         //to the end
  87         core.playTo(6 * 1000);
  88         assertEquals(20, target.get());
  89 
  90         //backwards
  91         core.playTo(6 * 200);
  92         assertEquals(12, target.get());
  93 
  94         //back to start
  95         core.playTo(0);