DrawablePanel extends JPanel { @Override public Dimension getPreferredSize() { Dimension dims = super.getPreferredSize(); Dimension2D dimsPlot = getDrawable().getPreferredSize(); dims.setSize(dimsPlot); return dims; } DrawablePanel(Drawable drawable); Drawable getDrawable(); @Override void setBounds(Rectangle bounds); @Override void setBounds(int x, int y, int width, int height); @Override Dimension getPreferredSize(); @Override Dimension getMinimumSize(); boolean isAntialiased(); void setAntialiased(boolean antialiased);  }
@Test public void testSize() { Dimension size = panel.getPreferredSize(); assertEquals(0.0, size.getWidth(), DELTA); assertEquals(0.0, size.getHeight(), DELTA); }