modules/controls/src/test/java/javafx/scene/control/skin/ProgressIndicatorSkinTest.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   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.javafx.scene.control.skin;
  27 
  28 import static org.junit.Assert.assertEquals;


  29 import javafx.scene.control.ProgressIndicator;
  30 import javafx.scene.Group;
  31 import javafx.scene.paint.Color;
  32 import javafx.scene.Scene;
  33 import javafx.stage.Stage;
  34 
  35 import org.junit.Before;
  36 import org.junit.Test;
  37 
  38 /**
  39  */
  40 public class ProgressIndicatorSkinTest {
  41     private ProgressIndicator progressindicator;
  42     private ProgressIndicatorSkinMock skin;
  43 
  44     @Before public void setup() {
  45         progressindicator = new ProgressIndicator();
  46         skin = new ProgressIndicatorSkinMock(progressindicator);
  47         progressindicator.setSkin(skin);
  48     }


  50     @Test public void progressCSSTracksProgressColor() {
  51         progressindicator.setStyle("-fx-progress-color: green;");
  52 
  53         Scene scene = new Scene(new Group(), 400, 400);
  54         ((Group) scene.getRoot()).getChildren().clear();
  55         ((Group) scene.getRoot()).getChildren().add(progressindicator);
  56         Stage stage = new Stage();
  57         stage.setScene(scene);
  58         stage.show();
  59 
  60         assertEquals(Color.GREEN, skin.getProgressColor());
  61     }
  62     
  63     public static final class ProgressIndicatorSkinMock extends ProgressIndicatorSkin {
  64         boolean propertyChanged = false;
  65         int propertyChangeCount = 0;
  66         public ProgressIndicatorSkinMock(ProgressIndicator progressindicator) {
  67             super(progressindicator);
  68         }
  69         
  70         @Override protected void handleControlPropertyChanged(String p) {
  71             super.handleControlPropertyChanged(p);
  72             propertyChanged = true;
  73             propertyChangeCount++;

  74         }
  75     }
  76 }


   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.scene.control.skin;
  27 
  28 import static org.junit.Assert.assertEquals;
  29 
  30 import javafx.beans.value.ObservableValue;
  31 import javafx.scene.control.ProgressIndicator;
  32 import javafx.scene.Group;
  33 import javafx.scene.paint.Color;
  34 import javafx.scene.Scene;
  35 import javafx.stage.Stage;
  36 
  37 import org.junit.Before;
  38 import org.junit.Test;
  39 
  40 /**
  41  */
  42 public class ProgressIndicatorSkinTest {
  43     private ProgressIndicator progressindicator;
  44     private ProgressIndicatorSkinMock skin;
  45 
  46     @Before public void setup() {
  47         progressindicator = new ProgressIndicator();
  48         skin = new ProgressIndicatorSkinMock(progressindicator);
  49         progressindicator.setSkin(skin);
  50     }


  52     @Test public void progressCSSTracksProgressColor() {
  53         progressindicator.setStyle("-fx-progress-color: green;");
  54 
  55         Scene scene = new Scene(new Group(), 400, 400);
  56         ((Group) scene.getRoot()).getChildren().clear();
  57         ((Group) scene.getRoot()).getChildren().add(progressindicator);
  58         Stage stage = new Stage();
  59         stage.setScene(scene);
  60         stage.show();
  61 
  62         assertEquals(Color.GREEN, skin.getProgressColor());
  63     }
  64     
  65     public static final class ProgressIndicatorSkinMock extends ProgressIndicatorSkin {
  66         boolean propertyChanged = false;
  67         int propertyChangeCount = 0;
  68         public ProgressIndicatorSkinMock(ProgressIndicator progressindicator) {
  69             super(progressindicator);
  70         }
  71 
  72         public void addWatchedProperty(ObservableValue<?> p) {
  73             p.addListener(o -> {
  74                 propertyChanged = true;
  75                 propertyChangeCount++;
  76             });
  77         }
  78     }
  79 }