/** * {@link AbstractPainter} will pass {@code null} objects to * {@link AbstractPainter#doPaint(Graphics2D, Object, int, int) doPaint}. */ @Test public void testPaintWithNullObject() { p.paint(g, null, 10, 10); if (p.isCacheable()) { verify(p).doPaint(any(Graphics2D.class), isNull(), eq(10), eq(10)); } else { verify(p).doPaint(g, null, 10, 10); } }
/** * {@link AbstractPainter} will pass any object to * {@link AbstractPainter#doPaint(Graphics2D, Object, int, int) doPaint}. */ @Test public void testPaintWithAnyObject() { p.paint(g, "yo", 10, 10); if (p.isCacheable()) { verify(p).doPaint(any(Graphics2D.class), eq("yo"), eq(10), eq(10)); } else { verify(p).doPaint(g, "yo", 10, 10); } p.clearCache(); p.paint(g, 1f, 10, 10); if (p.isCacheable()) { verify(p).doPaint(any(Graphics2D.class), eq(1f), eq(10), eq(10)); } else { verify(p).doPaint(g, 1f, 10, 10); } }
/** * Ensure that paint orders calls correctly. */ @Test public void testInOrderPaintCallsWithoutCaching() { when(p.shouldUseCache()).thenReturn(false); InOrder orderedCalls = inOrder(p); p.paint(g, null, 10, 10); orderedCalls.verify(p).configureGraphics(g); orderedCalls.verify(p, times(0)).validate(null); orderedCalls.verify(p).doPaint(g, null, 10, 10); }
/** * Ensure that paint orders calls correctly. */ @Test public void testInOrderPaintCallsWithCaching() { when(p.shouldUseCache()).thenReturn(true); InOrder orderedCalls = inOrder(p); p.paint(g, null, 10, 10); orderedCalls.verify(p).configureGraphics(g); orderedCalls.verify(p).validate(null); //when caching we get a different graphics object verify(p).doPaint(any(Graphics2D.class), isNull(), eq(10), eq(10)); }
/** * Ensure that no painting occurs if width and/or height is <= 0. */ @Test public void testNoPaintWithNonPositiveDimension() { p.paint(g, null, 0, 10); p.paint(g, null, 10, 0); p.paint(g, null, -1, 10); p.paint(g, null, 10, -1); p.paint(g, null, 0, 0); verify(p, never()).doPaint(any(Graphics2D.class), any(Object.class), anyInt(), anyInt()); }
/** * Ensure that shouldUseCache forces the use of the cache. */ @Test public void testShouldUseCacheRepaintsWithCachedCopy() { when(p.shouldUseCache()).thenReturn(true); p.paint(g, null, 10, 10); //when caching we get a different graphics object verify(p, times(1)).doPaint(any(Graphics2D.class), isNull(), eq(10), eq(10)); p.paint(g, null, 10, 10); p.paint(g, null, 10, 10); p.paint(g, null, 10, 10); p.paint(g, null, 10, 10); //we do not invoke doPaint a subsequent calls verify(p, times(1)).doPaint(any(Graphics2D.class), isNull(), eq(10), eq(10)); } }
/** * Ensure that visibility settings correctly alter painting behavior. */ @Test public void testPaintAndVisibility() { p.setVisible(false); p.paint(g, null, 10, 10); verify(p, never()).doPaint(g, null, 10, 10); p.setVisible(true); testPaintWithNullObject(); }
/** * Issue #??-swingx: clearCache has no detectable effect. Test was poorly designed. It has had * an effect for a long time, but the member is not bound, so the test was failing erroneously. */ @Test public void testClearCacheDetectable() { p.setCacheable(true); p.paint(g, null, 10, 10); // sanity //when caching we get a different graphics object verify(p).doPaint(any(Graphics2D.class), isNull(), eq(10), eq(10)); assertThat("clean after paint", false, is(p.isDirty())); assertThat("cacheable is enabled", true, is(p.isCacheable())); assertThat("has a cached image", false, is(p.isCacheCleared())); p.clearCache(); assertThat("has a cached image", true, is(p.isCacheCleared())); }