1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.scene.control.skin;
  27 
  28 import static org.junit.Assert.assertEquals;
  29 import static org.junit.Assert.assertFalse;
  30 import static org.junit.Assert.assertTrue;
  31 import javafx.geometry.Insets;
  32 import javafx.geometry.Pos;
  33 import javafx.scene.control.ContentDisplay;
  34 import javafx.scene.control.Label;
  35 import javafx.scene.control.OverrunStyle;
  36 import javafx.scene.control.SkinBaseAccessor;
  37 import javafx.scene.effect.BlendMode;
  38 import javafx.scene.paint.Color;
  39 import javafx.scene.shape.Rectangle;
  40 import javafx.scene.text.Font;
  41 import javafx.scene.text.Text;
  42 import javafx.scene.text.TextAlignment;
  43 
  44 import org.junit.Before;
  45 import org.junit.Ignore;
  46 import org.junit.Test;
  47 
  48 /**
  49  * Need to test:
  50  *  - String truncation works correctly
  51  *  - min/max/pref width/height when multiline text is turned on
  52  */
  53 public class LabelSkinTest {
  54     private Label label;
  55     private LabelSkinMock skin;
  56     private Text text;
  57     
  58     @Before public void setup() {
  59         label = new Label();
  60         skin = new LabelSkinMock(label);
  61         // Set some padding so that any places where padding was being
  62         // computed but wasn't expected will be caught.
  63         label.setPadding(new Insets(10, 10, 10, 10));
  64         label.setSkin(skin);
  65         // It so happens that a brand new LabelSkin on a plain Label
  66         // will have as its only child the Text node
  67         text = (Text) SkinBaseAccessor.getChildren(skin).get(0);
  68     }
  69     
  70     /****************************************************************************
  71      *                                                                          *
  72      * Tests for change notification                                            *
  73      *                                                                          *
  74      ***************************************************************************/
  75     
  76     @Test public void sizeChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
  77         assertFalse(skin.propertyChanged); // sanity check
  78         label.resize(500, label.getHeight());
  79         assertTrue(skin.propertyChanged);
  80         assertEquals(1, skin.propertyChangeCount); // sanity check
  81         label.resize(label.getWidth(), label.prefHeight(label.getWidth()));
  82         assertEquals(2, skin.propertyChangeCount); // sanity check
  83     }
  84     
  85     @Test public void textFillChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
  86         label.setTextFill(Color.PURPLE);
  87         assertTrue(skin.propertyChanged);
  88     }
  89     
  90     @Test public void fontChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
  91         final Font f = Font.font("Arial", 64);
  92         label.setFont(f);
  93         assertTrue(skin.propertyChanged);
  94     }
  95     
  96     @Test public void graphicChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
  97         label.setGraphic(new Rectangle());
  98         assertTrue(skin.propertyChanged);
  99     }
 100     
 101     @Test public void contentDisplayChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 102         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
 103         assertTrue(skin.propertyChanged);
 104     }
 105     
 106     @Test public void graphicTextGapChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 107         label.setGraphicTextGap(60.34);
 108         assertTrue(skin.propertyChanged);
 109     }
 110     
 111     @Test public void hposChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 112         label.setAlignment(Pos.CENTER_RIGHT);
 113         label.setAlignment(Pos.CENTER_RIGHT);
 114         assertTrue(skin.propertyChanged);
 115     }
 116     
 117     @Test public void vposChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 118         label.setAlignment(Pos.TOP_CENTER);
 119         assertTrue(skin.propertyChanged);
 120     }
 121     
 122     @Test public void textChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 123         label.setText("Bust my buffers!");
 124         assertTrue(skin.propertyChanged);
 125     }
 126     
 127     @Test public void textAlignmentChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 128         label.setTextAlignment(TextAlignment.JUSTIFY);
 129         assertTrue(skin.propertyChanged);
 130     }
 131     
 132     @Test public void textOverrunChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 133         label.setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS);
 134         assertTrue(skin.propertyChanged);
 135     }
 136     
 137     @Test public void wrapTextChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 138         label.setWrapText(true);
 139         assertTrue(skin.propertyChanged);
 140     }
 141     
 142     @Test public void underlineChangesOnLabelShouldInvoke_handleControlPropertyChanged() {
 143         label.setUnderline(true);
 144         assertTrue(skin.propertyChanged);
 145     }
 146     
 147     @Test public void uninterestingChangesOnLabelShouldNotInvoke_handleControlPropertyChanged() {
 148         label.setBlendMode(BlendMode.BLUE);
 149         assertFalse(skin.propertyChanged);
 150     }
 151     
 152     /****************************************************************************
 153      *                                                                          *
 154      * Tests for invalidation. When each of various properties change, we need  *
 155      * to invalidate some state, such as via requestLayout().                   *
 156      *                                                                          *
 157      ***************************************************************************/
 158     
 159     @Test public void graphicLayoutBoundsChangeShouldInvalidateLayoutAndDisplayText() {
 160         final Rectangle r = new Rectangle(20, 20);
 161         label.setGraphic(r);
 162         label.layout();
 163         skin.updateDisplayedText();
 164         
 165         r.setWidth(30);
 166         assertTrue(label.isNeedsLayout());
 167         assertTrue(skin.invalidText);
 168     }
 169     
 170     @Test public void widthChangesOnLabelShouldInvalidateLayoutAndDisplayText() {
 171         label.layout();
 172         skin.updateDisplayedText();
 173 
 174         label.resize(500, label.getHeight());
 175         assertTrue(label.isNeedsLayout());
 176         assertTrue(skin.invalidText);
 177     }
 178     
 179     @Test public void widthChangesWhenWrapTextIsTrueUpdatesTheWrappingWidth() {
 180         // Assert that the wrapping width changes with the label width if wrapText is true.
 181         // However, this will only be required if the longest line in the text is itself
 182         // wider than the label's available width.
 183         label.setText("A long line which is wider than 100 pixels.");
 184         label.setWrapText(true);
 185         label.autosize();
 186         //label.layout();
 187         skin.updateDisplayedText();
 188         
 189         final double oldWrappingWidth = text.getWrappingWidth();
 190         label.resize(100, label.getHeight());
 191         skin.updateDisplayedText();
 192         assertFalse(oldWrappingWidth == text.getWrappingWidth());
 193         assertTrue(text.getWrappingWidth() > 0);
 194     }
 195     
 196     @Test public void widthChangesWhenWrapTextIsFalseKeepsWrappingWidthAtZero() {
 197         label.layout();
 198         skin.updateDisplayedText();
 199         
 200         label.resize(500, label.getHeight());
 201         assertEquals(0, text.getWrappingWidth(), 0);
 202     }
 203     
 204     @Test public void fontChangesOnLabelShouldInvalidateLayoutAndDisplayTextAndEllipsesWidthAndTextWidth() {
 205         label.layout();
 206         skin.updateDisplayedText();
 207         
 208         label.setFont(Font.font("Arial", 37));
 209         assertTrue(label.isNeedsLayout());
 210         assertTrue(skin.invalidText);
 211         assertEquals(Double.NEGATIVE_INFINITY, skin.textWidth, 0);
 212         assertEquals(Double.NEGATIVE_INFINITY, skin.ellipsisWidth, 0);
 213     }
 214 
 215     @Test public void graphicChangesOnLabelShouldInvalidateLayoutAndDisplayText() {
 216         label.layout();
 217         skin.updateDisplayedText();
 218         
 219         label.setGraphic(new Rectangle(20, 20));
 220         assertTrue(label.isNeedsLayout());
 221         assertTrue(skin.invalidText);
 222     }
 223 
 224     @Test public void contentDisplayChangesOnLabelShouldInvalidateLayoutAndDisplayText() {
 225         label.layout();
 226         skin.updateDisplayedText();
 227         
 228         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
 229         assertTrue(label.isNeedsLayout());
 230         assertTrue(skin.invalidText);
 231     }
 232 
 233     @Test public void graphicTextGapChangesOnLabelShouldInvalidateLayoutAndDisplayText() {
 234         label.layout();
 235         skin.updateDisplayedText();
 236         
 237         label.setGraphicTextGap(8.37);
 238         assertTrue(label.isNeedsLayout());
 239         assertTrue(skin.invalidText);
 240     }
 241 
 242     @Test public void hposChangesOnLabelShouldInvalidateLayout() {
 243         label.layout();
 244         skin.updateDisplayedText();
 245         
 246         label.setAlignment(Pos.CENTER_RIGHT);
 247         assertTrue(label.isNeedsLayout());
 248         assertFalse(skin.invalidText);
 249     }
 250 
 251     @Test public void vposChangesOnLabelShouldInvalidateLayout() {
 252         label.layout();
 253         skin.updateDisplayedText();
 254         
 255         label.setAlignment(Pos.TOP_CENTER);
 256         assertTrue(label.isNeedsLayout());
 257         assertFalse(skin.invalidText);
 258     }
 259 
 260     @Test public void textChangesOnLabelShouldInvalidateLayoutAndDisplayTextAndTextWidth() {
 261         label.layout();
 262         skin.updateDisplayedText();
 263         
 264         label.setText("Apples and Oranges");
 265         assertTrue(label.isNeedsLayout());
 266         assertTrue(skin.invalidText);
 267         assertEquals(Double.NEGATIVE_INFINITY, skin.textWidth, 0);
 268     }
 269 // TODO(aim): changing textAlignment doesn't actually change Text layoutBounds
 270 //
 271 //    @Test public void textAlignmentChangesOnLabelShouldInvalidateLayout() {
 272 //        label.layout();
 273 //        skin.updateDisplayedText();
 274 //
 275 //        label.setTextAlignment(TextAlignment.JUSTIFY);
 276 //        assertTrue(label.isNeedsLayout());
 277 //        assertFalse(skin.invalidText);
 278 //    }
 279 
 280     @Test public void textOverrunChangesOnLabelShouldInvalidateLayoutAndDisplayText() {
 281         label.layout();
 282         skin.updateDisplayedText();
 283         
 284         label.setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS);
 285         assertTrue(label.isNeedsLayout());
 286         assertTrue(skin.invalidText);
 287     }
 288 
 289     @Test public void wrapTextChangesOnLabelShouldInvalidateLayoutAndDisplayTextAndWrappingWidth() {
 290         label.setText("A long line which is wider than 100 pixels.");
 291         label.resize(100, 30);
 292         label.layout();
 293         skin.updateDisplayedText();
 294 
 295         final double oldWrappingWidth = text.getWrappingWidth();
 296         label.setWrapText(true);
 297         assertTrue(label.isNeedsLayout());
 298         assertTrue(skin.invalidText);
 299         assertFalse(oldWrappingWidth == text.getWrappingWidth());
 300         assertTrue(text.getWrappingWidth() > 0);
 301     }
 302 
 303     @Test public void underlineChangesOnLabelShouldInvalidateLayoutAndDisplayText() {
 304         label.layout();
 305         skin.updateDisplayedText();
 306         
 307         label.setUnderline(true);
 308         assertTrue(label.isNeedsLayout());
 309         assertTrue(skin.invalidText);
 310     }
 311 
 312     /****************************************************************************
 313      *                                                                          *
 314      * Tests for minWidth                                                       *
 315      *                                                                          *
 316      ***************************************************************************/
 317 
 318     @Test public void whenTextIsNullAndNoGraphic_computeMinWidth_ReturnsZero() {
 319         label.setPadding(new Insets(7, 7, 7, 7));
 320         label.setText(null);
 321         assertEquals(0.0 + 14, label.minWidth(-1), 0);
 322     }
 323     
 324     @Test public void whenTextIsEmptyAndNoGraphic_computeMinWidth_ReturnsZero() {
 325         label.setPadding(new Insets(7, 7, 7, 7));
 326         label.setText("");
 327         assertEquals(0.0 + 14, label.minWidth(-1), 0);
 328     }
 329     
 330     @Test public void whenTextIsShorterThanEllipsisAndNoGraphic_computeMinWidth_ReturnsTextWidth() {
 331         label.setPadding(new Insets(7, 7, 7, 7));
 332         label.setText(".");
 333         assertTrue(label.minWidth(-1) >= 0);
 334         assertEquals(skin.textWidth + 14, label.minWidth(-1), 0);
 335     }
 336 
 337     @Test public void whenTextIsGreaterThanEllipsisAndNoGraphic_computeMinWidth_ReturnsEllipsisWidth() {
 338         label.setPadding(new Insets(7, 7, 7, 7));
 339         label.setText("These are the times that try men's souls.");
 340         assertTrue(label.minWidth(-1) >= 0);
 341         assertEquals(skin.ellipsisWidth + 14, label.minWidth(-1), 0);
 342     }
 343 
 344     @Test public void whenTextIsNullAndGraphicIsUnmanaged_computeMinWidth_ReturnsZero() {
 345         label.setPadding(new Insets(7, 7, 7, 7));
 346         Rectangle r = new Rectangle(23, 500);
 347         r.setManaged(false);
 348         label.setGraphic(r);
 349         label.setText(null);
 350         assertEquals(0.0 + 14, label.minWidth(-1), 0);
 351     }
 352     
 353     @Test public void whenTextIsEmptyAndGraphicIsUnmanaged_computeMinWidth_ReturnsZero() {
 354         label.setPadding(new Insets(7, 7, 7, 7));
 355         Rectangle r = new Rectangle(23, 500);
 356         r.setManaged(false);
 357         label.setGraphic(r);
 358         label.setText("");
 359         assertEquals(0.0 + 14, label.minWidth(-1), 0);
 360     }
 361     
 362     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsUnmanaged_computeMinWidth_ReturnsTextWidth() {
 363         label.setPadding(new Insets(7, 7, 7, 7));
 364         Rectangle r = new Rectangle(23, 500);
 365         r.setManaged(false);
 366         label.setGraphic(r);
 367         label.setText(".");
 368         assertTrue(label.minWidth(-1) >= 0);
 369         assertEquals(skin.textWidth + 14, label.minWidth(-1), 0);
 370     }
 371 
 372     @Test public void whenTextIsGreaterThanEllipsisAndGraphicIsUnmanaged_computeMinWidth_ReturnsEllipsisWidth() {
 373         label.setPadding(new Insets(7, 7, 7, 7));
 374         Rectangle r = new Rectangle(23, 500);
 375         r.setManaged(false);
 376         label.setGraphic(r);
 377         label.setText("These are the times that try men's souls.");
 378         assertTrue(label.minWidth(-1) >= 0);
 379         assertEquals(skin.ellipsisWidth + 14, label.minWidth(-1), 0);
 380     }
 381 
 382     @Test public void whenTextIsNullAndGraphicIsSet_computeMinWidth_ReturnsGraphicWidth() {
 383         label.setPadding(new Insets(7, 7, 7, 7));
 384         Rectangle r = new Rectangle(23, 23);
 385         label.setGraphic(r);
 386         label.setText(null);
 387         assertTrue(label.minWidth(-1) >= 0);
 388         assertEquals(23 + 14, label.minWidth(-1), 0);
 389     }
 390     
 391     @Test public void whenTextIsEmptyAndGraphicIsSet_computeMinWidth_ReturnsGraphicWidth() {
 392         label.setPadding(new Insets(7, 7, 7, 7));
 393         Rectangle r = new Rectangle(23, 23);
 394         label.setGraphic(r);
 395         label.setText("");
 396         assertTrue(label.minWidth(-1) >= 0);
 397         assertEquals(23 + 14, label.minWidth(-1), 0);
 398     }
 399 
 400     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsLEFT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusTextWidth() {
 401         label.setPadding(new Insets(7, 7, 7, 7));
 402         Rectangle r = new Rectangle(23, 23);
 403         label.setGraphicTextGap(2);
 404         label.setGraphic(r);
 405         label.setContentDisplay(ContentDisplay.LEFT);
 406         label.setText(".");
 407         assertTrue(label.minWidth(-1) >= 0);
 408         assertEquals(23 + 2 + skin.textWidth + 14, label.minWidth(-1), 0);
 409     }
 410 
 411     @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsLEFT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusEllipsisWidth() {
 412         label.setPadding(new Insets(7, 7, 7, 7));
 413         Rectangle r = new Rectangle(23, 23);
 414         label.setGraphicTextGap(2);
 415         label.setGraphic(r);
 416         label.setContentDisplay(ContentDisplay.LEFT);
 417         label.setText("Wherefore art thou Romeo?");
 418         assertTrue(label.minWidth(-1) >= 0);
 419         assertEquals(23 + 2 + skin.ellipsisWidth + 14, label.minWidth(-1), 0);
 420     }
 421 
 422     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsRIGHT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusTextWidth() {
 423         label.setPadding(new Insets(7, 7, 7, 7));
 424         Rectangle r = new Rectangle(23, 23);
 425         label.setGraphicTextGap(2);
 426         label.setGraphic(r);
 427         label.setContentDisplay(ContentDisplay.RIGHT);
 428         label.setText(".");
 429         assertTrue(label.minWidth(-1) >= 0);
 430         assertEquals(23 + 2 + skin.textWidth + 14, label.minWidth(-1), 0);
 431     }
 432 
 433     @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsRIGHT_computeMinWidth_ReturnsGraphicWidthPlusGraphicTextGapPlusEllipsisWidth() {
 434         label.setPadding(new Insets(7, 7, 7, 7));
 435         Rectangle r = new Rectangle(23, 23);
 436         label.setGraphicTextGap(2);
 437         label.setGraphic(r);
 438         label.setContentDisplay(ContentDisplay.RIGHT);
 439         label.setText("Wherefore art thou Romeo?");
 440         assertTrue(label.minWidth(-1) >= 0);
 441         assertEquals(23 + 2 + skin.ellipsisWidth + 14, label.minWidth(-1), 0);
 442     }
 443 
 444     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsCENTER_computeMinWidth_ReturnsRightAnswer() {
 445         label.setPadding(new Insets(7, 7, 7, 7));
 446         Rectangle r = new Rectangle(23, 23);
 447         label.setGraphicTextGap(2);
 448         label.setGraphic(r);
 449         label.setContentDisplay(ContentDisplay.CENTER);
 450         label.setText(".");
 451         assertTrue(label.minWidth(-1) >= 0);
 452         assertEquals(Math.max(23, skin.textWidth) + 14, label.minWidth(-1), 0);
 453     }
 454 
 455     @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsCENTER_computeMinWidth_ReturnsRightAnswer() {
 456         label.setPadding(new Insets(7, 7, 7, 7));
 457         Rectangle r = new Rectangle(23, 23);
 458         label.setGraphicTextGap(2);
 459         label.setGraphic(r);
 460         label.setContentDisplay(ContentDisplay.CENTER);
 461         label.setText("Wherefore art thou Romeo?");
 462         assertTrue(label.minWidth(-1) >= 0);
 463         assertEquals(Math.max(23, skin.ellipsisWidth) + 14, label.minWidth(-1), 0);
 464     }
 465 
 466     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsTOP_computeMinWidth_ReturnsRightAnswer() {
 467         label.setPadding(new Insets(7, 7, 7, 7));
 468         Rectangle r = new Rectangle(23, 23);
 469         label.setGraphicTextGap(2);
 470         label.setGraphic(r);
 471         label.setContentDisplay(ContentDisplay.TOP);
 472         label.setText(".");
 473         assertTrue(label.minWidth(-1) >= 0);
 474         assertEquals(Math.max(23, skin.textWidth) + 14, label.minWidth(-1), 0);
 475     }
 476 
 477     @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsTOP_computeMinWidth_ReturnsRightAnswer() {
 478         label.setPadding(new Insets(7, 7, 7, 7));
 479         Rectangle r = new Rectangle(23, 23);
 480         label.setGraphicTextGap(2);
 481         label.setGraphic(r);
 482         label.setContentDisplay(ContentDisplay.TOP);
 483         label.setText("Wherefore art thou Romeo?");
 484         assertTrue(label.minWidth(-1) >= 0);
 485         assertEquals(Math.max(23, skin.ellipsisWidth) + 14, label.minWidth(-1), 0);
 486     }
 487 
 488     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsBOTTOM_computeMinWidth_ReturnsRightAnswer() {
 489         label.setPadding(new Insets(7, 7, 7, 7));
 490         Rectangle r = new Rectangle(23, 23);
 491         label.setGraphicTextGap(2);
 492         label.setGraphic(r);
 493         label.setContentDisplay(ContentDisplay.BOTTOM);
 494         label.setText(".");
 495         assertTrue(label.minWidth(-1) >= 0);
 496         assertEquals(Math.max(23, skin.textWidth) + 14, label.minWidth(-1), 0);
 497     }
 498 
 499     @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsBOTTOM_computeMinWidth_ReturnsRightAnswer() {
 500         label.setPadding(new Insets(7, 7, 7, 7));
 501         Rectangle r = new Rectangle(23, 23);
 502         label.setGraphicTextGap(2);
 503         label.setGraphic(r);
 504         label.setContentDisplay(ContentDisplay.BOTTOM);
 505         label.setText("Wherefore art thou Romeo?");
 506         assertTrue(label.minWidth(-1) >= 0);
 507         assertEquals(Math.max(23, skin.ellipsisWidth) + 14, label.minWidth(-1), 0);
 508     }
 509 
 510     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsGRAPHIC_ONLY_computeMinWidth_ReturnsRightAnswer() {
 511         label.setPadding(new Insets(7, 7, 7, 7));
 512         Rectangle r = new Rectangle(3, 3);
 513         label.setGraphicTextGap(2);
 514         label.setGraphic(r);
 515         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
 516         label.setText(".");
 517         assertTrue(label.minWidth(-1) >= 0);
 518         assertEquals(3 + 14, label.minWidth(-1), 0);
 519     }
 520 
 521     @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsGRAPHIC_ONLY_computeMinWidth_ReturnsRightAnswer() {
 522         label.setPadding(new Insets(7, 7, 7, 7));
 523         Rectangle r = new Rectangle(3, 3);
 524         label.setGraphicTextGap(2);
 525         label.setGraphic(r);
 526         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
 527         label.setText("Wherefore art thou Romeo?");
 528         assertTrue(label.minWidth(-1) >= 0);
 529         assertEquals(3 + 14, label.minWidth(-1), 0);
 530     }
 531 
 532     @Test public void whenTextIsShorterThanEllipsisAndGraphicIsSetAndContentDisplayIsTEXT_ONLY_computeMinWidth_ReturnsRightAnswer() {
 533         label.setPadding(new Insets(7, 7, 7, 7));
 534         Rectangle r = new Rectangle(230, 230);
 535         label.setGraphicTextGap(2);
 536         label.setGraphic(r);
 537         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
 538         label.setText(".");
 539         assertTrue(label.minWidth(-1) >= 0);
 540         assertEquals(skin.textWidth + 14, label.minWidth(-1), 0);
 541     }
 542 
 543     @Test public void whenTextIsLongThanEllipsisAndGraphicIsSetAndContentDisplayIsTEXT_ONLY_computeMinWidth_ReturnsRightAnswer() {
 544         label.setPadding(new Insets(7, 7, 7, 7));
 545         Rectangle r = new Rectangle(230, 230);
 546         label.setGraphicTextGap(2);
 547         label.setGraphic(r);
 548         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
 549         label.setText("Wherefore art thou Romeo?");
 550         assertTrue(label.minWidth(-1) >= 0);
 551         assertEquals(skin.ellipsisWidth + 14, label.minWidth(-1), 0);
 552     }
 553 
 554     /****************************************************************************
 555      *                                                                          *
 556      * Tests for minHeight                                                      *
 557      *                                                                          *
 558      ***************************************************************************/
 559 
 560     @Test public void whenTextIsNullAndNoGraphic_computeMinHeight_ReturnsSingleLineStringHeight() {
 561         label.setText(null);
 562         label.setPadding(new Insets(7, 7, 7, 7));
 563         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 564         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 565     }
 566     
 567     @Test public void whenTextIsEmptyAndNoGraphic_computeMinHeight_ReturnsSingleLineStringHeight() {
 568         label.setText("");
 569         label.setPadding(new Insets(7, 7, 7, 7));
 570         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 571         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 572     }
 573     
 574     @Test public void whenTextIsSetAndNoGraphic_computeMinHeight_ReturnsSingleLineStringHeight() {
 575         label.setText("Howdy Pardner");
 576         label.setPadding(new Insets(7, 7, 7, 7));
 577         assertTrue(label.minHeight(-1) >= 0);
 578         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 579         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 580     }
 581     
 582     @Test public void whenTextIsNullAndUnmanagedGraphic_computeMinHeight_ReturnsSingleLineStringHeight() {
 583         label.setText(null);
 584         label.setPadding(new Insets(7, 7, 7, 7));
 585         Rectangle r = new Rectangle(23, 500);
 586         r.setManaged(false);
 587         label.setGraphic(r);
 588         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 589         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 590     }
 591     
 592     @Test public void whenTextIsEmptyAndUnmanagedGraphic_computeMinHeight_ReturnsSingleLineStringHeight() {
 593         label.setText("");
 594         label.setPadding(new Insets(7, 7, 7, 7));
 595         Rectangle r = new Rectangle(23, 500);
 596         r.setManaged(false);
 597         label.setGraphic(r);
 598         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 599         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 600     }
 601     
 602     @Test public void whenTextIsSetAndUnmanagedGraphic_computeMinHeight_ReturnsSingleLineStringHeight() {
 603         label.setText("Howdy Pardner");
 604         label.setPadding(new Insets(7, 7, 7, 7));
 605         Rectangle r = new Rectangle(23, 500);
 606         r.setManaged(false);
 607         label.setGraphic(r);
 608         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 609         assertTrue(label.minHeight(-1) >= 0);
 610         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 611     }
 612     
 613     @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 614         label.setText(null);
 615         label.setPadding(new Insets(7, 7, 7, 7));
 616         Rectangle r = new Rectangle(23, 23);
 617         label.setGraphicTextGap(2);
 618         label.setGraphic(r);
 619         label.setContentDisplay(ContentDisplay.TOP);
 620         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 621         assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0);
 622     }
 623     
 624     @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 625         label.setText("");
 626         label.setPadding(new Insets(7, 7, 7, 7));
 627         Rectangle r = new Rectangle(23, 23);
 628         label.setGraphicTextGap(2);
 629         label.setGraphic(r);
 630         label.setContentDisplay(ContentDisplay.TOP);
 631         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 632         assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0);
 633     }
 634     
 635     @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 636         label.setText("For crying in the mud");
 637         label.setPadding(new Insets(7, 7, 7, 7));
 638         Rectangle r = new Rectangle(23, 23);
 639         label.setGraphic(r);
 640         label.setGraphicTextGap(2);
 641         label.setContentDisplay(ContentDisplay.TOP);
 642         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 643         assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0);
 644     }
 645     
 646     @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 647         label.setText(null);
 648         label.setPadding(new Insets(7, 7, 7, 7));
 649         Rectangle r = new Rectangle(23, 23);
 650         label.setGraphic(r);
 651         label.setContentDisplay(ContentDisplay.RIGHT);
 652         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 653         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 654     }
 655     
 656     @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 657         label.setText("");
 658         label.setPadding(new Insets(7, 7, 7, 7));
 659         Rectangle r = new Rectangle(23, 23);
 660         label.setGraphic(r);
 661         label.setContentDisplay(ContentDisplay.RIGHT);
 662         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 663         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 664     }
 665     
 666     @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 667         label.setText("For crying in the mud");
 668         label.setPadding(new Insets(7, 7, 7, 7));
 669         Rectangle r = new Rectangle(23, 23);
 670         label.setGraphic(r);
 671         label.setContentDisplay(ContentDisplay.RIGHT);
 672         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 673         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 674     }
 675     
 676     @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 677         label.setText(null);
 678         label.setPadding(new Insets(7, 7, 7, 7));
 679         Rectangle r = new Rectangle(23, 23);
 680         label.setGraphicTextGap(2);
 681         label.setGraphic(r);
 682         label.setContentDisplay(ContentDisplay.BOTTOM);
 683         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 684         assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0);
 685     }
 686     
 687     @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 688         label.setText("");
 689         label.setPadding(new Insets(7, 7, 7, 7));
 690         Rectangle r = new Rectangle(23, 23);
 691         label.setGraphicTextGap(2);
 692         label.setGraphic(r);
 693         label.setContentDisplay(ContentDisplay.BOTTOM);
 694         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 695         assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0);
 696     }
 697     
 698     @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 699         label.setText("For crying in the mud");
 700         label.setPadding(new Insets(7, 7, 7, 7));
 701         Rectangle r = new Rectangle(23, 23);
 702         label.setGraphic(r);
 703         label.setGraphicTextGap(2);
 704         label.setContentDisplay(ContentDisplay.BOTTOM);
 705         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 706         assertEquals(23 + lineHeight + 2 + 14, label.minHeight(-1), 0);
 707     }
 708     
 709     @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 710         label.setText(null);
 711         label.setPadding(new Insets(7, 7, 7, 7));
 712         Rectangle r = new Rectangle(23, 23);
 713         label.setGraphic(r);
 714         label.setContentDisplay(ContentDisplay.LEFT);
 715         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 716         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 717     }
 718     
 719     @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 720         label.setText("");
 721         label.setPadding(new Insets(7, 7, 7, 7));
 722         Rectangle r = new Rectangle(23, 23);
 723         label.setGraphic(r);
 724         label.setContentDisplay(ContentDisplay.LEFT);
 725         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 726         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 727     }
 728     
 729     @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 730         label.setText("For crying in the mud");
 731         label.setPadding(new Insets(7, 7, 7, 7));
 732         Rectangle r = new Rectangle(23, 23);
 733         label.setGraphic(r);
 734         label.setContentDisplay(ContentDisplay.LEFT);
 735         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 736         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 737     }
 738     
 739     @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 740         label.setText(null);
 741         label.setPadding(new Insets(7, 7, 7, 7));
 742         Rectangle r = new Rectangle(23, 23);
 743         label.setGraphic(r);
 744         label.setContentDisplay(ContentDisplay.CENTER);
 745         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 746         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 747     }
 748     
 749     @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 750         label.setText("");
 751         label.setPadding(new Insets(7, 7, 7, 7));
 752         Rectangle r = new Rectangle(23, 23);
 753         label.setGraphic(r);
 754         label.setContentDisplay(ContentDisplay.CENTER);
 755         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 756         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 757     }
 758     
 759     @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 760         label.setText("For crying in the mud");
 761         label.setPadding(new Insets(7, 7, 7, 7));
 762         Rectangle r = new Rectangle(23, 23);
 763         label.setGraphic(r);
 764         label.setContentDisplay(ContentDisplay.CENTER);
 765         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 766         assertEquals(Math.max(23, lineHeight) + 14, label.minHeight(-1), 0);
 767     }
 768     
 769     @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 770         label.setText(null);
 771         label.setPadding(new Insets(7, 7, 7, 7));
 772         Rectangle r = new Rectangle(23, 23);
 773         label.setGraphic(r);
 774         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
 775         assertEquals(23 + 14, label.minHeight(-1), 0);
 776     }
 777     
 778     @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 779         label.setText("");
 780         label.setPadding(new Insets(7, 7, 7, 7));
 781         Rectangle r = new Rectangle(23, 23);
 782         label.setGraphic(r);
 783         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
 784         assertEquals(23 + 14, label.minHeight(-1), 0);
 785     }
 786     
 787     @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 788         label.setText("For crying in the mud");
 789         label.setPadding(new Insets(7, 7, 7, 7));
 790         Rectangle r = new Rectangle(23, 23);
 791         label.setGraphic(r);
 792         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
 793         assertEquals(23 + 14, label.minHeight(-1), 0);
 794     }
 795     
 796     @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 797         label.setText(null);
 798         label.setPadding(new Insets(7, 7, 7, 7));
 799         Rectangle r = new Rectangle(23, 23);
 800         label.setGraphic(r);
 801         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
 802         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 803         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 804     }
 805     
 806     @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 807         label.setText("");
 808         label.setPadding(new Insets(7, 7, 7, 7));
 809         Rectangle r = new Rectangle(23, 23);
 810         label.setGraphic(r);
 811         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
 812         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 813         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 814     }
 815     
 816     @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMinHeight_ReturnsRightAnswer() {
 817         label.setText("For crying in the mud");
 818         label.setPadding(new Insets(7, 7, 7, 7));
 819         Rectangle r = new Rectangle(23, 23);
 820         label.setGraphic(r);
 821         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
 822         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
 823         assertEquals(lineHeight + 14, label.minHeight(-1), 0);
 824     }
 825     
 826     /****************************************************************************
 827      *                                                                          *
 828      * Tests for prefWidth                                                      *
 829      *                                                                          *
 830      ***************************************************************************/
 831 
 832     @Test public void whenTextIsNullAndNoGraphic_computePrefWidth_ReturnsPadding() {
 833         label.setText(null);
 834         label.setPadding(new Insets(7, 7, 7, 7));
 835         assertEquals(14, label.prefWidth(-1), 0);
 836     }
 837     
 838     @Test public void whenTextIsEmptyAndNoGraphic_computePrefWidth_ReturnsPadding() {
 839         label.setText("");
 840         label.setPadding(new Insets(7, 7, 7, 7));
 841         assertEquals(14, label.prefWidth(-1), 0);
 842     }
 843     
 844     @Test public void whenTextIsSetAndNoGraphic_computePrefWidth_ReturnsTextWidthPlusPadding() {
 845         label.setText("Lollipop");
 846         label.setPadding(new Insets(7, 7, 7, 7));
 847         final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0);
 848         assertEquals(14 + textWidth, label.prefWidth(-1), 0);
 849     }
 850     
 851     @Test public void whenTextIsNullAndUnmanagedGraphic_computePrefWidth_ReturnsPadding() {
 852         label.setText(null);
 853         Rectangle r = new Rectangle(0, 0, 50, 50);
 854         r.setManaged(false);
 855         label.setGraphic(r);
 856         label.setPadding(new Insets(7, 7, 7, 7));
 857         assertEquals(14, label.prefWidth(-1), 0);
 858     }
 859     
 860     @Test public void whenTextIsEmptyAndUnmanagedGraphic_computePrefWidth_ReturnsPadding() {
 861         label.setText("");
 862         Rectangle r = new Rectangle(0, 0, 50, 50);
 863         r.setManaged(false);
 864         label.setGraphic(r);
 865         label.setPadding(new Insets(7, 7, 7, 7));
 866         assertEquals(14, label.prefWidth(-1), 0);
 867     }
 868     
 869     @Test public void whenTextIsSetAndUnmanagedGraphic_computePrefWidth_ReturnsTextWidthPlusPadding() {
 870         label.setText("Lollipop");
 871         Rectangle r = new Rectangle(0, 0, 50, 50);
 872         r.setManaged(false);
 873         label.setGraphic(r);
 874         label.setPadding(new Insets(7, 7, 7, 7));
 875         final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0);
 876         assertEquals(14 + textWidth, label.prefWidth(-1), 0);
 877     }
 878     
 879     @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
 880         label.setText(null);
 881         label.setGraphic(new Rectangle(0, 0, 20, 20));
 882         label.setGraphicTextGap(6.5);
 883         label.setContentDisplay(ContentDisplay.TOP);
 884         label.setPadding(new Insets(7, 7, 7, 7));
 885         assertEquals(14 + 20, label.prefWidth(-1), 0);
 886     }
 887     
 888     @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
 889         label.setText("");
 890         label.setGraphic(new Rectangle(0, 0, 20, 20));
 891         label.setGraphicTextGap(6.5);
 892         label.setContentDisplay(ContentDisplay.TOP);
 893         label.setPadding(new Insets(7, 7, 7, 7));
 894         assertEquals(14 + 20, label.prefWidth(-1), 0);
 895     }
 896     
 897     @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
 898         label.setText("Lollipop");
 899         label.setGraphic(new Rectangle(0, 0, 200, 20));
 900         label.setGraphicTextGap(6.5);
 901         label.setContentDisplay(ContentDisplay.TOP);
 902         label.setPadding(new Insets(7, 7, 7, 7));
 903         assertEquals(14 + 200, label.prefWidth(-1), 0);
 904     }
 905     
 906     @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndTextIsWider_computePrefWidth_ReturnsTextWidthPlusPadding() {
 907         label.setText("This is the right place");
 908         label.setGraphic(new Rectangle(0, 0, 20, 20));
 909         label.setGraphicTextGap(6.5);
 910         label.setContentDisplay(ContentDisplay.TOP);
 911         label.setPadding(new Insets(7, 7, 7, 7));
 912         final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0);
 913         assertEquals(14 + textWidth, label.prefWidth(-1), 0);
 914     }
 915 
 916     @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
 917         label.setText(null);
 918         label.setGraphic(new Rectangle(0, 0, 20, 20));
 919         label.setGraphicTextGap(6.5);
 920         label.setContentDisplay(ContentDisplay.RIGHT);
 921         label.setPadding(new Insets(7, 7, 7, 7));
 922         assertEquals(20 + 14, label.prefWidth(-1), 0);
 923     }
 924 
 925     @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
 926         label.setText("");
 927         label.setGraphic(new Rectangle(0, 0, 20, 20));
 928         label.setGraphicTextGap(6.5);
 929         label.setContentDisplay(ContentDisplay.RIGHT);
 930         label.setPadding(new Insets(7, 7, 7, 7));
 931         assertEquals(20 + 14, label.prefWidth(-1), 0);
 932     }
 933     
 934     @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computePrefWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() {
 935         label.setText("Howdy");
 936         label.setGraphic(new Rectangle(0, 0, 20, 20));
 937         label.setGraphicTextGap(6.5);
 938         label.setContentDisplay(ContentDisplay.RIGHT);
 939         label.setPadding(new Insets(7, 7, 7, 7));
 940         final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0);
 941         assertEquals(14 + textWidth + 6.5 + 20, label.prefWidth(-1), 0);
 942     }
 943     
 944     @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
 945         label.setText(null);
 946         label.setGraphic(new Rectangle(0, 0, 20, 20));
 947         label.setGraphicTextGap(6.5);
 948         label.setContentDisplay(ContentDisplay.BOTTOM);
 949         label.setPadding(new Insets(7, 7, 7, 7));
 950         assertEquals(14 + 20, label.prefWidth(-1), 0);
 951     }
 952     
 953     @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
 954         label.setText(null);
 955         label.setGraphic(new Rectangle(0, 0, 20, 20));
 956         label.setGraphicTextGap(6.5);
 957         label.setContentDisplay(ContentDisplay.BOTTOM);
 958         label.setPadding(new Insets(7, 7, 7, 7));
 959         assertEquals(14 + 20, label.prefWidth(-1), 0);
 960     }
 961     
 962     @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
 963         label.setText("Lollipop");
 964         label.setGraphic(new Rectangle(0, 0, 200, 20));
 965         label.setGraphicTextGap(6.5);
 966         label.setContentDisplay(ContentDisplay.BOTTOM);
 967         label.setPadding(new Insets(7, 7, 7, 7));
 968         assertEquals(14 + 200, label.prefWidth(-1), 0);
 969     }
 970     
 971     @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndTextIsWider_computePrefWidth_ReturnsTextWidthPlusPadding() {
 972         label.setText("This is the right place");
 973         label.setGraphic(new Rectangle(0, 0, 20, 20));
 974         label.setGraphicTextGap(6.5);
 975         label.setContentDisplay(ContentDisplay.BOTTOM);
 976         label.setPadding(new Insets(7, 7, 7, 7));
 977         final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0);
 978         assertEquals(14 + textWidth, label.prefWidth(-1), 0);
 979     }
 980 
 981     @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
 982         label.setText(null);
 983         label.setGraphic(new Rectangle(0, 0, 20, 20));
 984         label.setGraphicTextGap(6.5);
 985         label.setContentDisplay(ContentDisplay.LEFT);
 986         label.setPadding(new Insets(7, 7, 7, 7));
 987         assertEquals(20 + 14, label.prefWidth(-1), 0);
 988     }
 989 
 990     @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computePrefWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
 991         label.setText("");
 992         label.setGraphic(new Rectangle(0, 0, 20, 20));
 993         label.setGraphicTextGap(6.5);
 994         label.setContentDisplay(ContentDisplay.LEFT);
 995         label.setPadding(new Insets(7, 7, 7, 7));
 996         assertEquals(20 + 14, label.prefWidth(-1), 0);
 997     }
 998     
 999     @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computePrefWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() {
1000         label.setText("Howdy");
1001         label.setGraphic(new Rectangle(0, 0, 20, 20));
1002         label.setGraphicTextGap(6.5);
1003         label.setContentDisplay(ContentDisplay.LEFT);
1004         label.setPadding(new Insets(7, 7, 7, 7));
1005         final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0);
1006         assertEquals(14 + textWidth + 6.5 + 20, label.prefWidth(-1), 0);
1007     }
1008     
1009     @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
1010         label.setText(null);
1011         label.setGraphic(new Rectangle(0, 0, 20, 20));
1012         label.setGraphicTextGap(6.5);
1013         label.setContentDisplay(ContentDisplay.CENTER);
1014         label.setPadding(new Insets(7, 7, 7, 7));
1015         assertEquals(14 + 20, label.prefWidth(-1), 0);
1016     }
1017     
1018     @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
1019         label.setText("");
1020         label.setGraphic(new Rectangle(0, 0, 20, 20));
1021         label.setGraphicTextGap(6.5);
1022         label.setContentDisplay(ContentDisplay.CENTER);
1023         label.setPadding(new Insets(7, 7, 7, 7));
1024         assertEquals(14 + 20, label.prefWidth(-1), 0);
1025     }
1026     
1027     @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
1028         label.setText("Lollipop");
1029         label.setGraphic(new Rectangle(0, 0, 200, 20));
1030         label.setGraphicTextGap(6.5);
1031         label.setContentDisplay(ContentDisplay.CENTER);
1032         label.setPadding(new Insets(7, 7, 7, 7));
1033         assertEquals(14 + 200, label.prefWidth(-1), 0);
1034     }
1035     
1036     @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndTextIsWider_computePrefWidth_ReturnsTextWidthPlusPadding() {
1037         label.setText("This is the right place");
1038         label.setGraphic(new Rectangle(0, 0, 20, 20));
1039         label.setGraphicTextGap(6.5);
1040         label.setContentDisplay(ContentDisplay.CENTER);
1041         label.setPadding(new Insets(7, 7, 7, 7));
1042         final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0);
1043         assertEquals(14 + textWidth, label.prefWidth(-1), 0);
1044     }
1045 
1046     @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
1047         label.setText(null);
1048         label.setGraphic(new Rectangle(0, 0, 20, 20));
1049         label.setGraphicTextGap(6.5);
1050         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1051         label.setPadding(new Insets(7, 7, 7, 7));
1052         assertEquals(14 + 20, label.prefWidth(-1), 0);
1053     }
1054     
1055     @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
1056         label.setText("");
1057         label.setGraphic(new Rectangle(0, 0, 20, 20));
1058         label.setGraphicTextGap(6.5);
1059         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1060         label.setPadding(new Insets(7, 7, 7, 7));
1061         assertEquals(14 + 20, label.prefWidth(-1), 0);
1062     }
1063     
1064     @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndGraphicIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
1065         label.setText("Howdy");
1066         label.setGraphic(new Rectangle(0, 0, 200, 20));
1067         label.setGraphicTextGap(6.5);
1068         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1069         label.setPadding(new Insets(7, 7, 7, 7));
1070         assertEquals(14 + 200, label.prefWidth(-1), 0);
1071     }
1072     
1073     @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndTextIsWider_computePrefWidth_ReturnsGraphicWidthPlusPadding() {
1074         label.setText("Tally ho, off to the races");
1075         label.setGraphic(new Rectangle(0, 0, 20, 20));
1076         label.setGraphicTextGap(6.5);
1077         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1078         label.setPadding(new Insets(7, 7, 7, 7));
1079         assertEquals(14 + 20, label.prefWidth(-1), 0);
1080     }
1081     
1082     // TODO should this include the gap??
1083     @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefWidth_ReturnsPadding() {
1084         label.setText(null);
1085         label.setGraphic(new Rectangle(0, 0, 20, 20));
1086         label.setGraphicTextGap(6.5);
1087         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1088         label.setPadding(new Insets(7, 7, 7, 7));
1089         assertEquals(14, label.prefWidth(-1), 0);
1090     }
1091     
1092     @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefWidth_ReturnsPadding() {
1093         label.setText("");
1094         label.setGraphic(new Rectangle(0, 0, 20, 20));
1095         label.setGraphicTextGap(6.5);
1096         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1097         label.setPadding(new Insets(7, 7, 7, 7));
1098         assertEquals(14, label.prefWidth(-1), 0);
1099     }
1100     
1101     // TODO should this include the gap? I guess not, otherwise our gap would have to default to 0
1102     @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefWidth_ReturnsTextWidthPlusPadding() {
1103         label.setText("Yippee Skippee");
1104         label.setGraphic(new Rectangle(0, 0, 20, 20));
1105         label.setGraphicTextGap(6.5);
1106         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1107         label.setPadding(new Insets(7, 7, 7, 7));
1108         final double textWidth = Utils.computeTextWidth(label.getFont(), "Yippee Skippee", 0);
1109         assertEquals(14 + textWidth, label.prefWidth(-1), 0);
1110     }
1111     
1112     /****************************************************************************
1113      *                                                                          *
1114      * Tests for prefHeight                                                     *
1115      *                                                                          *
1116      ***************************************************************************/
1117 
1118     @Test public void whenTextHasNewlines_computePrefHeight_IncludesTheMultipleLinesInThePrefHeight() {
1119         label.setText("This\nis a test\nof the emergency\nbroadcast system.\nThis is only a test");
1120         label.setPadding(new Insets(0, 0, 0, 0));
1121         final double singleLineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1122         final double height = label.prefHeight(-1);
1123         assertTrue(height >= singleLineHeight * 5);
1124     }
1125     
1126     @Test public void whenTextHasNewlinesAfterPreviousComputationOf_computePrefHeight_IncludesTheMultipleLinesInThePrefHeight() {
1127         label.setText("This is a test");
1128         final double oldPrefHeight = label.prefHeight(-1);
1129         label.setText("This\nis a test\nof the emergency\nbroadcast system.\nThis is only a test");
1130         final double newPrefHeight = label.prefHeight(-1);
1131         assertTrue(oldPrefHeight != newPrefHeight);
1132     }
1133     
1134     @Test public void whenTextIsNullAndNoGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() {
1135         label.setText(null);
1136         label.setPadding(new Insets(7, 7, 7, 7));
1137         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1138         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1139     }
1140     
1141     @Test public void whenTextIsEmptyAndNoGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() {
1142         label.setText("");
1143         label.setPadding(new Insets(7, 7, 7, 7));
1144         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1145         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1146     }
1147     
1148     @Test public void whenTextIsSetAndNoGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() {
1149         label.setText("Howdy Pardner");
1150         label.setPadding(new Insets(7, 7, 7, 7));
1151         assertTrue(label.prefHeight(-1) >= 0);
1152         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1153         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1154     }
1155     
1156     @Test public void whenTextIsNullAndUnmanagedGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() {
1157         label.setText(null);
1158         label.setPadding(new Insets(7, 7, 7, 7));
1159         Rectangle r = new Rectangle(23, 500);
1160         r.setManaged(false);
1161         label.setGraphic(r);
1162         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1163         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1164     }
1165     
1166     @Test public void whenTextIsEmptyAndUnmanagedGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() {
1167         label.setText("");
1168         label.setPadding(new Insets(7, 7, 7, 7));
1169         Rectangle r = new Rectangle(23, 500);
1170         r.setManaged(false);
1171         label.setGraphic(r);
1172         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1173         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1174     }
1175     
1176     @Test public void whenTextIsSetAndUnmanagedGraphic_computePrefHeight_ReturnsSingleLineStringHeightPlusPadding() {
1177         label.setText("Howdy Pardner");
1178         label.setPadding(new Insets(7, 7, 7, 7));
1179         Rectangle r = new Rectangle(23, 500);
1180         r.setManaged(false);
1181         label.setGraphic(r);
1182         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1183         assertTrue(label.prefHeight(-1) >= 0);
1184         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1185     }
1186     
1187     @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1188         label.setText(null);
1189         label.setPadding(new Insets(7, 7, 7, 7));
1190         Rectangle r = new Rectangle(23, 23);
1191         label.setGraphicTextGap(2);
1192         label.setGraphic(r);
1193         label.setContentDisplay(ContentDisplay.TOP);
1194         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1195         assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0);
1196     }
1197     
1198     @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1199         label.setText("");
1200         label.setPadding(new Insets(7, 7, 7, 7));
1201         Rectangle r = new Rectangle(23, 23);
1202         label.setGraphicTextGap(2);
1203         label.setGraphic(r);
1204         label.setContentDisplay(ContentDisplay.TOP);
1205         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1206         assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0);
1207     }
1208     
1209     @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1210         label.setText("For crying in the mud");
1211         label.setPadding(new Insets(7, 7, 7, 7));
1212         Rectangle r = new Rectangle(23, 23);
1213         label.setGraphic(r);
1214         label.setGraphicTextGap(2);
1215         label.setContentDisplay(ContentDisplay.TOP);
1216         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1217         assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0);
1218     }
1219     
1220     @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1221         label.setText(null);
1222         label.setPadding(new Insets(7, 7, 7, 7));
1223         Rectangle r = new Rectangle(23, 23);
1224         label.setGraphic(r);
1225         label.setContentDisplay(ContentDisplay.RIGHT);
1226         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1227         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1228     }
1229     
1230     @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1231         label.setText("");
1232         label.setPadding(new Insets(7, 7, 7, 7));
1233         Rectangle r = new Rectangle(23, 23);
1234         label.setGraphic(r);
1235         label.setContentDisplay(ContentDisplay.RIGHT);
1236         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1237         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1238     }
1239     
1240     @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1241         label.setText("For crying in the mud");
1242         label.setPadding(new Insets(7, 7, 7, 7));
1243         Rectangle r = new Rectangle(23, 23);
1244         label.setGraphic(r);
1245         label.setContentDisplay(ContentDisplay.RIGHT);
1246         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1247         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1248     }
1249     
1250     @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1251         label.setText(null);
1252         label.setPadding(new Insets(7, 7, 7, 7));
1253         Rectangle r = new Rectangle(23, 23);
1254         label.setGraphicTextGap(2);
1255         label.setGraphic(r);
1256         label.setContentDisplay(ContentDisplay.BOTTOM);
1257         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1258         assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0);
1259     }
1260     
1261     @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1262         label.setText("");
1263         label.setPadding(new Insets(7, 7, 7, 7));
1264         Rectangle r = new Rectangle(23, 23);
1265         label.setGraphicTextGap(2);
1266         label.setGraphic(r);
1267         label.setContentDisplay(ContentDisplay.BOTTOM);
1268         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1269         assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0);
1270     }
1271     
1272     @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1273         label.setText("For crying in the mud");
1274         label.setPadding(new Insets(7, 7, 7, 7));
1275         Rectangle r = new Rectangle(23, 23);
1276         label.setGraphic(r);
1277         label.setGraphicTextGap(2);
1278         label.setContentDisplay(ContentDisplay.BOTTOM);
1279         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1280         assertEquals(14 + 23 + lineHeight + 2, label.prefHeight(-1), 0);
1281     }
1282     
1283     @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1284         label.setText(null);
1285         label.setPadding(new Insets(7, 7, 7, 7));
1286         Rectangle r = new Rectangle(23, 23);
1287         label.setGraphic(r);
1288         label.setContentDisplay(ContentDisplay.LEFT);
1289         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1290         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1291     }
1292     
1293     @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1294         label.setText("");
1295         label.setPadding(new Insets(7, 7, 7, 7));
1296         Rectangle r = new Rectangle(23, 23);
1297         label.setGraphic(r);
1298         label.setContentDisplay(ContentDisplay.LEFT);
1299         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1300         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1301     }
1302     
1303     @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1304         label.setText("For crying in the mud");
1305         label.setPadding(new Insets(7, 7, 7, 7));
1306         Rectangle r = new Rectangle(23, 23);
1307         label.setGraphic(r);
1308         label.setContentDisplay(ContentDisplay.LEFT);
1309         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1310         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1311     }
1312     
1313     @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1314         label.setText(null);
1315         label.setPadding(new Insets(7, 7, 7, 7));
1316         Rectangle r = new Rectangle(23, 23);
1317         label.setGraphic(r);
1318         label.setContentDisplay(ContentDisplay.CENTER);
1319         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1320         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1321     }
1322     
1323     @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1324         label.setText("");
1325         label.setPadding(new Insets(7, 7, 7, 7));
1326         Rectangle r = new Rectangle(23, 23);
1327         label.setGraphic(r);
1328         label.setContentDisplay(ContentDisplay.CENTER);
1329         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1330         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1331     }
1332     
1333     @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1334         label.setText("For crying in the mud");
1335         label.setPadding(new Insets(7, 7, 7, 7));
1336         Rectangle r = new Rectangle(23, 23);
1337         label.setGraphic(r);
1338         label.setContentDisplay(ContentDisplay.CENTER);
1339         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1340         assertEquals(14 + Math.max(23, lineHeight), label.prefHeight(-1), 0);
1341     }
1342     
1343     @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1344         label.setText(null);
1345         label.setPadding(new Insets(7, 7, 7, 7));
1346         Rectangle r = new Rectangle(23, 23);
1347         label.setGraphic(r);
1348         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1349         assertEquals(14 + 23, label.prefHeight(-1), 0);
1350     }
1351     
1352     @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1353         label.setText("");
1354         label.setPadding(new Insets(7, 7, 7, 7));
1355         Rectangle r = new Rectangle(23, 23);
1356         label.setGraphic(r);
1357         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1358         assertEquals(14 + 23, label.prefHeight(-1), 0);
1359     }
1360     
1361     @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1362         label.setText("For crying in the mud");
1363         label.setPadding(new Insets(7, 7, 7, 7));
1364         Rectangle r = new Rectangle(23, 23);
1365         label.setGraphic(r);
1366         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1367         assertEquals(14 + 23, label.prefHeight(-1), 0);
1368     }
1369     
1370     @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1371         label.setText(null);
1372         label.setPadding(new Insets(7, 7, 7, 7));
1373         Rectangle r = new Rectangle(23, 23);
1374         label.setGraphic(r);
1375         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1376         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1377         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1378     }
1379     
1380     @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1381         label.setText("");
1382         label.setPadding(new Insets(7, 7, 7, 7));
1383         Rectangle r = new Rectangle(23, 23);
1384         label.setGraphic(r);
1385         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1386         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1387         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1388     }
1389     
1390     @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computePrefHeight_ReturnsRightAnswer() {
1391         label.setText("For crying in the mud");
1392         label.setPadding(new Insets(7, 7, 7, 7));
1393         Rectangle r = new Rectangle(23, 23);
1394         label.setGraphic(r);
1395         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1396         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1397         assertEquals(14 + lineHeight, label.prefHeight(-1), 0);
1398     }
1399         
1400     /****************************************************************************
1401      *                                                                          *
1402      * Tests maxWidth                                                           *
1403      *                                                                          *
1404      ***************************************************************************/
1405 
1406     @Test public void whenTextIsNullAndNoGraphic_computeMaxWidth_ReturnsPadding() {
1407         label.setText(null);
1408         label.setPadding(new Insets(7, 7, 7, 7));
1409         assertEquals(14, label.maxWidth(-1), 0);
1410     }
1411     
1412     @Test public void whenTextIsEmptyAndNoGraphic_computeMaxWidth_ReturnsPadding() {
1413         label.setText("");
1414         label.setPadding(new Insets(7, 7, 7, 7));
1415         assertEquals(14, label.maxWidth(-1), 0);
1416     }
1417     
1418     @Test public void whenTextIsSetAndNoGraphic_computeMaxWidth_ReturnsTextWidthPlusPadding() {
1419         label.setText("Lollipop");
1420         label.setPadding(new Insets(7, 7, 7, 7));
1421         final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0);
1422         assertEquals(14 + textWidth, label.maxWidth(-1), 0);
1423     }
1424     
1425     @Test public void whenTextIsNullAndUnmanagedGraphic_computeMaxWidth_ReturnsPadding() {
1426         label.setText(null);
1427         Rectangle r = new Rectangle(0, 0, 50, 50);
1428         r.setManaged(false);
1429         label.setGraphic(r);
1430         label.setPadding(new Insets(7, 7, 7, 7));
1431         assertEquals(14, label.maxWidth(-1), 0);
1432     }
1433     
1434     @Test public void whenTextIsEmptyAndUnmanagedGraphic_computeMaxWidth_ReturnsPadding() {
1435         label.setText("");
1436         Rectangle r = new Rectangle(0, 0, 50, 50);
1437         r.setManaged(false);
1438         label.setGraphic(r);
1439         label.setPadding(new Insets(7, 7, 7, 7));
1440         assertEquals(14, label.maxWidth(-1), 0);
1441     }
1442     
1443     @Test public void whenTextIsSetAndUnmanagedGraphic_computeMaxWidth_ReturnsTextWidthPlusPadding() {
1444         label.setText("Lollipop");
1445         Rectangle r = new Rectangle(0, 0, 50, 50);
1446         r.setManaged(false);
1447         label.setGraphic(r);
1448         label.setPadding(new Insets(7, 7, 7, 7));
1449         final double textWidth = Utils.computeTextWidth(label.getFont(), "Lollipop", 0);
1450         assertEquals(14 + textWidth, label.maxWidth(-1), 0);
1451     }
1452     
1453     @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1454         label.setText(null);
1455         label.setGraphic(new Rectangle(0, 0, 20, 20));
1456         label.setGraphicTextGap(6.5);
1457         label.setContentDisplay(ContentDisplay.TOP);
1458         label.setPadding(new Insets(7, 7, 7, 7));
1459         assertEquals(14 + 20, label.maxWidth(-1), 0);
1460     }
1461     
1462     @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1463         label.setText("");
1464         label.setGraphic(new Rectangle(0, 0, 20, 20));
1465         label.setGraphicTextGap(6.5);
1466         label.setContentDisplay(ContentDisplay.TOP);
1467         label.setPadding(new Insets(7, 7, 7, 7));
1468         assertEquals(14 + 20, label.maxWidth(-1), 0);
1469     }
1470     
1471     @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1472         label.setText("Lollipop");
1473         label.setGraphic(new Rectangle(0, 0, 200, 20));
1474         label.setGraphicTextGap(6.5);
1475         label.setContentDisplay(ContentDisplay.TOP);
1476         label.setPadding(new Insets(7, 7, 7, 7));
1477         assertEquals(14 + 200, label.maxWidth(-1), 0);
1478     }
1479     
1480     @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplayAndTextIsWider_computeMaxWidth_ReturnsTextWidthPlusPadding() {
1481         label.setText("This is the right place");
1482         label.setGraphic(new Rectangle(0, 0, 20, 20));
1483         label.setGraphicTextGap(6.5);
1484         label.setContentDisplay(ContentDisplay.TOP);
1485         label.setPadding(new Insets(7, 7, 7, 7));
1486         final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0);
1487         assertEquals(14 + textWidth, label.maxWidth(-1), 0);
1488     }
1489 
1490     @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
1491         label.setText(null);
1492         label.setGraphic(new Rectangle(0, 0, 20, 20));
1493         label.setGraphicTextGap(6.5);
1494         label.setContentDisplay(ContentDisplay.RIGHT);
1495         label.setPadding(new Insets(7, 7, 7, 7));
1496         assertEquals(20 + 14, label.maxWidth(-1), 0);
1497     }
1498 
1499     @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
1500         label.setText("");
1501         label.setGraphic(new Rectangle(0, 0, 20, 20));
1502         label.setGraphicTextGap(6.5);
1503         label.setContentDisplay(ContentDisplay.RIGHT);
1504         label.setPadding(new Insets(7, 7, 7, 7));
1505         assertEquals(20 + 14, label.maxWidth(-1), 0);
1506     }
1507     
1508     @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computeMaxWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() {
1509         label.setText("Howdy");
1510         label.setGraphic(new Rectangle(0, 0, 20, 20));
1511         label.setGraphicTextGap(6.5);
1512         label.setContentDisplay(ContentDisplay.RIGHT);
1513         label.setPadding(new Insets(7, 7, 7, 7));
1514         final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0);
1515         assertEquals(14 + textWidth + 6.5 + 20, label.maxWidth(-1), 0);
1516     }
1517     
1518     @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1519         label.setText(null);
1520         label.setGraphic(new Rectangle(0, 0, 20, 20));
1521         label.setGraphicTextGap(6.5);
1522         label.setContentDisplay(ContentDisplay.BOTTOM);
1523         label.setPadding(new Insets(7, 7, 7, 7));
1524         assertEquals(14 + 20, label.maxWidth(-1), 0);
1525     }
1526     
1527     @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1528         label.setText(null);
1529         label.setGraphic(new Rectangle(0, 0, 20, 20));
1530         label.setGraphicTextGap(6.5);
1531         label.setContentDisplay(ContentDisplay.BOTTOM);
1532         label.setPadding(new Insets(7, 7, 7, 7));
1533         assertEquals(14 + 20, label.maxWidth(-1), 0);
1534     }
1535     
1536     @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1537         label.setText("Lollipop");
1538         label.setGraphic(new Rectangle(0, 0, 200, 20));
1539         label.setGraphicTextGap(6.5);
1540         label.setContentDisplay(ContentDisplay.BOTTOM);
1541         label.setPadding(new Insets(7, 7, 7, 7));
1542         assertEquals(14 + 200, label.maxWidth(-1), 0);
1543     }
1544     
1545     @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplayAndTextIsWider_computeMaxWidth_ReturnsTextWidthPlusPadding() {
1546         label.setText("This is the right place");
1547         label.setGraphic(new Rectangle(0, 0, 20, 20));
1548         label.setGraphicTextGap(6.5);
1549         label.setContentDisplay(ContentDisplay.BOTTOM);
1550         label.setPadding(new Insets(7, 7, 7, 7));
1551         final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0);
1552         assertEquals(14 + textWidth, label.maxWidth(-1), 0);
1553     }
1554 
1555     @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
1556         label.setText(null);
1557         label.setGraphic(new Rectangle(0, 0, 20, 20));
1558         label.setGraphicTextGap(6.5);
1559         label.setContentDisplay(ContentDisplay.LEFT);
1560         label.setPadding(new Insets(7, 7, 7, 7));
1561         assertEquals(20 + 14, label.maxWidth(-1), 0);
1562     }
1563 
1564     @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computeMaxWidth_ReturnsGraphicPlusPaddingNotIncludingGap() {
1565         label.setText("");
1566         label.setGraphic(new Rectangle(0, 0, 20, 20));
1567         label.setGraphicTextGap(6.5);
1568         label.setContentDisplay(ContentDisplay.LEFT);
1569         label.setPadding(new Insets(7, 7, 7, 7));
1570         assertEquals(20 + 14, label.maxWidth(-1), 0);
1571     }
1572     
1573     @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computeMaxWidth_ReturnsTextWidthPlusGraphicWidthPlusGapPlusPadding() {
1574         label.setText("Howdy");
1575         label.setGraphic(new Rectangle(0, 0, 20, 20));
1576         label.setGraphicTextGap(6.5);
1577         label.setContentDisplay(ContentDisplay.LEFT);
1578         label.setPadding(new Insets(7, 7, 7, 7));
1579         final double textWidth = Utils.computeTextWidth(label.getFont(), "Howdy", 0);
1580         assertEquals(14 + textWidth + 6.5 + 20, label.maxWidth(-1), 0);
1581     }
1582     
1583     @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1584         label.setText(null);
1585         label.setGraphic(new Rectangle(0, 0, 20, 20));
1586         label.setGraphicTextGap(6.5);
1587         label.setContentDisplay(ContentDisplay.CENTER);
1588         label.setPadding(new Insets(7, 7, 7, 7));
1589         assertEquals(14 + 20, label.maxWidth(-1), 0);
1590     }
1591     
1592     @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1593         label.setText("");
1594         label.setGraphic(new Rectangle(0, 0, 20, 20));
1595         label.setGraphicTextGap(6.5);
1596         label.setContentDisplay(ContentDisplay.CENTER);
1597         label.setPadding(new Insets(7, 7, 7, 7));
1598         assertEquals(14 + 20, label.maxWidth(-1), 0);
1599     }
1600     
1601     @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1602         label.setText("Lollipop");
1603         label.setGraphic(new Rectangle(0, 0, 200, 20));
1604         label.setGraphicTextGap(6.5);
1605         label.setContentDisplay(ContentDisplay.CENTER);
1606         label.setPadding(new Insets(7, 7, 7, 7));
1607         assertEquals(14 + 200, label.maxWidth(-1), 0);
1608     }
1609     
1610     @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplayAndTextIsWider_computeMaxWidth_ReturnsTextWidthPlusPadding() {
1611         label.setText("This is the right place");
1612         label.setGraphic(new Rectangle(0, 0, 20, 20));
1613         label.setGraphicTextGap(6.5);
1614         label.setContentDisplay(ContentDisplay.CENTER);
1615         label.setPadding(new Insets(7, 7, 7, 7));
1616         final double textWidth = Utils.computeTextWidth(label.getFont(), "This is the right place", 0);
1617         assertEquals(14 + textWidth, label.maxWidth(-1), 0);
1618     }
1619 
1620     @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1621         label.setText(null);
1622         label.setGraphic(new Rectangle(0, 0, 20, 20));
1623         label.setGraphicTextGap(6.5);
1624         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1625         label.setPadding(new Insets(7, 7, 7, 7));
1626         assertEquals(14 + 20, label.maxWidth(-1), 0);
1627     }
1628     
1629     @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1630         label.setText("");
1631         label.setGraphic(new Rectangle(0, 0, 20, 20));
1632         label.setGraphicTextGap(6.5);
1633         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1634         label.setPadding(new Insets(7, 7, 7, 7));
1635         assertEquals(14 + 20, label.maxWidth(-1), 0);
1636     }
1637     
1638     @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndGraphicIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1639         label.setText("Howdy");
1640         label.setGraphic(new Rectangle(0, 0, 200, 20));
1641         label.setGraphicTextGap(6.5);
1642         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1643         label.setPadding(new Insets(7, 7, 7, 7));
1644         assertEquals(14 + 200, label.maxWidth(-1), 0);
1645     }
1646     
1647     @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplayAndTextIsWider_computeMaxWidth_ReturnsGraphicWidthPlusPadding() {
1648         label.setText("Tally ho, off to the races");
1649         label.setGraphic(new Rectangle(0, 0, 20, 20));
1650         label.setGraphicTextGap(6.5);
1651         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1652         label.setPadding(new Insets(7, 7, 7, 7));
1653         assertEquals(14 + 20, label.maxWidth(-1), 0);
1654     }
1655     
1656     // TODO should this include the gap??
1657     @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxWidth_ReturnsPadding() {
1658         label.setText(null);
1659         label.setGraphic(new Rectangle(0, 0, 20, 20));
1660         label.setGraphicTextGap(6.5);
1661         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1662         label.setPadding(new Insets(7, 7, 7, 7));
1663         assertEquals(14, label.maxWidth(-1), 0);
1664     }
1665     
1666     @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxWidth_ReturnsPadding() {
1667         label.setText("");
1668         label.setGraphic(new Rectangle(0, 0, 20, 20));
1669         label.setGraphicTextGap(6.5);
1670         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1671         label.setPadding(new Insets(7, 7, 7, 7));
1672         assertEquals(14, label.maxWidth(-1), 0);
1673     }
1674     
1675     // TODO should this include the gap? I guess not, otherwise our gap would have to default to 0
1676     @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxWidth_ReturnsTextWidthPlusPadding() {
1677         label.setText("Yippee Skippee");
1678         label.setGraphic(new Rectangle(0, 0, 20, 20));
1679         label.setGraphicTextGap(6.5);
1680         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1681         label.setPadding(new Insets(7, 7, 7, 7));
1682         final double textWidth = Utils.computeTextWidth(label.getFont(), "Yippee Skippee", 0);
1683         assertEquals(14 + textWidth, label.maxWidth(-1), 0);
1684     }
1685     
1686     /****************************************************************************
1687      *                                                                          *
1688      * Tests for maxHeight.                                                     *
1689      *                                                                          *
1690      ***************************************************************************/
1691 
1692     @Test public void whenTextIsNullAndNoGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() {
1693         label.setText(null);
1694         label.setPadding(new Insets(7, 7, 7, 7));
1695         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1696         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1697     }
1698     
1699     @Test public void whenTextIsEmptyAndNoGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() {
1700         label.setText("");
1701         label.setPadding(new Insets(7, 7, 7, 7));
1702         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1703         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1704     }
1705     
1706     @Test public void whenTextIsSetAndNoGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() {
1707         label.setText("Howdy Pardner");
1708         label.setPadding(new Insets(7, 7, 7, 7));
1709         assertTrue(label.maxHeight(-1) >= 0);
1710         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1711         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1712     }
1713     
1714     @Test public void whenTextIsNullAndUnmanagedGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() {
1715         label.setText(null);
1716         label.setPadding(new Insets(7, 7, 7, 7));
1717         Rectangle r = new Rectangle(23, 500);
1718         r.setManaged(false);
1719         label.setGraphic(r);
1720         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1721         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1722     }
1723     
1724     @Test public void whenTextIsEmptyAndUnmanagedGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() {
1725         label.setText("");
1726         label.setPadding(new Insets(7, 7, 7, 7));
1727         Rectangle r = new Rectangle(23, 500);
1728         r.setManaged(false);
1729         label.setGraphic(r);
1730         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1731         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1732     }
1733     
1734     @Test public void whenTextIsSetAndUnmanagedGraphic_computeMaxHeight_ReturnsSingleLineStringHeightPlusPadding() {
1735         label.setText("Howdy Pardner");
1736         label.setPadding(new Insets(7, 7, 7, 7));
1737         Rectangle r = new Rectangle(23, 500);
1738         r.setManaged(false);
1739         label.setGraphic(r);
1740         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1741         assertTrue(label.maxHeight(-1) >= 0);
1742         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1743     }
1744     
1745     @Test public void whenTextIsNullAndGraphicIsSetWithTOPContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1746         label.setText(null);
1747         label.setPadding(new Insets(7, 7, 7, 7));
1748         Rectangle r = new Rectangle(23, 23);
1749         label.setGraphicTextGap(2);
1750         label.setGraphic(r);
1751         label.setContentDisplay(ContentDisplay.TOP);
1752         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1753         assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0);
1754     }
1755     
1756     @Test public void whenTextIsEmptyAndGraphicIsSetWithTOPContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1757         label.setText("");
1758         label.setPadding(new Insets(7, 7, 7, 7));
1759         Rectangle r = new Rectangle(23, 23);
1760         label.setGraphicTextGap(2);
1761         label.setGraphic(r);
1762         label.setContentDisplay(ContentDisplay.TOP);
1763         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1764         assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0);
1765     }
1766     
1767     @Test public void whenTextIsSetAndGraphicIsSetWithTOPContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1768         label.setText("For crying in the mud");
1769         label.setPadding(new Insets(7, 7, 7, 7));
1770         Rectangle r = new Rectangle(23, 23);
1771         label.setGraphic(r);
1772         label.setGraphicTextGap(2);
1773         label.setContentDisplay(ContentDisplay.TOP);
1774         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1775         assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0);
1776     }
1777     
1778     @Test public void whenTextIsNullAndGraphicIsSetWithRIGHTContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1779         label.setText(null);
1780         label.setPadding(new Insets(7, 7, 7, 7));
1781         Rectangle r = new Rectangle(23, 23);
1782         label.setGraphic(r);
1783         label.setContentDisplay(ContentDisplay.RIGHT);
1784         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1785         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1786     }
1787     
1788     @Test public void whenTextIsEmptyAndGraphicIsSetWithRIGHTContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1789         label.setText("");
1790         label.setPadding(new Insets(7, 7, 7, 7));
1791         Rectangle r = new Rectangle(23, 23);
1792         label.setGraphic(r);
1793         label.setContentDisplay(ContentDisplay.RIGHT);
1794         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1795         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1796     }
1797     
1798     @Test public void whenTextIsSetAndGraphicIsSetWithRIGHTContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1799         label.setText("For crying in the mud");
1800         label.setPadding(new Insets(7, 7, 7, 7));
1801         Rectangle r = new Rectangle(23, 23);
1802         label.setGraphic(r);
1803         label.setContentDisplay(ContentDisplay.RIGHT);
1804         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1805         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1806     }
1807     
1808     @Test public void whenTextIsNullAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1809         label.setText(null);
1810         label.setPadding(new Insets(7, 7, 7, 7));
1811         Rectangle r = new Rectangle(23, 23);
1812         label.setGraphicTextGap(2);
1813         label.setGraphic(r);
1814         label.setContentDisplay(ContentDisplay.BOTTOM);
1815         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1816         assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0);
1817     }
1818     
1819     @Test public void whenTextIsEmptyAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1820         label.setText("");
1821         label.setPadding(new Insets(7, 7, 7, 7));
1822         Rectangle r = new Rectangle(23, 23);
1823         label.setGraphicTextGap(2);
1824         label.setGraphic(r);
1825         label.setContentDisplay(ContentDisplay.BOTTOM);
1826         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1827         assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0);
1828     }
1829     
1830     @Test public void whenTextIsSetAndGraphicIsSetWithBOTTOMContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1831         label.setText("For crying in the mud");
1832         label.setPadding(new Insets(7, 7, 7, 7));
1833         Rectangle r = new Rectangle(23, 23);
1834         label.setGraphic(r);
1835         label.setGraphicTextGap(2);
1836         label.setContentDisplay(ContentDisplay.BOTTOM);
1837         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1838         assertEquals(14 + 23 + lineHeight + 2, label.maxHeight(-1), 0);
1839     }
1840     
1841     @Test public void whenTextIsNullAndGraphicIsSetWithLEFTContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1842         label.setText(null);
1843         label.setPadding(new Insets(7, 7, 7, 7));
1844         Rectangle r = new Rectangle(23, 23);
1845         label.setGraphic(r);
1846         label.setContentDisplay(ContentDisplay.LEFT);
1847         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1848         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1849     }
1850     
1851     @Test public void whenTextIsEmptyAndGraphicIsSetWithLEFTContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1852         label.setText("");
1853         label.setPadding(new Insets(7, 7, 7, 7));
1854         Rectangle r = new Rectangle(23, 23);
1855         label.setGraphic(r);
1856         label.setContentDisplay(ContentDisplay.LEFT);
1857         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1858         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1859     }
1860     
1861     @Test public void whenTextIsSetAndGraphicIsSetWithLEFTContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1862         label.setText("For crying in the mud");
1863         label.setPadding(new Insets(7, 7, 7, 7));
1864         Rectangle r = new Rectangle(23, 23);
1865         label.setGraphic(r);
1866         label.setContentDisplay(ContentDisplay.LEFT);
1867         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1868         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1869     }
1870     
1871     @Test public void whenTextIsNullAndGraphicIsSetWithCENTERContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1872         label.setText(null);
1873         label.setPadding(new Insets(7, 7, 7, 7));
1874         Rectangle r = new Rectangle(23, 23);
1875         label.setGraphic(r);
1876         label.setContentDisplay(ContentDisplay.CENTER);
1877         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1878         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1879     }
1880     
1881     @Test public void whenTextIsEmptyAndGraphicIsSetWithCENTERContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1882         label.setText("");
1883         label.setPadding(new Insets(7, 7, 7, 7));
1884         Rectangle r = new Rectangle(23, 23);
1885         label.setGraphic(r);
1886         label.setContentDisplay(ContentDisplay.CENTER);
1887         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1888         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1889     }
1890     
1891     @Test public void whenTextIsSetAndGraphicIsSetWithCENTERContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1892         label.setText("For crying in the mud");
1893         label.setPadding(new Insets(7, 7, 7, 7));
1894         Rectangle r = new Rectangle(23, 23);
1895         label.setGraphic(r);
1896         label.setContentDisplay(ContentDisplay.CENTER);
1897         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1898         assertEquals(14 + Math.max(23, lineHeight), label.maxHeight(-1), 0);
1899     }
1900     
1901     @Test public void whenTextIsNullAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1902         label.setText(null);
1903         label.setPadding(new Insets(7, 7, 7, 7));
1904         Rectangle r = new Rectangle(23, 23);
1905         label.setGraphic(r);
1906         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1907         assertEquals(14 + 23, label.maxHeight(-1), 0);
1908     }
1909     
1910     @Test public void whenTextIsEmptyAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1911         label.setText("");
1912         label.setPadding(new Insets(7, 7, 7, 7));
1913         Rectangle r = new Rectangle(23, 23);
1914         label.setGraphic(r);
1915         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1916         assertEquals(14 + 23, label.maxHeight(-1), 0);
1917     }
1918     
1919     @Test public void whenTextIsSetAndGraphicIsSetWithGRAPHIC_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1920         label.setText("For crying in the mud");
1921         label.setPadding(new Insets(7, 7, 7, 7));
1922         Rectangle r = new Rectangle(23, 23);
1923         label.setGraphic(r);
1924         label.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
1925         assertEquals(14 + 23, label.maxHeight(-1), 0);
1926     }
1927     
1928     @Test public void whenTextIsNullAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1929         label.setText(null);
1930         label.setPadding(new Insets(7, 7, 7, 7));
1931         Rectangle r = new Rectangle(23, 23);
1932         label.setGraphic(r);
1933         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1934         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1935         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1936     }
1937     
1938     @Test public void whenTextIsEmptyAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1939         label.setText("");
1940         label.setPadding(new Insets(7, 7, 7, 7));
1941         Rectangle r = new Rectangle(23, 23);
1942         label.setGraphic(r);
1943         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1944         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1945         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1946     }
1947     
1948     @Test public void whenTextIsSetAndGraphicIsSetWithTEXT_ONLYContentDisplay_computeMaxHeight_ReturnsRightAnswer() {
1949         label.setText("For crying in the mud");
1950         label.setPadding(new Insets(7, 7, 7, 7));
1951         Rectangle r = new Rectangle(23, 23);
1952         label.setGraphic(r);
1953         label.setContentDisplay(ContentDisplay.TEXT_ONLY);
1954         final double lineHeight = Utils.computeTextHeight(label.getFont(), " ", 0, text.getBoundsType());
1955         assertEquals(14 + lineHeight, label.maxHeight(-1), 0);
1956     }
1957 
1958     @Test public void maxWidthTracksPreferred() {
1959         label.setPrefWidth(500);
1960         assertEquals(500, label.maxWidth(-1), 0);
1961     }
1962 
1963     @Test public void maxHeightTracksPreferred() {
1964         label.setPrefHeight(500);
1965         assertEquals(500, label.maxHeight(-1), 0);
1966     }
1967     
1968     /****************************************************************************
1969      *                                                                          *
1970      * Tests for updateDisplayedText                                            *
1971      *                                                                          *
1972      ***************************************************************************/
1973 
1974     // tests for updateDisplayedText (not even sure how to test it exactly yet)
1975     
1976     
1977     public static final class LabelSkinMock extends LabelSkin {
1978         boolean propertyChanged = false;
1979         int propertyChangeCount = 0;
1980         public LabelSkinMock(Label label) {
1981             super(label);
1982         }
1983         
1984         @Override protected void handleControlPropertyChanged(String p) {
1985             super.handleControlPropertyChanged(p);
1986             propertyChanged = true;
1987             propertyChangeCount++;
1988         }
1989     }
1990 }