modules/controls/src/test/java/javafx/scene/control/skin/LabelSkinTest.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization

*** 21,35 **** * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package com.sun.javafx.scene.control.skin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; import javafx.scene.control.OverrunStyle; --- 21,38 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package javafx.scene.control.skin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + + import com.sun.javafx.scene.control.skin.Utils; + import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; import javafx.scene.control.OverrunStyle;
*** 40,50 **** import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; import org.junit.Before; - import org.junit.Ignore; import org.junit.Test; /** * Need to test: * - String truncation works correctly --- 43,52 ----
*** 72,147 **** --- 74,163 ---- * Tests for change notification * * * ***************************************************************************/ @Test public void sizeChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.widthProperty()); + skin.addWatchedProperty(label.heightProperty()); assertFalse(skin.propertyChanged); // sanity check label.resize(500, label.getHeight()); assertTrue(skin.propertyChanged); assertEquals(1, skin.propertyChangeCount); // sanity check label.resize(label.getWidth(), label.prefHeight(label.getWidth())); assertEquals(2, skin.propertyChangeCount); // sanity check } @Test public void textFillChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.textFillProperty()); label.setTextFill(Color.PURPLE); assertTrue(skin.propertyChanged); } @Test public void fontChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.fontProperty()); final Font f = Font.font("Arial", 64); label.setFont(f); assertTrue(skin.propertyChanged); } @Test public void graphicChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.graphicProperty()); label.setGraphic(new Rectangle()); assertTrue(skin.propertyChanged); } @Test public void contentDisplayChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.contentDisplayProperty()); label.setContentDisplay(ContentDisplay.TEXT_ONLY); assertTrue(skin.propertyChanged); } @Test public void graphicTextGapChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.graphicTextGapProperty()); label.setGraphicTextGap(60.34); assertTrue(skin.propertyChanged); } @Test public void hposChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.alignmentProperty()); label.setAlignment(Pos.CENTER_RIGHT); label.setAlignment(Pos.CENTER_RIGHT); assertTrue(skin.propertyChanged); } @Test public void vposChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.alignmentProperty()); label.setAlignment(Pos.TOP_CENTER); assertTrue(skin.propertyChanged); } @Test public void textChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.textProperty()); label.setText("Bust my buffers!"); assertTrue(skin.propertyChanged); } @Test public void textAlignmentChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.textAlignmentProperty()); label.setTextAlignment(TextAlignment.JUSTIFY); assertTrue(skin.propertyChanged); } @Test public void textOverrunChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.textOverrunProperty()); label.setTextOverrun(OverrunStyle.CENTER_WORD_ELLIPSIS); assertTrue(skin.propertyChanged); } @Test public void wrapTextChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.wrapTextProperty()); label.setWrapText(true); assertTrue(skin.propertyChanged); } @Test public void underlineChangesOnLabelShouldInvoke_handleControlPropertyChanged() { + skin.addWatchedProperty(label.underlineProperty()); label.setUnderline(true); assertTrue(skin.propertyChanged); } @Test public void uninterestingChangesOnLabelShouldNotInvoke_handleControlPropertyChanged() {
*** 1975,1990 **** public static final class LabelSkinMock extends LabelSkin { boolean propertyChanged = false; int propertyChangeCount = 0; public LabelSkinMock(Label label) { super(label); } ! @Override protected void handleControlPropertyChanged(String p) { ! super.handleControlPropertyChanged(p); propertyChanged = true; propertyChangeCount++; } } } --- 1991,2008 ---- public static final class LabelSkinMock extends LabelSkin { boolean propertyChanged = false; int propertyChangeCount = 0; + public LabelSkinMock(Label label) { super(label); } ! public void addWatchedProperty(ObservableValue<?> p) { ! p.addListener(o -> { propertyChanged = true; propertyChangeCount++; + }); } } }