modules/graphics/src/test/java/test/javafx/scene/layout/HBoxTest.java
Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:
@@ -21,19 +21,24 @@
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-package javafx.scene.layout;
+package test.javafx.scene.layout;
+import test.javafx.scene.layout.MockBiased;
+import test.javafx.scene.layout.MockRegion;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Node;
+import javafx.scene.ParentShim;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
import javafx.scene.shape.Rectangle;
import org.junit.Before;
import org.junit.Test;
@@ -64,11 +69,11 @@
}
@Test public void testSimpleHBox() {
MockResizable child1 = new MockResizable(100,200, 300,400, 500,600);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
assertEquals(200, hbox.minWidth(-1), 1e-100);
assertEquals(200, hbox.minHeight(-1), 1e-100);
assertEquals(400, hbox.prefWidth(-1), 1e-100);
assertEquals(400, hbox.prefHeight(-1), 1e-100);
@@ -98,11 +103,11 @@
@Test public void testHBoxSpacing() {
hbox.setSpacing(10);
MockResizable child1 = new MockResizable(100,200, 300,400, 500,600);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
assertEquals(210, hbox.minWidth(-1), 1e-100);
assertEquals(200, hbox.minHeight(-1), 1e-100);
assertEquals(410, hbox.prefWidth(-1), 1e-100);
assertEquals(400, hbox.prefHeight(-1), 1e-100);
@@ -133,11 +138,11 @@
@Test public void testHBoxFillHeight() {
hbox.setFillHeight(false);
hbox.setAlignment(Pos.TOP_CENTER);
MockResizable child1 = new MockResizable(100,100, 200,300, 500,600);
MockResizable child2 = new MockResizable(100,100, 100, 400, 800, 800);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
assertEquals(200, hbox.minWidth(-1), 1e-100);
assertEquals(100, hbox.minHeight(-1), 1e-100);
assertEquals(300, hbox.prefWidth(-1), 1e-100);
assertEquals(400, hbox.prefHeight(-1), 1e-100);
@@ -166,11 +171,11 @@
}
@Test public void testHBoxAlignmentTopLeft() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.TOP_LEFT);
hbox.resize(500,500);
hbox.layout();
assertEquals(0, child1.getLayoutX(), 1e-100);
@@ -184,11 +189,11 @@
}
@Test public void testHBoxAlignmentTopCenter() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.TOP_CENTER);
hbox.resize(500,500);
hbox.layout();
assertEquals(50, child1.getLayoutX(), 1e-100);
@@ -202,11 +207,11 @@
}
@Test public void testHBoxAlignmentTopRight() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.TOP_RIGHT);
hbox.resize(500,500);
hbox.layout();
assertEquals(100, child1.getLayoutX(), 1e-100);
@@ -220,11 +225,11 @@
}
@Test public void testHBoxAlignmentCenterLeft() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.CENTER_LEFT);
hbox.resize(500,500);
hbox.layout();
assertEquals(0, child1.getLayoutX(), 1e-100);
@@ -238,11 +243,11 @@
}
@Test public void testHBoxAlignmentCenter() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.CENTER);
hbox.resize(500,500);
hbox.layout();
assertEquals(50, child1.getLayoutX(), 1e-100);
@@ -256,11 +261,11 @@
}
@Test public void testHBoxAlignmentCenterRight() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.CENTER_RIGHT);
hbox.resize(500,500);
hbox.layout();
assertEquals(100, child1.getLayoutX(), 1e-100);
@@ -274,11 +279,11 @@
}
@Test public void testHBoxAlignmentBottomLeft() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.BOTTOM_LEFT);
hbox.resize(500,500);
hbox.layout();
assertEquals(0, child1.getLayoutX(), 1e-100);
@@ -292,11 +297,11 @@
}
@Test public void testHBoxAlignmentBottomCenter() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.BOTTOM_CENTER);
hbox.resize(500,500);
hbox.layout();
assertEquals(50, child1.getLayoutX(), 1e-100);
@@ -310,11 +315,11 @@
}
@Test public void testHBoxAlignmentBottomRight() {
MockResizable child1 = new MockResizable(300,400);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setAlignment(Pos.BOTTOM_RIGHT);
hbox.resize(500,500);
hbox.layout();
assertEquals(100, child1.getLayoutX(), 1e-100);
@@ -328,11 +333,11 @@
}
@Test public void testHBoxAlignmentBaselineLeft() {
MockResizable child1 = new MockResizable(300,300); // baseline=290
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setFillHeight(false);
hbox.setAlignment(Pos.BASELINE_LEFT);
hbox.resize(500,500);
hbox.layout();
@@ -347,11 +352,11 @@
}
@Test public void testHBoxAlignmentBaselineCenter() {
MockResizable child1 = new MockResizable(300,300); // baseline=290
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setFillHeight(false);
hbox.setAlignment(Pos.BASELINE_CENTER);
hbox.resize(500,500);
hbox.layout();
@@ -366,11 +371,11 @@
}
@Test public void testHBoxAlignmentBaselineRight() {
MockResizable child1 = new MockResizable(300,300); // baseline=290
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setFillHeight(false);
hbox.setAlignment(Pos.BASELINE_RIGHT);
hbox.resize(500,500);
hbox.layout();
@@ -389,11 +394,11 @@
@Override public double getBaselineOffset() {
return BASELINE_OFFSET_SAME_AS_HEIGHT; // should be prefHeight
}
};
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setFillHeight(false);
hbox.setAlignment(Pos.BASELINE_LEFT);
hbox.resize(500,500);
hbox.layout();
@@ -412,11 +417,11 @@
@Override public double getBaselineOffset() {
return BASELINE_OFFSET_SAME_AS_HEIGHT; // should be prefHeight
}
};
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setFillHeight(false);
hbox.setAlignment(Pos.BASELINE_CENTER);
hbox.resize(500,500);
hbox.layout();
@@ -435,11 +440,11 @@
@Override public double getBaselineOffset() {
return BASELINE_OFFSET_SAME_AS_HEIGHT; // should be prefHeight
}
};
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
hbox.setFillHeight(false);
hbox.setAlignment(Pos.BASELINE_RIGHT);
hbox.resize(500,500);
hbox.layout();
@@ -457,11 +462,11 @@
/* Content Bias */
@Test public void testHBoxContentBiasNullNoChildHasContentBias() {
Rectangle r = new Rectangle(100,100);
MockResizable child = new MockResizable(200,100);
- hbox.getChildren().addAll(r, child);
+ ParentShim.getChildren(hbox).addAll(r, child);
assertNull(hbox.getContentBias());
assertEquals(300, hbox.prefWidth(-1), 0);
assertEquals(100, hbox.prefHeight(-1), 0);
assertEquals(300, hbox.prefWidth(200), 0);
@@ -469,21 +474,21 @@
@Test public void testHBoxContentBiasVERTICALIfChildVERTICAL() {
Rectangle r = new Rectangle(100,50);
MockBiased biased = new MockBiased(Orientation.VERTICAL, 200, 100);
MockResizable child = new MockResizable(100,100);
- hbox.getChildren().addAll(r, biased, child);
+ ParentShim.getChildren(hbox).addAll(r, biased, child);
assertEquals(Orientation.VERTICAL, hbox.getContentBias());
}
@Test public void testHBoxWithVerticalContentBiasAtPrefSize() {
Rectangle rect1 = new Rectangle(100,50);
MockBiased biased2 = new MockBiased(Orientation.VERTICAL, 200, 100);
MockResizable resizable3 = new MockResizable(100,100);
- hbox.getChildren().addAll(rect1, biased2, resizable3);
+ ParentShim.getChildren(hbox).addAll(rect1, biased2, resizable3);
assertEquals(100, hbox.prefHeight(-1), 0);
assertEquals(400, hbox.prefWidth(-1), 0);
hbox.autosize(); // 400 x 100
@@ -502,11 +507,11 @@
@Test public void testHBoxWithVerticalContentBiasWithVerticalShrinking() {
Rectangle rect1 = new Rectangle(100,50);
MockBiased biased2 = new MockBiased(Orientation.VERTICAL, 200, 100);
MockResizable resizable3 = new MockResizable(100,100);
- hbox.getChildren().addAll(rect1, biased2, resizable3);
+ ParentShim.getChildren(hbox).addAll(rect1, biased2, resizable3);
assertEquals(600, hbox.prefWidth(50), 0);
hbox.resize(600,50); // height smaller than pref
hbox.layout();
@@ -525,11 +530,11 @@
@Test public void testHBoxWithVerticalContentBiasWithVerticalGrowing() {
Rectangle rect1 = new Rectangle(100,50);
MockBiased biased2 = new MockBiased(Orientation.VERTICAL, 200, 100);
MockResizable resizable3 = new MockResizable(100,100);
- hbox.getChildren().addAll(rect1, biased2, resizable3);
+ ParentShim.getChildren(hbox).addAll(rect1, biased2, resizable3);
assertEquals(300, hbox.prefWidth(200), 0);
hbox.resize(300,200); // height larger than pref
hbox.layout();
@@ -547,20 +552,20 @@
@Test public void testHBoxContentBiasHORIZONTALIfChildHORIZONTAL() {
Rectangle r = new Rectangle(100,100);
MockBiased biased = new MockBiased(Orientation.HORIZONTAL, 200, 100);
MockResizable child = new MockResizable(100,100);
- hbox.getChildren().addAll(r, biased, child);
+ ParentShim.getChildren(hbox).addAll(r, biased, child);
assertEquals(Orientation.HORIZONTAL, hbox.getContentBias());
}
@Test public void testHBoxWithHorizontalContentBiasAtPrefSize() {
Rectangle rect1 = new Rectangle(100,50);
MockBiased biased2 = new MockBiased(Orientation.HORIZONTAL, 200, 100);
MockResizable resizable3 = new MockResizable(100,100);
- hbox.getChildren().addAll(rect1, biased2, resizable3);
+ ParentShim.getChildren(hbox).addAll(rect1, biased2, resizable3);
assertEquals(400, hbox.prefWidth(-1), 0);
assertEquals(100, hbox.prefHeight(-1), 0);
hbox.autosize(); // 400 x 100
@@ -579,11 +584,11 @@
@Test public void testHBoxWithHorizontalContentBiasWithHorizontalShrinking() {
Rectangle rect1 = new Rectangle(100,50);
MockBiased biased2 = new MockBiased(Orientation.HORIZONTAL, 200, 100);
MockResizable resizable3 = new MockResizable(100,100);
- hbox.getChildren().addAll(rect1, biased2, resizable3);
+ ParentShim.getChildren(hbox).addAll(rect1, biased2, resizable3);
assertEquals(134, hbox.prefHeight(300), 0);
hbox.resize(300,134); // width less than preferred
hbox.layout();
@@ -603,11 +608,11 @@
hbox.setFillHeight(false);
Rectangle rect1 = new Rectangle(100,50);
MockBiased biased2 = new MockBiased(Orientation.HORIZONTAL, 200, 100);
MockResizable resizable3 = new MockResizable(100,100);
- hbox.getChildren().addAll(rect1, biased2, resizable3);
+ ParentShim.getChildren(hbox).addAll(rect1, biased2, resizable3);
HBox.setHgrow(biased2, Priority.ALWAYS);
assertEquals(100, hbox.prefHeight(500), 0);
@@ -629,11 +634,11 @@
hbox.setFillHeight(true);
Rectangle rect1 = new Rectangle(100,50);
MockBiased biased2 = new MockBiased(Orientation.HORIZONTAL, 200, 100);
MockResizable resizable3 = new MockResizable(100,100);
- hbox.getChildren().addAll(rect1, biased2, resizable3);
+ ParentShim.getChildren(hbox).addAll(rect1, biased2, resizable3);
HBox.setHgrow(biased2, Priority.ALWAYS);
assertEquals(100, hbox.prefHeight(500), 0);
@@ -657,11 +662,11 @@
// @Test public void testHBoxContentBiasNullIfFillHeightFalse() {
// hbox.setFillHeight(false);
// Rectangle r = new Rectangle(100,100);
// MockBiased biased = new MockBiased(Orientation.VERTICAL, 200, 100);
// MockResizable child = new MockResizable(100,100);
-// hbox.getChildren().addAll(r, biased, child);
+// ParentShim.getChildren(hbox).addAll(r, biased, child);
//
// assertNull(hbox.getContentBias());
// assertEquals(100, hbox.prefHeight(-1), 0);
// assertEquals(400, hbox.prefWidth(-1), 0);
// assertEquals(400, hbox.prefWidth(200), 0);
@@ -670,11 +675,11 @@
// @Test public void testHBoxContentBiasNullIfChildHORIZONTALAndFillHeightTrue() {
// hbox.setFillHeight(true);
// Rectangle r = new Rectangle(100,100);
// MockBiased biased = new MockBiased(Orientation.HORIZONTAL, 100, 200);
// MockResizable child = new MockResizable(100,100);
-// hbox.getChildren().addAll(r, biased, child);
+// ParentShim.getChildren(hbox).addAll(r, biased, child);
//
// assertNull(hbox.getContentBias());
// assertEquals(300, hbox.prefWidth(-1), 0);
// assertEquals(200, hbox.prefHeight(-1), 0);
// assertEquals(200, hbox.prefHeight(200), 0);
@@ -683,11 +688,11 @@
// @Test public void testHBoxContentBiasNullIfChildHORIZONTALAndFillHeightFalse() {
// hbox.setFillHeight(false);
// Rectangle r = new Rectangle(100,100);
// MockBiased biased = new MockBiased(Orientation.HORIZONTAL, 100, 200);
// MockResizable child = new MockResizable(100,100);
-// hbox.getChildren().addAll(r, biased, child);
+// ParentShim.getChildren(hbox).addAll(r, biased, child);
//
// assertNull(hbox.getContentBias());
// assertEquals(300, hbox.prefWidth(-1), 0);
// assertEquals(200, hbox.prefHeight(-1), 0);
// assertEquals(200, hbox.prefHeight(200), 0);
@@ -708,11 +713,11 @@
@Test public void testHBoxMarginConstraint() {
HBox hbox = new HBox();
MockResizable child1 = new MockResizable(100,200, 300,400, 500,600);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
HBox.setMargin(child1, new Insets(10,20,30,40));
assertEquals(260, hbox.minWidth(-1), 1e-100);
assertEquals(240, hbox.minHeight(-1), 1e-100);
@@ -756,11 +761,11 @@
@Test public void testHBoxHgrowConstraint() {
HBox hbox = new HBox();
MockResizable child1 = new MockResizable(100,200, 300,400, 500,600);
Rectangle child2 = new Rectangle(100, 100);
- hbox.getChildren().addAll(child1, child2);
+ ParentShim.getChildren(hbox).addAll(child1, child2);
HBox.setHgrow(child1, Priority.ALWAYS);
assertEquals(200, hbox.minWidth(-1), 1e-100);
assertEquals(200, hbox.minHeight(-1), 1e-100);
@@ -798,11 +803,11 @@
biased.setId("test");
MockBiased biased2 = new MockBiased(Orientation.HORIZONTAL, 200, 200);
biased2.setId("test");
HBox.setHgrow(biased, Priority.ALWAYS);
- hbox.getChildren().addAll(biased, biased2);
+ ParentShim.getChildren(hbox).addAll(biased, biased2);
assertEquals(300, hbox.prefWidth(-1), 1e-100);
assertEquals(200, hbox.prefHeight(-1), 1e-100);
assertEquals(20, hbox.minWidth(-1), 1e-100); //MockBias minWidth == 10
assertEquals(1, hbox.minHeight(-1), 1e-100); // If both have max width, min height can be indeed 1
@@ -839,11 +844,11 @@
MockBiased biased = new MockBiased(Orientation.VERTICAL, 100,100);
MockBiased biased2 = new MockBiased(Orientation.VERTICAL, 200, 200);
HBox.setHgrow(biased, Priority.ALWAYS);
- hbox.getChildren().addAll(biased, biased2);
+ ParentShim.getChildren(hbox).addAll(biased, biased2);
assertEquals(300, hbox.prefWidth(-1), 1e-100);
assertEquals(200, hbox.prefHeight(-1), 1e-100);
hbox.autosize();
@@ -874,11 +879,11 @@
MockRegion child = new MockRegion(10,10,100,100,300,300);
MockRegion child2 = new MockRegion(10,10,100,100,200,200);
HBox.setHgrow(child, Priority.ALWAYS);
HBox.setHgrow(child2, Priority.ALWAYS);
- hbox.getChildren().addAll(child, child2);
+ ParentShim.getChildren(hbox).addAll(child, child2);
hbox.resize(600,600);
hbox.layout();
assertEquals(300, child.getWidth(), 0);
assertEquals(0, child.getLayoutX(), 0);
@@ -893,11 +898,11 @@
HBox.setMargin(child, new Insets(55, 0, 0, 0));
assertEquals(Node.BASELINE_OFFSET_SAME_AS_HEIGHT, hbox.getBaselineOffset(), 1e-100);
- hbox.getChildren().addAll(child, child2);
+ ParentShim.getChildren(hbox).addAll(child, child2);
assertEquals(145, hbox.getBaselineOffset(), 1e-100);
}
}