modules/graphics/src/test/java/test/javafx/scene/PaneTest.java

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


   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 package javafx.scene;
  26 
  27 import javafx.scene.layout.MockRegion;


  28 import javafx.scene.layout.Pane;
  29 import javafx.scene.shape.Rectangle;
  30 import static org.junit.Assert.assertEquals;
  31 import org.junit.Test;
  32 
  33 public class PaneTest {
  34     
  35 
  36     @Test
  37     public void testPrefWidthWithResizableChild() {
  38         Pane pane = new Pane();
  39 
  40         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
  41         pane.getChildren().add(region);
  42         pane.layout();
  43 
  44         assertEquals(100, pane.prefWidth(-1), 0);
  45     }
  46 
  47     @Test
  48     public void testPrefHeightWithResizableChild() {
  49         Pane pane = new Pane();
  50 
  51         javafx.scene.layout.MockRegion region = new javafx.scene.layout.MockRegion(100,150);
  52         pane.getChildren().add(region);
  53         pane.layout();
  54 
  55         assertEquals(150, pane.prefHeight(-1), 0);
  56     }
  57 
  58     @Test
  59     public void testMinAndPreferredSizes() {
  60         Pane pane = new Pane();
  61         Rectangle rect = new Rectangle(50,50);
  62         pane.getChildren().add(rect);
  63         
  64         rect.relocate(0, 0);
  65         
  66         pane.layout();
  67 
  68         //min size is always equal to insets
  69         assertEquals(0, pane.minWidth(-1), 1e-100);
  70         assertEquals(0, pane.minHeight(-1), 1e-100);
  71         assertEquals(50, pane.prefWidth(-1), 1e-100);
  72         assertEquals(50, pane.prefHeight(-1), 1e-100);
  73 
  74         rect.setWidth(100);
  75 
  76         assertEquals(0, pane.minWidth(-1), 1e-100);
  77         assertEquals(0, pane.minHeight(-1), 1e-100);
  78         assertEquals(100, pane.prefWidth(-1), 1e-100);
  79         assertEquals(50, pane.prefHeight(-1), 1e-100);
  80 
  81         rect.setHeight(200);
  82 
  83         assertEquals(0, pane.minWidth(-1), 1e-100);
  84         assertEquals(0, pane.minHeight(-1), 1e-100);
  85         assertEquals(100, pane.prefWidth(-1), 1e-100);
  86         assertEquals(200, pane.prefHeight(-1), 1e-100);
  87     }
  88     
  89     @Test
  90     public void testPrefSizeRespectsBounds() {
  91         Pane pane = new Pane();
  92         Node n1 = new MockRegion(100, 100, 10, 10, 1000, 1000);
  93         n1.relocate(10, 0);
  94         Node n2 = new MockRegion(0, 0, 200, 200, 100, 100);
  95         n2.relocate(0, 20);
  96         
  97         pane.getChildren().addAll(n1, n2);
  98         
  99         pane.layout();
 100         
 101         assertEquals(110, pane.prefWidth(-1), 1e-100);
 102         assertEquals(120, pane.prefHeight(-1), 1e-100);
 103     }
 104     
 105 }


   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 package test.javafx.scene;
  26 
  27 import javafx.scene.Node;
  28 import javafx.scene.ParentShim;
  29 import test.javafx.scene.layout.MockRegion;
  30 import javafx.scene.layout.Pane;
  31 import javafx.scene.shape.Rectangle;
  32 import static org.junit.Assert.assertEquals;
  33 import org.junit.Test;
  34 
  35 public class PaneTest {
  36     
  37 
  38     @Test
  39     public void testPrefWidthWithResizableChild() {
  40         Pane pane = new Pane();
  41 
  42         test.javafx.scene.layout.MockRegion region = new test.javafx.scene.layout.MockRegion(100,150);
  43         ParentShim.getChildren(pane).add(region);
  44         pane.layout();
  45 
  46         assertEquals(100, pane.prefWidth(-1), 0);
  47     }
  48 
  49     @Test
  50     public void testPrefHeightWithResizableChild() {
  51         Pane pane = new Pane();
  52 
  53         test.javafx.scene.layout.MockRegion region = new test.javafx.scene.layout.MockRegion(100,150);
  54         ParentShim.getChildren(pane).add(region);
  55         pane.layout();
  56 
  57         assertEquals(150, pane.prefHeight(-1), 0);
  58     }
  59 
  60     @Test
  61     public void testMinAndPreferredSizes() {
  62         Pane pane = new Pane();
  63         Rectangle rect = new Rectangle(50,50);
  64         ParentShim.getChildren(pane).add(rect);
  65         
  66         rect.relocate(0, 0);
  67         
  68         pane.layout();
  69 
  70         //min size is always equal to insets
  71         assertEquals(0, pane.minWidth(-1), 1e-100);
  72         assertEquals(0, pane.minHeight(-1), 1e-100);
  73         assertEquals(50, pane.prefWidth(-1), 1e-100);
  74         assertEquals(50, pane.prefHeight(-1), 1e-100);
  75 
  76         rect.setWidth(100);
  77 
  78         assertEquals(0, pane.minWidth(-1), 1e-100);
  79         assertEquals(0, pane.minHeight(-1), 1e-100);
  80         assertEquals(100, pane.prefWidth(-1), 1e-100);
  81         assertEquals(50, pane.prefHeight(-1), 1e-100);
  82 
  83         rect.setHeight(200);
  84 
  85         assertEquals(0, pane.minWidth(-1), 1e-100);
  86         assertEquals(0, pane.minHeight(-1), 1e-100);
  87         assertEquals(100, pane.prefWidth(-1), 1e-100);
  88         assertEquals(200, pane.prefHeight(-1), 1e-100);
  89     }
  90     
  91     @Test
  92     public void testPrefSizeRespectsBounds() {
  93         Pane pane = new Pane();
  94         Node n1 = new MockRegion(100, 100, 10, 10, 1000, 1000);
  95         n1.relocate(10, 0);
  96         Node n2 = new MockRegion(0, 0, 200, 200, 100, 100);
  97         n2.relocate(0, 20);
  98         
  99         ParentShim.getChildren(pane).addAll(n1, n2);
 100         
 101         pane.layout();
 102         
 103         assertEquals(110, pane.prefWidth(-1), 1e-100);
 104         assertEquals(120, pane.prefHeight(-1), 1e-100);
 105     }
 106     
 107 }