1 /*
   2  * Copyright (c) 2011, 2013, 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 static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.assertNull;
  30 import static org.junit.Assert.assertTrue;
  31 
  32 import java.util.Arrays;
  33 import javafx.animation.Animation;
  34 import javafx.animation.Interpolator;
  35 import javafx.animation.SequentialTransition;
  36 
  37 import javafx.scene.Node;
  38 import javafx.scene.shape.Rectangle;
  39 import javafx.util.Duration;
  40 
  41 import org.junit.Before;
  42 import org.junit.Test;
  43 
  44 public class SequentialTransitionTest {
  45 
  46         private static Interpolator DEFAULT_INTERPOLATOR = Interpolator.LINEAR;
  47         
  48         private static Duration ONE_SEC = Duration.millis(1000);
  49         private static Duration TWO_SECS = Duration.millis(2000);
  50         private static Duration THREE_SECS = Duration.millis(3000);
  51         private static Duration SIX_SECS = Duration.millis(6000);
  52         
  53         private Node node;
  54         private Animation child1;
  55         private Animation child2;
  56         private Animation child3;
  57         
  58         @Before
  59         public void setUp() {
  60                 node = new Rectangle();
  61                 child1 = new AnimationDummy(ONE_SEC);
  62                 child2 = new AnimationDummy(TWO_SECS);
  63                 child3 = new AnimationDummy(THREE_SECS);
  64         }
  65         
  66         @Test
  67         public void testDefaultValues() {
  68                 // empty ctor
  69                 final SequentialTransition t0 = new SequentialTransition();
  70                 assertEquals(Duration.ZERO, t0.getTotalDuration());
  71                 assertNull(t0.getNode());
  72                 assertNull(t0.nodeProperty().get());
  73                 assertTrue(t0.getChildren().isEmpty());
  74                 assertEquals(DEFAULT_INTERPOLATOR, t0.getInterpolator());
  75                 assertNull(t0.getOnFinished());
  76                 
  77                 // node only
  78                 final SequentialTransition t1 = new SequentialTransition(node);
  79                 assertEquals(Duration.ZERO, t1.getTotalDuration());
  80                 assertEquals(node, t1.getNode());
  81                 assertEquals(node, t1.nodeProperty().get());
  82                 assertTrue(t1.getChildren().isEmpty());
  83                 assertEquals(DEFAULT_INTERPOLATOR, t1.getInterpolator());
  84                 assertNull(t1.getOnFinished());
  85                 
  86                 // child animations only
  87                 final SequentialTransition t2 = new SequentialTransition(child1, child2, child3);
  88                 assertEquals(SIX_SECS, t2.getTotalDuration());
  89                 assertNull(t2.getNode());
  90                 assertNull(t2.nodeProperty().get());
  91                 assertEquals(Arrays.asList(child1, child2, child3), t2.getChildren());
  92                 assertEquals(DEFAULT_INTERPOLATOR, t2.getInterpolator());
  93                 assertNull(t2.getOnFinished());
  94                 
  95                 // node and child animations
  96                 final SequentialTransition t3 = new SequentialTransition(node, child1, child2, child3);
  97                 assertEquals(SIX_SECS, t3.getTotalDuration());
  98                 assertEquals(node, t3.getNode());
  99                 assertEquals(node, t3.nodeProperty().get());
 100                 assertEquals(Arrays.asList(child1, child2, child3), t3.getChildren());
 101                 assertEquals(DEFAULT_INTERPOLATOR, t3.getInterpolator());
 102                 assertNull(t3.getOnFinished());
 103         }
 104 }