@Before public void setup() { shape = new NGShape() { @Override public Shape getShape() { return new Ellipse2D(10, 10, 10, 10); } @Override protected boolean supportsOpaqueRegions() { return true; } @Override protected RectBounds computeOpaqueRegion(RectBounds opaqueRegion) { // For the sake of the tests in this class we actually don't care // what the opaque region is, so I just make something up opaqueRegion.setBounds(0, 0, 20, 20); return opaqueRegion; } }; shape.setDrawPaint(Color.WHITE); shape.setFillPaint(Color.BLACK); }
@Test public void hasOpaqueRegionReturnsFalseIfFillPaintIsNotOpaque() { shape.setFillPaint( new LinearGradient( 0, 0, 1, 1, BaseTransform.IDENTITY_TRANSFORM, true, 0, Arrays.asList(new Stop(Color.BLACK, 0), new Stop(Color.TRANSPARENT, 1)))); assertFalse(shape.hasOpaqueRegion()); }
@Test public void getOpaqueRegionChangesWhenFillChanged() { RectBounds or = shape.getOpaqueRegion(); assertNotNull(or); shape.setFillPaint(null); assertNull(shape.getOpaqueRegion()); shape.setFillPaint(Color.BLACK); assertNotNull(shape.getOpaqueRegion()); assertEquals(or, shape.getOpaqueRegion()); }
@Test public void hasOpaqueRegionReturnsFalseIfFillPaintIsNull() { shape.setFillPaint(null); assertFalse(shape.hasOpaqueRegion()); }
@Test public void hasOpaqueRegionReturnsFalseIfModeIsEmpty() { shape.setMode(NGShape.Mode.EMPTY); assertFalse(shape.hasOpaqueRegion()); }
@Test public void hasOpaqueRegionReturnsFalseIfModeIsStroke() { shape.setMode(NGShape.Mode.STROKE); assertFalse(shape.hasOpaqueRegion()); }
@Test public void getOpaqueRegionChangesWhenModeChanged() { RectBounds or = shape.getOpaqueRegion(); assertNotNull(or); shape.setMode(NGShape.Mode.EMPTY); assertNull(shape.getOpaqueRegion()); shape.setMode(NGShape.Mode.FILL); assertNotNull(shape.getOpaqueRegion()); assertEquals(or, shape.getOpaqueRegion()); shape.setMode(NGShape.Mode.STROKE); assertNull(shape.getOpaqueRegion()); shape.setMode(NGShape.Mode.STROKE_FILL); assertNotNull(shape.getOpaqueRegion()); assertEquals(or, shape.getOpaqueRegion()); }
@Test public void hasOpaqueRegionReturnsTrueIfModeIsFILL() { assertTrue(shape.hasOpaqueRegion()); }
@Test public void hasOpaqueRegionReturnsTrueIfModeIsSTROKE_FILE() { shape.setMode(NGShape.Mode.STROKE_FILL); assertTrue(shape.hasOpaqueRegion()); }