modules/graphics/src/test/java/test/javafx/scene/layout/BackgroundTest.java
Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:
@@ -21,15 +21,21 @@
* 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 javafx.geometry.Insets;
import javafx.geometry.Side;
import javafx.scene.image.Image;
+import javafx.scene.layout.Background;
+import javafx.scene.layout.BackgroundFill;
+import javafx.scene.layout.BackgroundImage;
+import javafx.scene.layout.BackgroundPosition;
+import javafx.scene.layout.BackgroundShim;
+import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import org.junit.Test;
import static javafx.scene.layout.BackgroundRepeat.*;
import static org.junit.Assert.*;
@@ -43,14 +49,14 @@
private static final BackgroundFill[] FILLS_2 = new BackgroundFill[] {
new BackgroundFill(Color.GREEN, new CornerRadii(3), new Insets(4)),
new BackgroundFill(Color.BLUE, new CornerRadii(6), new Insets(8)),
};
- private static final Image IMAGE_1 = new Image("javafx/scene/layout/red.png");
- private static final Image IMAGE_2 = new Image("javafx/scene/layout/blue.png");
- private static final Image IMAGE_3 = new Image("javafx/scene/layout/green.png");
- private static final Image IMAGE_4 = new Image("javafx/scene/layout/yellow.png");
+ private static final Image IMAGE_1 = new Image("test/javafx/scene/layout/red.png");
+ private static final Image IMAGE_2 = new Image("test/javafx/scene/layout/blue.png");
+ private static final Image IMAGE_3 = new Image("test/javafx/scene/layout/green.png");
+ private static final Image IMAGE_4 = new Image("test/javafx/scene/layout/yellow.png");
private static final BackgroundImage[] IMAGES_1 = new BackgroundImage[] {
new BackgroundImage(IMAGE_1, null, null, null, null)
};
@@ -345,33 +351,33 @@
*************************************************************************/
@Test public void opaqueInsets_nullFillsResultsInNaN() {
Background b = new Background((BackgroundFill[])null, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertTrue(Double.isNaN(trbl[0]));
assertTrue(Double.isNaN(trbl[1]));
assertTrue(Double.isNaN(trbl[2]));
assertTrue(Double.isNaN(trbl[3]));
}
@Test public void opaqueInsets_transparentFillsResultsInNaN() {
BackgroundFill f = new BackgroundFill(Color.TRANSPARENT, null, null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertTrue(Double.isNaN(trbl[0]));
assertTrue(Double.isNaN(trbl[1]));
assertTrue(Double.isNaN(trbl[2]));
assertTrue(Double.isNaN(trbl[3]));
}
@Test public void opaqueInsets_transparentFillsResultsInNaN2() {
BackgroundFill f = new BackgroundFill(Color.rgb(255, 0, 0, 0), null, null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertTrue(Double.isNaN(trbl[0]));
assertTrue(Double.isNaN(trbl[1]));
assertTrue(Double.isNaN(trbl[2]));
assertTrue(Double.isNaN(trbl[3]));
}
@@ -379,11 +385,11 @@
@Test public void opaqueInsets_transparentFillsResultsInNaN3() {
BackgroundFill f = new BackgroundFill(Color.TRANSPARENT, null, null);
BackgroundFill f2 = new BackgroundFill(Color.rgb(255, 0, 0, 0), null, null);
Background b = new Background(new BackgroundFill[] { f, f2 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertTrue(Double.isNaN(trbl[0]));
assertTrue(Double.isNaN(trbl[1]));
assertTrue(Double.isNaN(trbl[2]));
assertTrue(Double.isNaN(trbl[3]));
}
@@ -391,11 +397,11 @@
@Test public void opaqueInsets_transparentFillsMixedWithNonTransparentFills() {
BackgroundFill f = new BackgroundFill(Color.TRANSPARENT, null, null);
BackgroundFill f2 = new BackgroundFill(Color.RED, null, new Insets(1));
Background b = new Background(new BackgroundFill[] { f, f2 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(1, trbl[0], 0);
assertEquals(1, trbl[1], 0);
assertEquals(1, trbl[2], 0);
assertEquals(1, trbl[3], 0);
}
@@ -403,11 +409,11 @@
@Test public void opaqueInsets_transparentFillsMixedWithNonTransparentFills2() {
BackgroundFill f = new BackgroundFill(Color.TRANSPARENT, null, null);
BackgroundFill f2 = new BackgroundFill(Color.RED, null, new Insets(-1));
Background b = new Background(new BackgroundFill[] { f, f2 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(-1, trbl[0], 0);
assertEquals(-1, trbl[1], 0);
assertEquals(-1, trbl[2], 0);
assertEquals(-1, trbl[3], 0);
}
@@ -416,11 +422,11 @@
BackgroundFill f = new BackgroundFill(Color.RED, null, new Insets(0));
BackgroundFill f2 = new BackgroundFill(Color.GREEN, null, new Insets(1));
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(2));
Background b = new Background(new BackgroundFill[] { f, f2, f3 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(0, trbl[0], 0);
assertEquals(0, trbl[1], 0);
assertEquals(0, trbl[2], 0);
assertEquals(0, trbl[3], 0);
}
@@ -429,11 +435,11 @@
BackgroundFill f = new BackgroundFill(Color.RED, null, new Insets(-1));
BackgroundFill f2 = new BackgroundFill(Color.GREEN, null, new Insets(0));
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(1));
Background b = new Background(new BackgroundFill[] { f, f2, f3 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(-1, trbl[0], 0);
assertEquals(-1, trbl[1], 0);
assertEquals(-1, trbl[2], 0);
assertEquals(-1, trbl[3], 0);
}
@@ -442,11 +448,11 @@
BackgroundFill f = new BackgroundFill(Color.RED, null, new Insets(10));
BackgroundFill f2 = new BackgroundFill(Color.GREEN, null, new Insets(1));
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(2));
Background b = new Background(new BackgroundFill[] { f, f2, f3 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(1, trbl[0], 0);
assertEquals(1, trbl[1], 0);
assertEquals(1, trbl[2], 0);
assertEquals(1, trbl[3], 0);
}
@@ -455,11 +461,11 @@
BackgroundFill f = new BackgroundFill(Color.RED, null, new Insets(0));
BackgroundFill f2 = new BackgroundFill(Color.GREEN, null, new Insets(1));
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(-2));
Background b = new Background(new BackgroundFill[] { f, f2, f3 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(-2, trbl[0], 0);
assertEquals(-2, trbl[1], 0);
assertEquals(-2, trbl[2], 0);
assertEquals(-2, trbl[3], 0);
}
@@ -470,11 +476,11 @@
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(0, 1, 0, 0));
BackgroundFill f4 = new BackgroundFill(Color.YELLOW, null, new Insets(0, 0, 1, 0));
BackgroundFill f5 = new BackgroundFill(Color.CYAN, null, new Insets(0, 0, 0, 1));
Background b = new Background(new BackgroundFill[] { f, f2, f3, f4, f5 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(0, trbl[0], 0);
assertEquals(0, trbl[1], 0);
assertEquals(0, trbl[2], 0);
assertEquals(0, trbl[3], 0);
}
@@ -486,11 +492,11 @@
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(0, 1, 0, 0));
BackgroundFill f4 = new BackgroundFill(Color.RED, null, new Insets(0));
BackgroundFill f5 = new BackgroundFill(Color.CYAN, null, new Insets(0, 0, 0, 1));
Background b = new Background(new BackgroundFill[] { f, f2, f3, f4, f5 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(0, trbl[0], 0);
assertEquals(0, trbl[1], 0);
assertEquals(0, trbl[2], 0);
assertEquals(0, trbl[3], 0);
}
@@ -500,11 +506,11 @@
BackgroundFill f2 = new BackgroundFill(Color.GREEN, null, new Insets(0, 10, 0, 0));
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(0, 0, 10, 0));
BackgroundFill f4 = new BackgroundFill(Color.YELLOW, null, new Insets(0, 0, 0, 10));
Background b = new Background(new BackgroundFill[] { f, f2, f3, f4 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(0, trbl[0], 0);
assertEquals(0, trbl[1], 0);
assertEquals(0, trbl[2], 0);
assertEquals(0, trbl[3], 0);
}
@@ -514,11 +520,11 @@
BackgroundFill f2 = new BackgroundFill(Color.GREEN, null, new Insets(10, 10, 0, 0));
BackgroundFill f3 = new BackgroundFill(Color.BLUE, null, new Insets(10, 10, 10, 0));
BackgroundFill f4 = new BackgroundFill(Color.YELLOW, null, new Insets(10, 10, 10, 10));
Background b = new Background(new BackgroundFill[] { f, f2, f3, f4 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(10, trbl[0], 0);
assertEquals(0, trbl[1], 0);
assertEquals(0, trbl[2], 0);
assertEquals(0, trbl[3], 0);
}
@@ -530,11 +536,11 @@
@Test public void opaqueInsets_offsetOpaqueRectangles_LargestUsed() {
BackgroundFill f = new BackgroundFill(Color.RED, null, new Insets(10));
BackgroundFill f2 = new BackgroundFill(Color.GREEN, null, new Insets(20, 0, 0, 20));
Background b = new Background(new BackgroundFill[] { f, f2 }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(10, trbl[0], 0);
assertEquals(10, trbl[1], 0);
assertEquals(10, trbl[2], 0);
assertEquals(10, trbl[3], 0);
}
@@ -545,22 +551,22 @@
// implementation is all the same
@Test public void opaqueInsets_uniformCornerRadii() {
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(3), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(1.5, trbl[0], 0);
assertEquals(1.5, trbl[1], 0);
assertEquals(1.5, trbl[2], 0);
assertEquals(1.5, trbl[3], 0);
}
@Test public void opaqueInsets_nonUniformCornerRadii() {
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(1, 2, 3, 4, false), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(1, trbl[0], 0);
assertEquals(1.5, trbl[1], 0);
assertEquals(2, trbl[2], 0);
assertEquals(2, trbl[3], 0);
}
@@ -569,33 +575,33 @@
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(1, 2, 3, 4, 5, 6, 7, 8,
false, false, false, false,
false, false, false, false), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(1.5, trbl[0], 0);
assertEquals(2.5, trbl[1], 0);
assertEquals(3.5, trbl[2], 0);
assertEquals(4, trbl[3], 0);
}
@Test public void opaqueInsetsPercent_uniformCornerRadii() {
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(.1, true), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(2.5, trbl[0], 0);
assertEquals(5, trbl[1], 0);
assertEquals(2.5, trbl[2], 0);
assertEquals(5, trbl[3], 0);
}
@Test public void opaqueInsetsPercent_nonUniformCornerRadii() {
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(.1, .2, .3, .4, true), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(5, trbl[0], 0); // top-left-vertical is 2.5, but top-right-vertical is 5
assertEquals(15, trbl[1], 0); // top-right-horizontal is 5, but bottom-right-horizontal is 15
assertEquals(10, trbl[2], 0); // bottom-right-vertical is 7.5, but bottom-left-vertical is 10
assertEquals(20, trbl[3], 0); // bottom-left-horizontal dominates at 20
}
@@ -604,11 +610,11 @@
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(.1, .15, .2, .25, .3, .35, .4, .45,
true, true, true, true,
true, true, true, true), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(5, trbl[0], 0); // top-left-vertical is 3.75, but top-right-vertical is 5
assertEquals(15, trbl[1], 0); // top-right-horizontal is 12.5, but bottom-right-horizontal is 15
assertEquals(10, trbl[2], 0); // bottom-right-vertical is 8.75, but bottom-left-vertical is 10
assertEquals(22.5, trbl[3], 0); // bottom-left-horizontal dominates at 22.5
}
@@ -617,11 +623,11 @@
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(.1, 15, .2, 25, .3, 35, .4, 45,
true, false, true, false,
true, false, true, false), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(7.5, trbl[0], 0); // top-left-vertical is 7.5, and top-right-vertical is 5
assertEquals(15, trbl[1], 0); // top-right-horizontal is 12.5, but bottom-right-horizontal is 15
assertEquals(17.5, trbl[2], 0); // bottom-right-vertical is 17.5, and bottom-left-vertical is 10
assertEquals(22.5, trbl[3], 0); // bottom-left-horizontal dominates at 22.5
}
@@ -630,11 +636,11 @@
BackgroundFill f = new BackgroundFill(Color.RED, new CornerRadii(10, .15, 20, .25, 30, .35, 40, .45,
false, true, false, true,
false, true, false, true), null);
Background b = new Background(new BackgroundFill[] { f }, null);
final double[] trbl = new double[4];
- b.computeOpaqueInsets(100, 50, trbl);
+ BackgroundShim.computeOpaqueInsets(b, 100, 50, trbl);
assertEquals(10, trbl[0], 0); // top-left-vertical is 3.75, but top-right-vertical is 10
assertEquals(15, trbl[1], 0); // top-right-horizontal is 12.5, but bottom-right-horizontal is 15
assertEquals(20, trbl[2], 0); // bottom-right-vertical is 8.75, but bottom-left-vertical is 20
assertEquals(22.5, trbl[3], 0); // bottom-left-horizontal dominates at 22.5
}