@Test
public void labelTextIsFittedProperly() throws Exception {

    final StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    
    // Red dot at start of text
    sb.append("<span style=\"color: #FF0000;\">.</span>");
    
    // Long text
    sb.append("This is a very very very very very very very very very very ");
    sb.append("very very very very very very very very very very very very ");
    sb.append("very very very very very very very very very very very very ");
    sb.append("long message");
    
    // Blue dot at end of text
    sb.append("<span style=\"color: #0000FF;\">.</span>");
    sb.append("</html>");

    final int labelWidth = 300;
    final Dimension dim = DialogUtils.getHtmlLabelTextExtent(sb.toString(), labelWidth, true);
    
    JFrame frame = GuiActionRunner.execute(new GuiQuery<JFrame>() {
        @Override
        protected JFrame executeInEDT() throws Throwable {
            JFrame frame = new JFrame();
            
            /**
             * mbedward: 
             * I tried overriding the label's paintComponent method to
             * disable text anti-aliasing in order to make searching for
             * the red and blue dots easier, but the rendering hint did
             * not seem to affect HTML rendering. So instead, the
             * findColorInRange method is used to allow for the fuzz of
             * colour values.
             */
            JLabel label = new JLabel(sb.toString());
            label.setName("TheLabel");
            
            label.setPreferredSize(dim);
            frame.add(label);
            
            frame.pack();
            return frame;
        }
    });
    
    FrameFixture fixture = new FrameFixture(frame);
    Insets insets = frame.getInsets();
    fixture.show();
    
    JLabelFixture lf = fixture.label("TheLabel");
    Point pos = lf.component().getLocationOnScreen();
    Dimension size = lf.component().getSize();
    
    Robot robot = new Robot();
    BufferedImage img = robot.createScreenCapture(new Rectangle(pos, dim));
    fixture.close();
    
    if (displayLabelImage) {
        CountDownLatch latch = TestImageFrame.showImage(img, "Label screen shot");
        latch.await();
    }
    // Search for the red-ish start dot
    int[] lower = new int[] {200, 0, 0};
    int[] upper = new int[] {255, 80, 80};
    Rectangle bounds = new Rectangle(img.getMinX(), img.getMinY(), 20, 20);
    assertTrue( findColorInRange(img, bounds, lower, upper) );
    
    // Search for the blue-ish end dot
    lower = new int[] {0, 0, 200};
    upper = new int[] {80, 80, 255};
    bounds = new Rectangle(
            img.getMinX(), img.getMinY() + img.getHeight() - 20, 
            img.getWidth(), 20);
    assertTrue( findColorInRange(img, bounds, lower, upper));
    
    fixture.cleanUp();
}