modules/graphics/src/test/java/test/javafx/scene/layout/ResizabilityTest.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 javafx.scene.layout;
  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.geometry.Insets;
  32 import javafx.scene.Group;
  33 import javafx.scene.Node;
  34 import javafx.scene.Parent;



  35 import javafx.scene.shape.Rectangle;
  36 import javafx.scene.text.Text;
  37 
  38 import org.junit.Test;
  39 import org.junit.Ignore;
  40 /**
  41  * Tests resizability apis of Node and key subclasses.
  42  *
  43  */
  44 public class ResizabilityTest {
  45 
  46     // test isResizable on key base classes
  47 
  48     @Test public void testNodeNotResizable() {
  49         Node node = new MockNode();
  50         assertFalse(node.isResizable());
  51     }
  52 
  53     @Test public void testShapeNotResizable() {
  54         Rectangle rect = new Rectangle();


 121         Parent parent = new MockParent();
 122         assertTrue(parent.prefHeight(-1) == parent.minHeight(-1) &&
 123                    parent.prefHeight(-1) == parent.maxHeight(-1));
 124     }
 125 
 126     // test that parent computes pref size based on chldren
 127 
 128     @Test public void testParentPrefWidthQueriesChildPrefWidth() {
 129         Parent parent = new MockParent();
 130         assertEquals(110, parent.prefWidth(-1), 1e-100);
 131     }
 132 
 133     @Test public void testParentPrefHeightQueriesChildPrefHeight() {
 134         Parent parent = new MockParent();
 135         assertEquals(220, parent.prefHeight(-1), 1e-100);
 136     }
 137 
 138     @Test public void testPanePrefWidthQueriesChildPrefWidth() {
 139         Pane container = new Pane();
 140         Rectangle r = new Rectangle(-10,-20,100,200);
 141         container.getChildren().add(r);
 142         MockResizable tr = new MockResizable(100,200);
 143         container.getChildren().add(tr);
 144         assertEquals(110, container.prefWidth(-1), 1e-100);
 145     }
 146 
 147     @Test public void testPanePrefHeightQueriesChildPrefHeight() {
 148         Pane container = new Pane();
 149         Rectangle r = new Rectangle(-10,-20,100,200);
 150         container.getChildren().add(r);
 151         MockResizable tr = new MockResizable(100,200);
 152         container.getChildren().add(tr);
 153         assertEquals(220, container.prefHeight(-1), 1e-100);
 154     }
 155 
 156     @Test public void testPanePrefWidthIncludesPadding() {
 157         Pane container = new Pane();
 158         container.setPadding(new Insets(10,20,30,40));
 159         Rectangle r = new Rectangle(-10,-20,100,200);
 160         container.getChildren().add(r);
 161         MockResizable tr = new MockResizable(100,200);
 162         container.getChildren().add(tr);
 163         assertEquals(170, container.prefWidth(-1), 1e-100);
 164     }
 165 
 166     @Test public void testPanePrefHeightIncludesPadding() {
 167         Pane container = new Pane();
 168         container.setPadding(new Insets(10,20,30,40));
 169         Rectangle r = new Rectangle(-10,-20,100,200);
 170         container.getChildren().add(r);
 171         MockResizable tr = new MockResizable(100,200);
 172         container.getChildren().add(tr);
 173         assertEquals(260, container.prefHeight(-1), 1e-100);
 174     }
 175 
 176     // test relocate, resize, resizeRelocate
 177 
 178     @Test public void testRelocateNonResizable() {
 179         Rectangle r = new Rectangle(10, 20, 100, 200);
 180         r.relocate(0,0);
 181 
 182         assertEquals(-10, r.getLayoutX(), 1e-100);
 183         assertEquals(-20, r.getLayoutY(), 1e-100);
 184     }
 185 
 186     @Test public void testRelocateResizable() {
 187         MockResizable resizable = new MockResizable(100,200);
 188         resizable.relocate(50,50);
 189 
 190         assertEquals(50, resizable.getLayoutX(), 1e-100);
 191         assertEquals(50, resizable.getLayoutY(), 1e-100);
 192     }




   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.scene.layout;
  27 
  28 import test.javafx.scene.layout.MockNode;
  29 import static org.junit.Assert.assertEquals;
  30 import static org.junit.Assert.assertFalse;
  31 import static org.junit.Assert.assertTrue;
  32 import javafx.geometry.Insets;
  33 import javafx.scene.Group;
  34 import javafx.scene.Node;
  35 import javafx.scene.Parent;
  36 import javafx.scene.ParentShim;
  37 import javafx.scene.layout.Pane;
  38 import javafx.scene.layout.Region;
  39 import javafx.scene.shape.Rectangle;
  40 import javafx.scene.text.Text;
  41 
  42 import org.junit.Test;
  43 import org.junit.Ignore;
  44 /**
  45  * Tests resizability apis of Node and key subclasses.
  46  *
  47  */
  48 public class ResizabilityTest {
  49 
  50     // test isResizable on key base classes
  51 
  52     @Test public void testNodeNotResizable() {
  53         Node node = new MockNode();
  54         assertFalse(node.isResizable());
  55     }
  56 
  57     @Test public void testShapeNotResizable() {
  58         Rectangle rect = new Rectangle();


 125         Parent parent = new MockParent();
 126         assertTrue(parent.prefHeight(-1) == parent.minHeight(-1) &&
 127                    parent.prefHeight(-1) == parent.maxHeight(-1));
 128     }
 129 
 130     // test that parent computes pref size based on chldren
 131 
 132     @Test public void testParentPrefWidthQueriesChildPrefWidth() {
 133         Parent parent = new MockParent();
 134         assertEquals(110, parent.prefWidth(-1), 1e-100);
 135     }
 136 
 137     @Test public void testParentPrefHeightQueriesChildPrefHeight() {
 138         Parent parent = new MockParent();
 139         assertEquals(220, parent.prefHeight(-1), 1e-100);
 140     }
 141 
 142     @Test public void testPanePrefWidthQueriesChildPrefWidth() {
 143         Pane container = new Pane();
 144         Rectangle r = new Rectangle(-10,-20,100,200);
 145         ParentShim.getChildren(container).add(r);
 146         MockResizable tr = new MockResizable(100,200);
 147         ParentShim.getChildren(container).add(tr);
 148         assertEquals(110, container.prefWidth(-1), 1e-100);
 149     }
 150 
 151     @Test public void testPanePrefHeightQueriesChildPrefHeight() {
 152         Pane container = new Pane();
 153         Rectangle r = new Rectangle(-10,-20,100,200);
 154         ParentShim.getChildren(container).add(r);
 155         MockResizable tr = new MockResizable(100,200);
 156         ParentShim.getChildren(container).add(tr);
 157         assertEquals(220, container.prefHeight(-1), 1e-100);
 158     }
 159 
 160     @Test public void testPanePrefWidthIncludesPadding() {
 161         Pane container = new Pane();
 162         container.setPadding(new Insets(10,20,30,40));
 163         Rectangle r = new Rectangle(-10,-20,100,200);
 164         ParentShim.getChildren(container).add(r);
 165         MockResizable tr = new MockResizable(100,200);
 166         ParentShim.getChildren(container).add(tr);
 167         assertEquals(170, container.prefWidth(-1), 1e-100);
 168     }
 169 
 170     @Test public void testPanePrefHeightIncludesPadding() {
 171         Pane container = new Pane();
 172         container.setPadding(new Insets(10,20,30,40));
 173         Rectangle r = new Rectangle(-10,-20,100,200);
 174         ParentShim.getChildren(container).add(r);
 175         MockResizable tr = new MockResizable(100,200);
 176         ParentShim.getChildren(container).add(tr);
 177         assertEquals(260, container.prefHeight(-1), 1e-100);
 178     }
 179 
 180     // test relocate, resize, resizeRelocate
 181 
 182     @Test public void testRelocateNonResizable() {
 183         Rectangle r = new Rectangle(10, 20, 100, 200);
 184         r.relocate(0,0);
 185 
 186         assertEquals(-10, r.getLayoutX(), 1e-100);
 187         assertEquals(-20, r.getLayoutY(), 1e-100);
 188     }
 189 
 190     @Test public void testRelocateResizable() {
 191         MockResizable resizable = new MockResizable(100,200);
 192         resizable.relocate(50,50);
 193 
 194         assertEquals(50, resizable.getLayoutX(), 1e-100);
 195         assertEquals(50, resizable.getLayoutY(), 1e-100);
 196     }