PanelBorder extends AbstractBorder { @Override public void paintBorder(Component c, Graphics gInit, int x, int y, int width, int height) { Graphics g = gInit.create(); g.setColor(visibleBorderColor(borderColor, c.getBackground())); if (hasNorthBorder(this.borders)) { drawBorder(g, x+offset, y, x + width - 1, y, this.borderStyle); } if (hasSouthBorder(this.borders)) { drawBorder(g, x+offset, y + height-1, x+width, y + height-1, this.borderStyle); } if (hasEastBorder(this.borders)) { drawBorder(g, x + width - 1, y, x + width - 1, y + height - 1, this.borderStyle); } if (hasWestBorder(this.borders)) { drawBorder(g, x, y + height, x, y, this.borderStyle); } g.dispose(); } PanelBorder(byte initialBorderState);  PanelBorder(Color color); byte getBorders(); @Override void paintBorder(Component c, Graphics gInit, int x, int y, int width, int height); void setBorderStyle(int newStyle); void setBorderStyle(BorderStyle newStyle); void setBorderState(byte newBorderState); void addBorderState(byte newBorder); void removeBorderState(byte removeBorder); void removeAllBorders(); @Override Insets getBorderInsets(Component c); @Override boolean isBorderOpaque(); boolean isBorderActive(byte border); int getBorderStyle(); Color getBorderColor(); void setBorderColor(Color borderColor); static boolean hasNorthBorder(byte borders); static boolean hasEastBorder(byte borders); static boolean hasSouthBorder(byte borders); static boolean hasWestBorder(byte borders); void setOffset(int offset); void setDefaultBorderColor(Color defaultBorderColor); static final byte NO_BORDER; static final byte NORTH_BORDER; static final byte SOUTH_BORDER; static final byte EAST_BORDER; static final byte WEST_BORDER; static final byte ALL_BORDERS; }
@Test public void testGraphicsContextNotReset() { PanelBorder panelBorder = new PanelBorder(Color.BLUE); Mockito.when(g1.create()).thenReturn(g2); panelBorder.paintBorder(c, g1, 0, 0, 10, 10); Mockito.verify(g1).create(); Mockito.verify(g1, Mockito.times(0)).setColor((Color)Mockito.anyObject()); Mockito.verify(g2,Mockito.atLeastOnce()).setColor(Color.BLUE); Mockito.verify(g2, Mockito.times(1)).dispose(); }