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 javafx.animation.AnimationShim;
  29 import javafx.animation.Interpolator;
  30 import javafx.animation.ParallelTransition;
  31 import javafx.animation.TransitionShim;
  32 import javafx.animation.TranslateTransition;
  33 import static org.junit.Assert.assertEquals;
  34 import static org.junit.Assert.assertFalse;
  35 import static org.junit.Assert.assertNull;
  36 import static org.junit.Assert.assertTrue;
  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 TranslateTransitionTest {
  45         
  46         private static Duration DEFAULT_DURATION = Duration.millis(400);
  47         private static Interpolator DEFAULT_INTERPOLATOR = Interpolator.EASE_BOTH;
  48         
  49         private static double EPSILON = 1e-12;
  50         private static Duration ONE_SEC = Duration.millis(1000);
  51         private static Duration TWO_SECS = Duration.millis(2000);
  52         
  53         private Node node;
  54         
  55         @Before
  56         public void setUp() {
  57                 node = new Rectangle();
  58         }
  59         
  60         @Test
  61         public void testDefaultValues() {
  62                 // empty ctor
  63                 final TranslateTransition t0 = new TranslateTransition();
  64                 assertEquals(DEFAULT_DURATION, t0.getDuration());
  65         assertEquals(DEFAULT_DURATION, t0.getCycleDuration());
  66                 assertTrue(Double.isNaN(t0.getFromX()));
  67                 assertTrue(Double.isNaN(t0.getFromY()));
  68                 assertTrue(Double.isNaN(t0.getFromZ()));
  69                 assertTrue(Double.isNaN(t0.getToX()));
  70                 assertTrue(Double.isNaN(t0.getToY()));
  71                 assertTrue(Double.isNaN(t0.getToZ()));
  72                 assertEquals(0.0, t0.getByX(), EPSILON);
  73                 assertEquals(0.0, t0.getByY(), EPSILON);
  74                 assertEquals(0.0, t0.getByZ(), EPSILON);
  75                 assertNull(t0.getNode());
  76                 assertEquals(DEFAULT_INTERPOLATOR, t0.getInterpolator());
  77                 assertNull(t0.getOnFinished());
  78                 
  79                 // duration only
  80                 final TranslateTransition t1 = new TranslateTransition(ONE_SEC);
  81                 assertEquals(ONE_SEC, t1.getDuration());
  82                 assertTrue(Double.isNaN(t1.getFromX()));
  83                 assertTrue(Double.isNaN(t1.getFromY()));
  84                 assertTrue(Double.isNaN(t1.getFromZ()));
  85                 assertTrue(Double.isNaN(t1.getToX()));
  86                 assertTrue(Double.isNaN(t1.getToY()));
  87                 assertTrue(Double.isNaN(t1.getToZ()));
  88                 assertEquals(0.0, t1.getByX(), EPSILON);
  89                 assertEquals(0.0, t1.getByY(), EPSILON);
  90                 assertEquals(0.0, t1.getByZ(), EPSILON);
  91                 assertNull(t1.getNode());
  92                 assertEquals(DEFAULT_INTERPOLATOR, t1.getInterpolator());
  93                 assertNull(t1.getOnFinished());
  94                 
  95                 // duration and node
  96                 final TranslateTransition t2 = new TranslateTransition(TWO_SECS, node);
  97                 assertEquals(TWO_SECS, t2.getDuration());
  98                 assertTrue(Double.isNaN(t2.getFromX()));
  99                 assertTrue(Double.isNaN(t2.getFromY()));
 100                 assertTrue(Double.isNaN(t2.getFromZ()));
 101                 assertTrue(Double.isNaN(t2.getToX()));
 102                 assertTrue(Double.isNaN(t2.getToY()));
 103                 assertTrue(Double.isNaN(t2.getToZ()));
 104                 assertEquals(0.0, t2.getByX(), EPSILON);
 105                 assertEquals(0.0, t2.getByY(), EPSILON);
 106                 assertEquals(0.0, t2.getByZ(), EPSILON);
 107                 assertEquals(node, t2.getNode());
 108                 assertEquals(DEFAULT_INTERPOLATOR, t2.getInterpolator());
 109                 assertNull(t2.getOnFinished());
 110         }
 111 
 112     @Test
 113     public void testDefaultValuesFromProperties() {
 114         // empty ctor
 115         final TranslateTransition t0 = new TranslateTransition();
 116         assertEquals(DEFAULT_DURATION, t0.durationProperty().get());
 117         assertTrue(Double.isNaN(t0.fromXProperty().get()));
 118         assertTrue(Double.isNaN(t0.fromYProperty().get()));
 119         assertTrue(Double.isNaN(t0.fromZProperty().get()));
 120         assertTrue(Double.isNaN(t0.toXProperty().get()));
 121         assertTrue(Double.isNaN(t0.toYProperty().get()));
 122         assertTrue(Double.isNaN(t0.toZProperty().get()));
 123         assertEquals(0.0, t0.byXProperty().get(), EPSILON);
 124         assertEquals(0.0, t0.byYProperty().get(), EPSILON);
 125         assertEquals(0.0, t0.byZProperty().get(), EPSILON);
 126         assertNull(t0.nodeProperty().get());
 127         assertEquals(DEFAULT_INTERPOLATOR, t0.interpolatorProperty().get());
 128         assertNull(t0.onFinishedProperty().get());
 129 
 130         // duration only
 131         final TranslateTransition t1 = new TranslateTransition(ONE_SEC);
 132         assertEquals(ONE_SEC, t1.durationProperty().get());
 133         assertTrue(Double.isNaN(t1.fromXProperty().get()));
 134         assertTrue(Double.isNaN(t1.fromYProperty().get()));
 135         assertTrue(Double.isNaN(t1.fromZProperty().get()));
 136         assertTrue(Double.isNaN(t1.toXProperty().get()));
 137         assertTrue(Double.isNaN(t1.toYProperty().get()));
 138         assertTrue(Double.isNaN(t1.toZProperty().get()));
 139         assertEquals(0.0, t1.byXProperty().get(), EPSILON);
 140         assertEquals(0.0, t1.byYProperty().get(), EPSILON);
 141         assertEquals(0.0, t1.byZProperty().get(), EPSILON);
 142         assertNull(t1.nodeProperty().get());
 143         assertEquals(DEFAULT_INTERPOLATOR, t1.interpolatorProperty().get());
 144         assertNull(t1.onFinishedProperty().get());
 145 
 146         // duration and node
 147         final TranslateTransition t2 = new TranslateTransition(TWO_SECS, node);
 148         assertEquals(TWO_SECS, t2.durationProperty().get());
 149         assertTrue(Double.isNaN(t2.fromXProperty().get()));
 150         assertTrue(Double.isNaN(t2.fromYProperty().get()));
 151         assertTrue(Double.isNaN(t2.fromZProperty().get()));
 152         assertTrue(Double.isNaN(t2.toXProperty().get()));
 153         assertTrue(Double.isNaN(t2.toYProperty().get()));
 154         assertTrue(Double.isNaN(t2.toZProperty().get()));
 155         assertEquals(0.0, t2.byXProperty().get(), EPSILON);
 156         assertEquals(0.0, t2.byYProperty().get(), EPSILON);
 157         assertEquals(0.0, t2.byZProperty().get(), EPSILON);
 158         assertEquals(node, t2.nodeProperty().get());
 159         assertEquals(DEFAULT_INTERPOLATOR, t2.interpolatorProperty().get());
 160         assertNull(t2.onFinishedProperty().get());
 161     }
 162 
 163         @Test
 164         public void testInterpolate() {
 165                 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
 166                 t0.setFromX(0.5);
 167                 t0.setToX(1.0);
 168                 t0.setFromY(1.5);
 169                 t0.setToY(2.0);
 170                 t0.setFromZ(1.5);
 171                 t0.setToZ(0.5);
 172                 
 173                 assertTrue(AnimationShim.impl_startable(t0,true));
 174                 AnimationShim.impl_start(t0,true);
 175                 TransitionShim.interpolate(t0,0.0);
 176                 assertEquals(0.5, node.getTranslateX(), EPSILON);
 177                 assertEquals(1.5, node.getTranslateY(), EPSILON);
 178                 assertEquals(1.5, node.getTranslateZ(), EPSILON);
 179                 TransitionShim.interpolate(t0,0.4);
 180                 assertEquals(0.7, node.getTranslateX(), EPSILON);
 181                 assertEquals(1.7, node.getTranslateY(), EPSILON);
 182                 assertEquals(1.1, node.getTranslateZ(), EPSILON);
 183                 TransitionShim.interpolate(t0,1.0);
 184                 assertEquals(1.0, node.getTranslateX(), EPSILON);
 185                 assertEquals(2.0, node.getTranslateY(), EPSILON);
 186                 assertEquals(0.5, node.getTranslateZ(), EPSILON);
 187                 AnimationShim.impl_finished(t0);
 188         }
 189         
 190         @Test
 191         public void testXValueCombinations() {
 192                 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
 193                 final double originalValue = 0.6;
 194                 final double fromValue = 0.4;
 195                 final double toValue = 0.9;
 196                 final double byValue = -0.2;
 197 
 198                 // no value set
 199                 node.setTranslateX(originalValue);
 200                 t0.setFromX(Double.NaN);
 201                 t0.setToX(Double.NaN);
 202                 t0.setByX(0.0);
 203                 assertTrue(AnimationShim.impl_startable(t0,true));
 204                 AnimationShim.impl_start(t0,true);
 205                 TransitionShim.interpolate(t0,0.0);
 206                 assertEquals(originalValue, node.getTranslateX(), EPSILON);
 207                 TransitionShim.interpolate(t0,1.0);
 208                 assertEquals(originalValue, node.getTranslateX(), EPSILON);
 209                 AnimationShim.impl_finished(t0);
 210 
 211                 // only from-value set
 212                 node.setTranslateX(originalValue);
 213                 t0.setFromX(fromValue);
 214                 t0.setToX(Double.NaN);
 215                 t0.setByX(0.0);
 216                 assertTrue(AnimationShim.impl_startable(t0,true));
 217                 AnimationShim.impl_start(t0,true);
 218                 TransitionShim.interpolate(t0,0.0);
 219                 assertEquals(fromValue, node.getTranslateX(), EPSILON);
 220                 TransitionShim.interpolate(t0,1.0);
 221                 assertEquals(fromValue, node.getTranslateX(), EPSILON);
 222                 AnimationShim.impl_finished(t0);
 223 
 224                 // only to-value set
 225                 node.setTranslateX(originalValue);
 226                 t0.setFromX(Double.NaN);
 227                 t0.setToX(toValue);
 228                 t0.setByX(0.0);
 229                 assertTrue(AnimationShim.impl_startable(t0,true));
 230                 AnimationShim.impl_start(t0,true);
 231                 TransitionShim.interpolate(t0,0.0);
 232                 assertEquals(originalValue, node.getTranslateX(), EPSILON);
 233                 TransitionShim.interpolate(t0,1.0);
 234                 assertEquals(toValue, node.getTranslateX(), EPSILON);
 235                 AnimationShim.impl_finished(t0);
 236 
 237                 // only by-value set
 238                 node.setTranslateX(originalValue);
 239                 t0.setFromX(Double.NaN);
 240                 t0.setToX(Double.NaN);
 241                 t0.setByX(byValue);
 242                 assertTrue(AnimationShim.impl_startable(t0,true));
 243                 AnimationShim.impl_start(t0,true);
 244                 TransitionShim.interpolate(t0,0.0);
 245                 assertEquals(originalValue, node.getTranslateX(), EPSILON);
 246                 TransitionShim.interpolate(t0,1.0);
 247                 assertEquals(originalValue + byValue, node.getTranslateX(), EPSILON);
 248                 AnimationShim.impl_finished(t0);
 249 
 250                 // from- and to-values set
 251                 node.setTranslateX(originalValue);
 252                 t0.setFromX(fromValue);
 253                 t0.setToX(toValue);
 254                 t0.setByX(0.0);
 255                 assertTrue(AnimationShim.impl_startable(t0,true));
 256                 AnimationShim.impl_start(t0,true);
 257                 TransitionShim.interpolate(t0,0.0);
 258                 assertEquals(fromValue, node.getTranslateX(), EPSILON);
 259                 TransitionShim.interpolate(t0,1.0);
 260                 assertEquals(toValue, node.getTranslateX(), EPSILON);
 261                 AnimationShim.impl_finished(t0);
 262 
 263                 // from- and by-values set
 264                 node.setTranslateX(originalValue);
 265                 t0.setFromX(fromValue);
 266                 t0.setToX(Double.NaN);
 267                 t0.setByX(byValue);
 268                 assertTrue(AnimationShim.impl_startable(t0,true));
 269                 AnimationShim.impl_start(t0,true);
 270                 TransitionShim.interpolate(t0,0.0);
 271                 assertEquals(fromValue, node.getTranslateX(), EPSILON);
 272                 TransitionShim.interpolate(t0,1.0);
 273                 assertEquals(fromValue + byValue, node.getTranslateX(), EPSILON);
 274                 AnimationShim.impl_finished(t0);
 275 
 276                 // to- and by-values set
 277                 node.setTranslateX(originalValue);
 278                 t0.setFromX(Double.NaN);
 279                 t0.setToX(toValue);
 280                 t0.setByX(byValue);
 281                 assertTrue(AnimationShim.impl_startable(t0,true));
 282                 AnimationShim.impl_start(t0,true);
 283                 TransitionShim.interpolate(t0,0.0);
 284                 assertEquals(originalValue, node.getTranslateX(), EPSILON);
 285                 TransitionShim.interpolate(t0,1.0);
 286                 assertEquals(toValue, node.getTranslateX(), EPSILON);
 287                 AnimationShim.impl_finished(t0);
 288 
 289                 // all values set
 290                 node.setTranslateX(originalValue);
 291                 t0.setFromX(fromValue);
 292                 t0.setToX(toValue);
 293                 t0.setByX(byValue);
 294                 assertTrue(AnimationShim.impl_startable(t0,true));
 295                 AnimationShim.impl_start(t0,true);
 296                 TransitionShim.interpolate(t0,0.0);
 297                 assertEquals(fromValue, node.getTranslateX(), EPSILON);
 298                 TransitionShim.interpolate(t0,1.0);
 299                 assertEquals(toValue, node.getTranslateX(), EPSILON);
 300                 AnimationShim.impl_finished(t0);
 301         }
 302 
 303         @Test
 304         public void testYValueCombinations() {
 305                 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
 306                 final double originalValue = 0.6;
 307                 final double fromValue = 0.4;
 308                 final double toValue = 0.9;
 309                 final double byValue = -0.2;
 310 
 311                 // no value set
 312                 node.setTranslateY(originalValue);
 313                 t0.setFromY(Double.NaN);
 314                 t0.setToY(Double.NaN);
 315                 t0.setByY(0.0);
 316                 assertTrue(AnimationShim.impl_startable(t0,true));
 317                 AnimationShim.impl_start(t0,true);
 318                 TransitionShim.interpolate(t0,0.0);
 319                 assertEquals(originalValue, node.getTranslateY(), EPSILON);
 320                 TransitionShim.interpolate(t0,1.0);
 321                 assertEquals(originalValue, node.getTranslateY(), EPSILON);
 322                 AnimationShim.impl_finished(t0);
 323 
 324                 // only from-value set
 325                 node.setTranslateY(originalValue);
 326                 t0.setFromY(fromValue);
 327                 t0.setToY(Double.NaN);
 328                 t0.setByY(0.0);
 329                 assertTrue(AnimationShim.impl_startable(t0,true));
 330                 AnimationShim.impl_start(t0,true);
 331                 TransitionShim.interpolate(t0,0.0);
 332                 assertEquals(fromValue, node.getTranslateY(), EPSILON);
 333                 TransitionShim.interpolate(t0,1.0);
 334                 assertEquals(fromValue, node.getTranslateY(), EPSILON);
 335                 AnimationShim.impl_finished(t0);
 336 
 337                 // only to-value set
 338                 node.setTranslateY(originalValue);
 339                 t0.setFromY(Double.NaN);
 340                 t0.setToY(toValue);
 341                 t0.setByY(0.0);
 342                 assertTrue(AnimationShim.impl_startable(t0,true));
 343                 AnimationShim.impl_start(t0,true);
 344                 TransitionShim.interpolate(t0,0.0);
 345                 assertEquals(originalValue, node.getTranslateY(), EPSILON);
 346                 TransitionShim.interpolate(t0,1.0);
 347                 assertEquals(toValue, node.getTranslateY(), EPSILON);
 348                 AnimationShim.impl_finished(t0);
 349 
 350                 // only by-value set
 351                 node.setTranslateY(originalValue);
 352                 t0.setFromY(Double.NaN);
 353                 t0.setToY(Double.NaN);
 354                 t0.setByY(byValue);
 355                 assertTrue(AnimationShim.impl_startable(t0,true));
 356                 AnimationShim.impl_start(t0,true);
 357                 TransitionShim.interpolate(t0,0.0);
 358                 assertEquals(originalValue, node.getTranslateY(), EPSILON);
 359                 TransitionShim.interpolate(t0,1.0);
 360                 assertEquals(originalValue + byValue, node.getTranslateY(), EPSILON);
 361                 AnimationShim.impl_finished(t0);
 362 
 363                 // from- and to-values set
 364                 node.setTranslateY(originalValue);
 365                 t0.setFromY(fromValue);
 366                 t0.setToY(toValue);
 367                 t0.setByY(0.0);
 368                 assertTrue(AnimationShim.impl_startable(t0,true));
 369                 AnimationShim.impl_start(t0,true);
 370                 TransitionShim.interpolate(t0,0.0);
 371                 assertEquals(fromValue, node.getTranslateY(), EPSILON);
 372                 TransitionShim.interpolate(t0,1.0);
 373                 assertEquals(toValue, node.getTranslateY(), EPSILON);
 374                 AnimationShim.impl_finished(t0);
 375 
 376                 // from- and by-values set
 377                 node.setTranslateY(originalValue);
 378                 t0.setFromY(fromValue);
 379                 t0.setToY(Double.NaN);
 380                 t0.setByY(byValue);
 381                 assertTrue(AnimationShim.impl_startable(t0,true));
 382                 AnimationShim.impl_start(t0,true);
 383                 TransitionShim.interpolate(t0,0.0);
 384                 assertEquals(fromValue, node.getTranslateY(), EPSILON);
 385                 TransitionShim.interpolate(t0,1.0);
 386                 assertEquals(fromValue + byValue, node.getTranslateY(), EPSILON);
 387                 AnimationShim.impl_finished(t0);
 388 
 389                 // to- and by-values set
 390                 node.setTranslateY(originalValue);
 391                 t0.setFromY(Double.NaN);
 392                 t0.setToY(toValue);
 393                 t0.setByY(byValue);
 394                 assertTrue(AnimationShim.impl_startable(t0,true));
 395                 AnimationShim.impl_start(t0,true);
 396                 TransitionShim.interpolate(t0,0.0);
 397                 assertEquals(originalValue, node.getTranslateY(), EPSILON);
 398                 TransitionShim.interpolate(t0,1.0);
 399                 assertEquals(toValue, node.getTranslateY(), EPSILON);
 400                 AnimationShim.impl_finished(t0);
 401 
 402                 // all values set
 403                 node.setTranslateY(originalValue);
 404                 t0.setFromY(fromValue);
 405                 t0.setToY(toValue);
 406                 t0.setByY(byValue);
 407                 assertTrue(AnimationShim.impl_startable(t0,true));
 408                 AnimationShim.impl_start(t0,true);
 409                 TransitionShim.interpolate(t0,0.0);
 410                 assertEquals(fromValue, node.getTranslateY(), EPSILON);
 411                 TransitionShim.interpolate(t0,1.0);
 412                 assertEquals(toValue, node.getTranslateY(), EPSILON);
 413                 AnimationShim.impl_finished(t0);
 414         }
 415 
 416         @Test
 417         public void testZValueCombinations() {
 418                 final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
 419                 final double originalValue = 0.6;
 420                 final double fromValue = 0.4;
 421                 final double toValue = 0.9;
 422                 final double byValue = -0.2;
 423 
 424                 // no value set
 425                 node.setTranslateZ(originalValue);
 426                 t0.setFromZ(Double.NaN);
 427                 t0.setToZ(Double.NaN);
 428                 t0.setByZ(0.0);
 429                 assertTrue(AnimationShim.impl_startable(t0,true));
 430                 AnimationShim.impl_start(t0,true);
 431                 TransitionShim.interpolate(t0,0.0);
 432                 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
 433                 TransitionShim.interpolate(t0,1.0);
 434                 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
 435                 AnimationShim.impl_finished(t0);
 436 
 437                 // only from-value set
 438                 node.setTranslateZ(originalValue);
 439                 t0.setFromZ(fromValue);
 440                 t0.setToZ(Double.NaN);
 441                 t0.setByZ(0.0);
 442                 assertTrue(AnimationShim.impl_startable(t0,true));
 443                 AnimationShim.impl_start(t0,true);
 444                 TransitionShim.interpolate(t0,0.0);
 445                 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
 446                 TransitionShim.interpolate(t0,1.0);
 447                 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
 448                 AnimationShim.impl_finished(t0);
 449 
 450                 // only to-value set
 451                 node.setTranslateZ(originalValue);
 452                 t0.setFromZ(Double.NaN);
 453                 t0.setToZ(toValue);
 454                 t0.setByZ(0.0);
 455                 assertTrue(AnimationShim.impl_startable(t0,true));
 456                 AnimationShim.impl_start(t0,true);
 457                 TransitionShim.interpolate(t0,0.0);
 458                 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
 459                 TransitionShim.interpolate(t0,1.0);
 460                 assertEquals(toValue, node.getTranslateZ(), EPSILON);
 461                 AnimationShim.impl_finished(t0);
 462 
 463                 // only by-value set
 464                 node.setTranslateZ(originalValue);
 465                 t0.setFromZ(Double.NaN);
 466                 t0.setToZ(Double.NaN);
 467                 t0.setByZ(byValue);
 468                 assertTrue(AnimationShim.impl_startable(t0,true));
 469                 AnimationShim.impl_start(t0,true);
 470                 TransitionShim.interpolate(t0,0.0);
 471                 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
 472                 TransitionShim.interpolate(t0,1.0);
 473                 assertEquals(originalValue + byValue, node.getTranslateZ(), EPSILON);
 474                 AnimationShim.impl_finished(t0);
 475 
 476                 // from- and to-values set
 477                 node.setTranslateZ(originalValue);
 478                 t0.setFromZ(fromValue);
 479                 t0.setToZ(toValue);
 480                 t0.setByZ(0.0);
 481                 assertTrue(AnimationShim.impl_startable(t0,true));
 482                 AnimationShim.impl_start(t0,true);
 483                 TransitionShim.interpolate(t0,0.0);
 484                 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
 485                 TransitionShim.interpolate(t0,1.0);
 486                 assertEquals(toValue, node.getTranslateZ(), EPSILON);
 487                 AnimationShim.impl_finished(t0);
 488 
 489                 // from- and by-values set
 490                 node.setTranslateZ(originalValue);
 491                 t0.setFromZ(fromValue);
 492                 t0.setToZ(Double.NaN);
 493                 t0.setByZ(byValue);
 494                 assertTrue(AnimationShim.impl_startable(t0,true));
 495                 AnimationShim.impl_start(t0,true);
 496                 TransitionShim.interpolate(t0,0.0);
 497                 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
 498                 TransitionShim.interpolate(t0,1.0);
 499                 assertEquals(fromValue + byValue, node.getTranslateZ(), EPSILON);
 500                 AnimationShim.impl_finished(t0);
 501 
 502                 // to- and by-values set
 503                 node.setTranslateZ(originalValue);
 504                 t0.setFromZ(Double.NaN);
 505                 t0.setToZ(toValue);
 506                 t0.setByZ(byValue);
 507                 assertTrue(AnimationShim.impl_startable(t0,true));
 508                 AnimationShim.impl_start(t0,true);
 509                 TransitionShim.interpolate(t0,0.0);
 510                 assertEquals(originalValue, node.getTranslateZ(), EPSILON);
 511                 TransitionShim.interpolate(t0,1.0);
 512                 assertEquals(toValue, node.getTranslateZ(), EPSILON);
 513                 AnimationShim.impl_finished(t0);
 514 
 515                 // all values set
 516                 node.setTranslateZ(originalValue);
 517                 t0.setFromZ(fromValue);
 518                 t0.setToZ(toValue);
 519                 t0.setByZ(byValue);
 520                 assertTrue(AnimationShim.impl_startable(t0,true));
 521                 AnimationShim.impl_start(t0,true);
 522                 TransitionShim.interpolate(t0,0.0);
 523                 assertEquals(fromValue, node.getTranslateZ(), EPSILON);
 524                 TransitionShim.interpolate(t0,1.0);
 525                 assertEquals(toValue, node.getTranslateZ(), EPSILON);
 526                 AnimationShim.impl_finished(t0);
 527         }
 528 
 529     @Test
 530     public void testGetTargetNode() {
 531         final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
 532         t0.setInterpolator(Interpolator.LINEAR);
 533                 t0.setFromX(0.5);
 534                 t0.setToX(1.0);
 535         final Rectangle node2 = new Rectangle();
 536         final ParallelTransition pt = new ParallelTransition();
 537         pt.getChildren().add(t0);
 538         pt.setNode(node2);
 539 
 540         // node set, parent set
 541         assertTrue(AnimationShim.impl_startable(t0,true));
 542         AnimationShim.impl_start(t0,true);
 543         TransitionShim.interpolate(t0,0.5);
 544         assertEquals(0.75, node.getTranslateX(), EPSILON);
 545         assertEquals(0.0, node2.getTranslateX(), EPSILON);
 546         AnimationShim.impl_finished(t0);
 547 
 548         // node null, parent set
 549         t0.setNode(null);
 550         assertTrue(AnimationShim.impl_startable(t0,true));
 551         AnimationShim.impl_start(t0,true);
 552         TransitionShim.interpolate(t0,0.4);
 553         assertEquals(0.75, node.getTranslateX(), EPSILON);
 554         assertEquals(0.7, node2.getTranslateX(), EPSILON);
 555         AnimationShim.impl_finished(t0);
 556 
 557         // node null, parent null
 558         pt.setNode(null);
 559         assertFalse(AnimationShim.impl_startable(t0,true));
 560     }
 561 
 562     @Test
 563     public void testCachedValues() {
 564         final TranslateTransition t0 = new TranslateTransition(ONE_SEC, node);
 565         t0.setInterpolator(Interpolator.LINEAR);
 566                 t0.setFromX(0.5);
 567                 t0.setToX(1.0);
 568                 t0.setFromY(1.5);
 569                 t0.setToY(2.0);
 570                 t0.setFromZ(1.5);
 571                 t0.setToZ(0.5);
 572 
 573         // start
 574         assertTrue(AnimationShim.impl_startable(t0,true));
 575         AnimationShim.impl_start(t0,true);
 576         t0.setFromX(0.0);
 577         t0.setFromY(-1.0);
 578         t0.setFromZ(0.5);
 579         TransitionShim.interpolate(t0,0.5);
 580         assertEquals(0.75, node.getTranslateX(), EPSILON);
 581         assertEquals(1.75, node.getTranslateY(), EPSILON);
 582         assertEquals(1.0,  node.getTranslateZ(), EPSILON);
 583         AnimationShim.impl_finished(t0);
 584         t0.setFromX(0.5);
 585                 t0.setFromY(1.5);
 586                 t0.setFromZ(1.5);
 587 
 588         // end
 589         assertTrue(AnimationShim.impl_startable(t0,true));
 590         AnimationShim.impl_start(t0,true);
 591         t0.setToX(0.0);
 592         t0.setFromY(-1.0);
 593         t0.setFromZ(1.5);
 594         TransitionShim.interpolate(t0,0.2);
 595         assertEquals(0.6, node.getTranslateX(), EPSILON);
 596         assertEquals(1.6, node.getTranslateY(), EPSILON);
 597         assertEquals(1.3, node.getTranslateZ(), EPSILON);
 598         AnimationShim.impl_finished(t0);
 599         t0.setToX(1.0);
 600                 t0.setToY(2.0);
 601                 t0.setToZ(0.5);
 602 
 603         // node
 604         assertTrue(AnimationShim.impl_startable(t0,true));
 605         AnimationShim.impl_start(t0,true);
 606         t0.setNode(null);
 607         TransitionShim.interpolate(t0,0.7);
 608         assertEquals(0.85, node.getTranslateX(), EPSILON);
 609         AnimationShim.impl_finished(t0);
 610         t0.setNode(node);
 611 
 612         // interpolator
 613         assertTrue(AnimationShim.impl_startable(t0,true));
 614         AnimationShim.impl_start(t0,true);
 615         t0.setInterpolator(null);
 616         TransitionShim.interpolate(t0,0.1);
 617         assertEquals(0.55, node.getTranslateX(), EPSILON);
 618         AnimationShim.impl_finished(t0);
 619         t0.setInterpolator(Interpolator.LINEAR);
 620     }
 621 
 622         @Test
 623         public void testStartable() {
 624                 final TranslateTransition t0 = new TranslateTransition(Duration.ONE, node);
 625                 assertTrue(AnimationShim.impl_startable(t0,true));
 626                 
 627                 // duration is 0
 628                 t0.setDuration(Duration.ZERO);
 629                 assertFalse(AnimationShim.impl_startable(t0,true));
 630                 t0.setDuration(Duration.ONE);
 631                 assertTrue(AnimationShim.impl_startable(t0,true));
 632                 
 633                 // node is null
 634                 t0.setNode(null);
 635                 assertFalse(AnimationShim.impl_startable(t0,true));
 636                 t0.setNode(node);
 637                 assertTrue(AnimationShim.impl_startable(t0,true));
 638                 
 639                 // interpolator is null
 640                 t0.setInterpolator(null);
 641                 assertFalse(AnimationShim.impl_startable(t0,true));
 642                 t0.setInterpolator(Interpolator.LINEAR);
 643                 assertTrue(AnimationShim.impl_startable(t0,true));
 644         }
 645 
 646         @Test
 647         public void testEvaluateStartValue() {
 648                 final TranslateTransition t0 = new TranslateTransition(Duration.INDEFINITE, node);
 649         t0.setToX(2.0);
 650         t0.setToY(2.0);
 651         t0.setToZ(2.0);
 652                 
 653                 // first run
 654                 node.setTranslateX( 0.6);
 655                 node.setTranslateY( 1.6);
 656                 node.setTranslateZ(-0.6);
 657                 assertTrue(AnimationShim.impl_startable(t0,true));
 658                 AnimationShim.impl_start(t0,true);
 659                 node.setTranslateX(0.8);
 660                 node.setTranslateY(0.8);
 661                 node.setTranslateZ(0.8);
 662                 TransitionShim.interpolate(t0,0.0);
 663                 assertEquals( 0.6, node.getTranslateX(), EPSILON);
 664                 assertEquals( 1.6, node.getTranslateY(), EPSILON);
 665                 assertEquals(-0.6, node.getTranslateZ(), EPSILON);
 666                 AnimationShim.impl_finished(t0);
 667                 
 668                 // second run
 669                 node.setTranslateX( 0.2);
 670                 node.setTranslateY(-2.2);
 671                 node.setTranslateZ(11.2);
 672                 assertTrue(AnimationShim.impl_startable(t0,true));
 673                 AnimationShim.impl_start(t0,true);
 674                 node.setTranslateX(0.8);
 675                 node.setTranslateY(0.8);
 676                 node.setTranslateZ(0.8);
 677                 TransitionShim.interpolate(t0,0.0);
 678                 assertEquals( 0.2, node.getTranslateX(), EPSILON);
 679                 assertEquals(-2.2, node.getTranslateY(), EPSILON);
 680                 assertEquals(11.2, node.getTranslateZ(), EPSILON);
 681                 AnimationShim.impl_finished(t0);
 682         }
 683 
 684 }