Styling: TestFlatStyleableValue:

- check whether all keys (returned by `getStyleableInfos()`) are tested
- added tests for missing keys
- cache `ui.applyStyle(...)` methods
This commit is contained in:
Karl Tauber
2025-11-27 22:33:53 +01:00
parent 2b587d4dba
commit 855c41bf4a
5 changed files with 218 additions and 26 deletions

View File

@@ -21,7 +21,6 @@ import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
import java.util.Map;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
@@ -40,23 +39,6 @@ public class FlatMenuBarBorder
{ {
@Styleable protected Color borderColor = UIManager.getColor( "MenuBar.borderColor" ); @Styleable protected Color borderColor = UIManager.getColor( "MenuBar.borderColor" );
/** @since 2 */
@Override
public Object applyStyleProperty( String key, Object value ) {
return FlatStylingSupport.applyToAnnotatedObject( this, key, value );
}
@Override
public Map<String, Class<?>> getStyleableInfos() {
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
}
/** @since 2.5 */
@Override
public Object getStyleableValue( String key ) {
return FlatStylingSupport.getAnnotatedStyleableValue( this, key );
}
@Override @Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
if( !showBottomSeparator( c ) ) if( !showBottomSeparator( c ) )

View File

@@ -149,7 +149,15 @@ public class TestFlatStyleableInfo
@Test @Test
void checkBox() { void checkBox() {
checkBox( new JCheckBox() ); checkBox( new JCheckBox() );
}
@Test
void checkBox2() {
checkBox( new JCheckBox( new CustomIcon() ) ); checkBox( new JCheckBox( new CustomIcon() ) );
}
@Test
void checkBox3() {
checkBox( new JCheckBox( new CustomCheckBoxIcon() ) ); checkBox( new JCheckBox( new CustomCheckBoxIcon() ) );
} }
@@ -507,7 +515,15 @@ public class TestFlatStyleableInfo
@Test @Test
void radioButton() { void radioButton() {
radioButton( new JRadioButton() ); radioButton( new JRadioButton() );
}
@Test
void radioButton2() {
radioButton( new JRadioButton( new CustomIcon() ) ); radioButton( new JRadioButton( new CustomIcon() ) );
}
@Test
void radioButton3() {
radioButton( new JRadioButton( new CustomRadioButtonIcon() ) ); radioButton( new JRadioButton( new CustomRadioButtonIcon() ) );
} }

View File

@@ -26,14 +26,21 @@ import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.swing.*; import javax.swing.*;
import javax.swing.table.JTableHeader; import javax.swing.table.JTableHeader;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;
import com.formdev.flatlaf.icons.*; import com.formdev.flatlaf.icons.*;
import com.formdev.flatlaf.ui.FlatInternalFrameUI.FlatInternalFrameBorder; import com.formdev.flatlaf.ui.FlatInternalFrameUI.FlatInternalFrameBorder;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject; import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableObject;
@@ -58,65 +65,98 @@ public class TestFlatStyleableValue
TestUtils.cleanup(); TestUtils.cleanup();
} }
private Map<String, Class<?>> expectedStyleableInfos;
private final Set<String> testedKeys = new HashSet<>();
@BeforeEach
void beforeTest() {
expectedStyleableInfos = null;
testedKeys.clear();
}
@AfterEach
void afterTest() {
if( expectedStyleableInfos == null )
throw new AssertionFailedError( "missing 'expectedStyleableInfos'" );
TestUtils.assertSetEquals( expectedStyleableInfos.keySet(), testedKeys, "untested keys" );
}
private void testString( JComponent c, StyleableUI ui, String key, String value ) { private void testString( JComponent c, StyleableUI ui, String key, String value ) {
applyStyle( c, ui, String.format( "%s: %s", key, value ) ); applyStyle( c, ui, String.format( "%s: %s", key, value ) );
assertEquals( value, ui.getStyleableValue( c, key ) ); assertEquals( value, ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testBoolean( JComponent c, StyleableUI ui, String key, boolean value ) { private void testBoolean( JComponent c, StyleableUI ui, String key, boolean value ) {
applyStyle( c, ui, String.format( "%s: %s", key, value ) ); applyStyle( c, ui, String.format( "%s: %s", key, value ) );
assertEquals( value, ui.getStyleableValue( c, key ) ); assertEquals( value, ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testInteger( JComponent c, StyleableUI ui, String key, int value ) { private void testInteger( JComponent c, StyleableUI ui, String key, int value ) {
applyStyle( c, ui, String.format( "%s: %d", key, value ) ); applyStyle( c, ui, String.format( "%s: %d", key, value ) );
assertEquals( value, ui.getStyleableValue( c, key ) ); assertEquals( value, ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testFloat( JComponent c, StyleableUI ui, String key, float value ) { private void testFloat( JComponent c, StyleableUI ui, String key, float value ) {
applyStyle( c, ui, String.format( Locale.ENGLISH, "%s: %f", key, value ) ); applyStyle( c, ui, String.format( Locale.ENGLISH, "%s: %f", key, value ) );
assertEquals( value, ui.getStyleableValue( c, key ) ); assertEquals( value, ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testColor( JComponent c, StyleableUI ui, String key, int rgb ) { private void testColor( JComponent c, StyleableUI ui, String key, int rgb ) {
applyStyle( c, ui, String.format( "%s: #%06x", key, rgb ) ); applyStyle( c, ui, String.format( "%s: #%06x", key, rgb ) );
assertEquals( new Color( rgb ), ui.getStyleableValue( c, key ) ); assertEquals( new Color( rgb ), ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testInsets( JComponent c, StyleableUI ui, String key, int top, int left, int bottom, int right ) { private void testInsets( JComponent c, StyleableUI ui, String key, int top, int left, int bottom, int right ) {
applyStyle( c,ui, String.format( "%s: %d,%d,%d,%d", key, top, left, bottom, right ) ); applyStyle( c,ui, String.format( "%s: %d,%d,%d,%d", key, top, left, bottom, right ) );
assertEquals( new Insets( top, left, bottom, right ), ui.getStyleableValue( c, key ) ); assertEquals( new Insets( top, left, bottom, right ), ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testDimension( JComponent c, StyleableUI ui, String key, int width, int height ) { private void testDimension( JComponent c, StyleableUI ui, String key, int width, int height ) {
applyStyle( c,ui, String.format( "%s: %d,%d", key, width, height ) ); applyStyle( c,ui, String.format( "%s: %d,%d", key, width, height ) );
assertEquals( new Dimension( width, height ), ui.getStyleableValue( c, key ) ); assertEquals( new Dimension( width, height ), ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testFont( JComponent c, StyleableUI ui, String key, String style, Font expectedFont ) { private void testFont( JComponent c, StyleableUI ui, String key, String style, Font expectedFont ) {
applyStyle( c,ui, String.format( "%s: %s", key, style ) ); applyStyle( c,ui, String.format( "%s: %s", key, style ) );
assertEquals( expectedFont, ui.getStyleableValue( c, key ) ); assertEquals( expectedFont, ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void testIcon( JComponent c, StyleableUI ui, String key, String classname, Icon expectedIcon ) { private void testIcon( JComponent c, StyleableUI ui, String key, String classname, Icon expectedIcon ) {
applyStyle( c,ui, String.format( "%s: %s", key, classname ) ); applyStyle( c,ui, String.format( "%s: %s", key, classname ) );
assertEquals( expectedIcon, ui.getStyleableValue( c, key ) ); assertEquals( expectedIcon, ui.getStyleableValue( c, key ) );
testedKeys.add( key );
} }
private void applyStyle( JComponent c, StyleableUI ui, String style ) { private void applyStyle( JComponent c, StyleableUI ui, String style ) {
Method m = findMethod( ui, "applyStyle", Object.class ); Class<?> uiClass = ui.getClass();
Class<?> compClass = c.getClass();
CacheKey key = new CacheKey( uiClass, compClass );
Method m = methodCache.get( key );
if( m == null ) if( m == null )
m = findMethod( ui, "applyStyle", c.getClass(), Object.class ); m = findMethod( uiClass, "applyStyle", Object.class );
if( m == null ) if( m == null )
m = findMethod( ui, "applyStyle", c.getClass().getSuperclass(), Object.class ); m = findMethod( uiClass, "applyStyle", compClass, Object.class );
if( m == null ) if( m == null )
m = findMethod( ui, "applyStyle", c.getClass().getSuperclass().getSuperclass(), Object.class ); m = findMethod( uiClass, "applyStyle", compClass.getSuperclass(), Object.class );
if( m == null )
m = findMethod( uiClass, "applyStyle", compClass.getSuperclass().getSuperclass(), Object.class );
if( m == null ) { if( m == null ) {
Assertions.fail( "missing method '" + ui.getClass() Assertions.fail( "missing method '" + uiClass
+ ".applyStyle( Object )' or 'applyStyle( " + c.getClass().getSimpleName() + ".applyStyle( Object )' or 'applyStyle( " + compClass.getSimpleName()
+ ", Object )'" ); + ", Object )'" );
return; return;
} }
methodCache.put( key, m );
try { try {
m.setAccessible( true ); m.setAccessible( true );
@@ -129,8 +169,8 @@ public class TestFlatStyleableValue
} }
} }
private Method findMethod( StyleableUI ui, String name, Class<?>... parameterTypes ) { private Method findMethod( Class<?> uiClass, String name, Class<?>... parameterTypes ) {
for( Class<?> cls = ui.getClass(); cls != null; cls = cls.getSuperclass() ) { for( Class<?> cls = uiClass; cls != null; cls = cls.getSuperclass() ) {
try { try {
return cls.getDeclaredMethod( name, parameterTypes ); return cls.getDeclaredMethod( name, parameterTypes );
} catch( Exception ex ) { } catch( Exception ex ) {
@@ -140,6 +180,28 @@ public class TestFlatStyleableValue
return null; return null;
} }
private static class CacheKey {
private final Class<?> uiClass;
private final Class<?> compClass;
CacheKey( Class<?> uiClass, Class<?> compClass ) {
this.uiClass = uiClass;
this.compClass = compClass;
}
@Override
public boolean equals( Object obj ) {
return uiClass == ((CacheKey)obj).uiClass && compClass == ((CacheKey)obj).compClass;
}
@Override
public int hashCode() {
return uiClass.hashCode() * 13 + compClass.hashCode();
}
}
private final Map<CacheKey, Method> methodCache = new HashMap<>();
private void testValue( Object obj, String key, Object value ) { private void testValue( Object obj, String key, Object value ) {
assertInstanceOf( StyleableObject.class, obj ); assertInstanceOf( StyleableObject.class, obj );
@@ -148,6 +210,8 @@ public class TestFlatStyleableValue
Object actualValue = sobj.getStyleableValue( key ); Object actualValue = sobj.getStyleableValue( key );
assertEquals( value, actualValue ); assertEquals( value, actualValue );
testedKeys.add( key );
} }
//---- components --------------------------------------------------------- //---- components ---------------------------------------------------------
@@ -156,6 +220,7 @@ public class TestFlatStyleableValue
void button() { void button() {
JButton c = new JButton(); JButton c = new JButton();
FlatButtonUI ui = (FlatButtonUI) c.getUI(); FlatButtonUI ui = (FlatButtonUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
button( c, ui ); button( c, ui );
@@ -231,12 +296,21 @@ public class TestFlatStyleableValue
@Test @Test
void checkBox() { void checkBox() {
checkBox( new JCheckBox() ); checkBox( new JCheckBox() );
}
@Test
void checkBox2() {
checkBox( new JCheckBox( new CustomCheckBoxIcon() ) ); checkBox( new JCheckBox( new CustomCheckBoxIcon() ) );
}
@Test
void checkBox3() {
checkBox( new JCheckBox( new CustomIcon() ) ); checkBox( new JCheckBox( new CustomIcon() ) );
} }
private void checkBox( JCheckBox c ) { private void checkBox( JCheckBox c ) {
FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI(); FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
// FlatCheckBoxUI extends FlatRadioButtonUI // FlatCheckBoxUI extends FlatRadioButtonUI
radioButton( ui, c ); radioButton( ui, c );
@@ -250,6 +324,7 @@ public class TestFlatStyleableValue
void comboBox() { void comboBox() {
JComboBox<Object> c = new JComboBox<>(); JComboBox<Object> c = new JComboBox<>();
FlatComboBoxUI ui = (FlatComboBoxUI) c.getUI(); FlatComboBoxUI ui = (FlatComboBoxUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInsets( c, ui, "padding", 1,2,3,4 ); testInsets( c, ui, "padding", 1,2,3,4 );
@@ -287,6 +362,7 @@ public class TestFlatStyleableValue
void editorPane() { void editorPane() {
JEditorPane c = new JEditorPane(); JEditorPane c = new JEditorPane();
FlatEditorPaneUI ui = (FlatEditorPaneUI) c.getUI(); FlatEditorPaneUI ui = (FlatEditorPaneUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "minimumWidth", 123 ); testInteger( c, ui, "minimumWidth", 123 );
testColor( c, ui, "disabledBackground", 0x123456 ); testColor( c, ui, "disabledBackground", 0x123456 );
@@ -298,6 +374,7 @@ public class TestFlatStyleableValue
void formattedTextField() { void formattedTextField() {
JFormattedTextField c = new JFormattedTextField(); JFormattedTextField c = new JFormattedTextField();
FlatFormattedTextFieldUI ui = (FlatFormattedTextFieldUI) c.getUI(); FlatFormattedTextFieldUI ui = (FlatFormattedTextFieldUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
// FlatFormattedTextFieldUI extends FlatTextFieldUI // FlatFormattedTextFieldUI extends FlatTextFieldUI
textField( c, ui ); textField( c, ui );
@@ -307,6 +384,7 @@ public class TestFlatStyleableValue
void internalFrame() { void internalFrame() {
JInternalFrame c = new JInternalFrame(); JInternalFrame c = new JInternalFrame();
FlatInternalFrameUI ui = (FlatInternalFrameUI) c.getUI(); FlatInternalFrameUI ui = (FlatInternalFrameUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testColor( c, ui, "activeBorderColor", 0x123456 ); testColor( c, ui, "activeBorderColor", 0x123456 );
testColor( c, ui, "inactiveBorderColor", 0x123456 ); testColor( c, ui, "inactiveBorderColor", 0x123456 );
@@ -326,6 +404,7 @@ public class TestFlatStyleableValue
void label() { void label() {
JLabel c = new JLabel(); JLabel c = new JLabel();
FlatLabelUI ui = (FlatLabelUI) c.getUI(); FlatLabelUI ui = (FlatLabelUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testColor( c, ui, "disabledForeground", 0x123456 ); testColor( c, ui, "disabledForeground", 0x123456 );
testInteger( c, ui, "arc", 123 ); testInteger( c, ui, "arc", 123 );
@@ -335,6 +414,7 @@ public class TestFlatStyleableValue
void list() { void list() {
JList<Object> c = new JList<>(); JList<Object> c = new JList<>();
FlatListUI ui = (FlatListUI) c.getUI(); FlatListUI ui = (FlatListUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testColor( c, ui, "selectionBackground", 0x123456 ); testColor( c, ui, "selectionBackground", 0x123456 );
testColor( c, ui, "selectionForeground", 0x123456 ); testColor( c, ui, "selectionForeground", 0x123456 );
@@ -354,8 +434,12 @@ public class TestFlatStyleableValue
void menuBar() { void menuBar() {
JMenuBar c = new JMenuBar(); JMenuBar c = new JMenuBar();
FlatMenuBarUI ui = (FlatMenuBarUI) c.getUI(); FlatMenuBarUI ui = (FlatMenuBarUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInsets( c, ui, "itemMargins", 1,2,3,4 ); testInsets( c, ui, "itemMargins", 1,2,3,4 );
testInsets( c, ui, "selectionInsets", 1,2,3,4 );
testInsets( c, ui, "selectionEmbeddedInsets", 1,2,3,4 );
testInteger( c, ui, "selectionArc", 8 );
testColor( c, ui, "hoverBackground", 0x123456 ); testColor( c, ui, "hoverBackground", 0x123456 );
testColor( c, ui, "selectionBackground", 0x123456 ); testColor( c, ui, "selectionBackground", 0x123456 );
testColor( c, ui, "selectionForeground", 0x123456 ); testColor( c, ui, "selectionForeground", 0x123456 );
@@ -371,6 +455,7 @@ public class TestFlatStyleableValue
void menu() { void menu() {
JMenu c = new JMenu(); JMenu c = new JMenu();
FlatMenuUI ui = (FlatMenuUI) c.getUI(); FlatMenuUI ui = (FlatMenuUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
menuItem( c, ui ); menuItem( c, ui );
menuItem_arrowIcon( c, ui ); menuItem_arrowIcon( c, ui );
@@ -380,6 +465,7 @@ public class TestFlatStyleableValue
void menuItem() { void menuItem() {
JMenuItem c = new JMenuItem(); JMenuItem c = new JMenuItem();
FlatMenuItemUI ui = (FlatMenuItemUI) c.getUI(); FlatMenuItemUI ui = (FlatMenuItemUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
menuItem( c, ui ); menuItem( c, ui );
} }
@@ -388,6 +474,7 @@ public class TestFlatStyleableValue
void checkBoxMenuItem() { void checkBoxMenuItem() {
JCheckBoxMenuItem c = new JCheckBoxMenuItem(); JCheckBoxMenuItem c = new JCheckBoxMenuItem();
FlatCheckBoxMenuItemUI ui = (FlatCheckBoxMenuItemUI) c.getUI(); FlatCheckBoxMenuItemUI ui = (FlatCheckBoxMenuItemUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
menuItem( c, ui ); menuItem( c, ui );
menuItem_checkIcon( c, ui ); menuItem_checkIcon( c, ui );
@@ -397,6 +484,7 @@ public class TestFlatStyleableValue
void radioButtonMenuItem() { void radioButtonMenuItem() {
JRadioButtonMenuItem c = new JRadioButtonMenuItem(); JRadioButtonMenuItem c = new JRadioButtonMenuItem();
FlatRadioButtonMenuItemUI ui = (FlatRadioButtonMenuItemUI) c.getUI(); FlatRadioButtonMenuItemUI ui = (FlatRadioButtonMenuItemUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
menuItem( c, ui ); menuItem( c, ui );
menuItem_checkIcon( c, ui ); menuItem_checkIcon( c, ui );
@@ -424,6 +512,9 @@ public class TestFlatStyleableValue
testColor( c, ui, "checkBackground", 0x123456 ); testColor( c, ui, "checkBackground", 0x123456 );
testInsets( c, ui, "checkMargins", 1,2,3,4 ); testInsets( c, ui, "checkMargins", 1,2,3,4 );
testInsets( c, ui, "selectionInsets", 1,2,3,4 );
testInteger( c, ui, "selectionArc", 8 );
testColor( c, ui, "underlineSelectionBackground", 0x123456 ); testColor( c, ui, "underlineSelectionBackground", 0x123456 );
testColor( c, ui, "underlineSelectionCheckBackground", 0x123456 ); testColor( c, ui, "underlineSelectionCheckBackground", 0x123456 );
testColor( c, ui, "underlineSelectionColor", 0x123456 ); testColor( c, ui, "underlineSelectionColor", 0x123456 );
@@ -447,6 +538,7 @@ public class TestFlatStyleableValue
void panel() { void panel() {
JPanel c = new JPanel(); JPanel c = new JPanel();
FlatPanelUI ui = (FlatPanelUI) c.getUI(); FlatPanelUI ui = (FlatPanelUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "arc", 123 ); testInteger( c, ui, "arc", 123 );
} }
@@ -455,6 +547,7 @@ public class TestFlatStyleableValue
void passwordField() { void passwordField() {
JPasswordField c = new JPasswordField(); JPasswordField c = new JPasswordField();
FlatPasswordFieldUI ui = (FlatPasswordFieldUI) c.getUI(); FlatPasswordFieldUI ui = (FlatPasswordFieldUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
// FlatPasswordFieldUI extends FlatTextFieldUI // FlatPasswordFieldUI extends FlatTextFieldUI
textField( c, ui ); textField( c, ui );
@@ -473,6 +566,7 @@ public class TestFlatStyleableValue
void popupMenu() { void popupMenu() {
JPopupMenu c = new JPopupMenu(); JPopupMenu c = new JPopupMenu();
FlatPopupMenuUI ui = (FlatPopupMenuUI) c.getUI(); FlatPopupMenuUI ui = (FlatPopupMenuUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testString( c, ui, "arrowType", "chevron" ); testString( c, ui, "arrowType", "chevron" );
testColor( c, ui, "scrollArrowColor", 0x123456 ); testColor( c, ui, "scrollArrowColor", 0x123456 );
@@ -486,6 +580,7 @@ public class TestFlatStyleableValue
void popupMenuSeparator() { void popupMenuSeparator() {
JPopupMenu.Separator c = new JPopupMenu.Separator(); JPopupMenu.Separator c = new JPopupMenu.Separator();
FlatPopupMenuSeparatorUI ui = (FlatPopupMenuSeparatorUI) c.getUI(); FlatPopupMenuSeparatorUI ui = (FlatPopupMenuSeparatorUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
// FlatPopupMenuSeparatorUI extends FlatSeparatorUI // FlatPopupMenuSeparatorUI extends FlatSeparatorUI
separator( ui, c ); separator( ui, c );
@@ -495,6 +590,7 @@ public class TestFlatStyleableValue
void progressBar() { void progressBar() {
JProgressBar c = new JProgressBar(); JProgressBar c = new JProgressBar();
FlatProgressBarUI ui = (FlatProgressBarUI) c.getUI(); FlatProgressBarUI ui = (FlatProgressBarUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "arc", 123 ); testInteger( c, ui, "arc", 123 );
testDimension( c, ui, "horizontalSize", 1,2 ); testDimension( c, ui, "horizontalSize", 1,2 );
@@ -507,12 +603,21 @@ public class TestFlatStyleableValue
@Test @Test
void radioButton() { void radioButton() {
radioButton( new JRadioButton() ); radioButton( new JRadioButton() );
}
@Test
void radioButton2() {
radioButton( new JRadioButton( new CustomRadioButtonIcon() ) ); radioButton( new JRadioButton( new CustomRadioButtonIcon() ) );
}
@Test
void radioButton3() {
radioButton( new JRadioButton( new CustomIcon() ) ); radioButton( new JRadioButton( new CustomIcon() ) );
} }
private void radioButton( JRadioButton c ) { private void radioButton( JRadioButton c ) {
FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI(); FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon ); assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
@@ -547,6 +652,8 @@ public class TestFlatStyleableValue
testFloat( b, ui, "icon.borderWidth", 1.23f ); testFloat( b, ui, "icon.borderWidth", 1.23f );
testFloat( b, ui, "icon.selectedBorderWidth", 1.23f ); testFloat( b, ui, "icon.selectedBorderWidth", 1.23f );
testFloat( b, ui, "icon.disabledSelectedBorderWidth", 1.23f ); testFloat( b, ui, "icon.disabledSelectedBorderWidth", 1.23f );
testFloat( b, ui, "icon.indeterminateBorderWidth", 1.23f );
testFloat( b, ui, "icon.disabledIndeterminateBorderWidth", 1.23f );
testInteger( b, ui, "icon.arc", 123 ); testInteger( b, ui, "icon.arc", 123 );
// enabled // enabled
@@ -555,6 +662,9 @@ public class TestFlatStyleableValue
testColor( b, ui, "icon.selectedBorderColor", 0x123456 ); testColor( b, ui, "icon.selectedBorderColor", 0x123456 );
testColor( b, ui, "icon.selectedBackground", 0x123456 ); testColor( b, ui, "icon.selectedBackground", 0x123456 );
testColor( b, ui, "icon.checkmarkColor", 0x123456 ); testColor( b, ui, "icon.checkmarkColor", 0x123456 );
testColor( b, ui, "icon.indeterminateBorderColor", 0x123456 );
testColor( b, ui, "icon.indeterminateBackground", 0x123456 );
testColor( b, ui, "icon.indeterminateCheckmarkColor", 0x123456 );
// disabled // disabled
testColor( b, ui, "icon.disabledBorderColor", 0x123456 ); testColor( b, ui, "icon.disabledBorderColor", 0x123456 );
@@ -562,6 +672,9 @@ public class TestFlatStyleableValue
testColor( b, ui, "icon.disabledSelectedBorderColor", 0x123456 ); testColor( b, ui, "icon.disabledSelectedBorderColor", 0x123456 );
testColor( b, ui, "icon.disabledSelectedBackground", 0x123456 ); testColor( b, ui, "icon.disabledSelectedBackground", 0x123456 );
testColor( b, ui, "icon.disabledCheckmarkColor", 0x123456 ); testColor( b, ui, "icon.disabledCheckmarkColor", 0x123456 );
testColor( b, ui, "icon.disabledIndeterminateBorderColor", 0x123456 );
testColor( b, ui, "icon.disabledIndeterminateBackground", 0x123456 );
testColor( b, ui, "icon.disabledIndeterminateCheckmarkColor", 0x123456 );
// focused // focused
testColor( b, ui, "icon.focusedBorderColor", 0x123456 ); testColor( b, ui, "icon.focusedBorderColor", 0x123456 );
@@ -569,6 +682,9 @@ public class TestFlatStyleableValue
testColor( b, ui, "icon.focusedSelectedBorderColor", 0x123456 ); testColor( b, ui, "icon.focusedSelectedBorderColor", 0x123456 );
testColor( b, ui, "icon.focusedSelectedBackground", 0x123456 ); testColor( b, ui, "icon.focusedSelectedBackground", 0x123456 );
testColor( b, ui, "icon.focusedCheckmarkColor", 0x123456 ); testColor( b, ui, "icon.focusedCheckmarkColor", 0x123456 );
testColor( b, ui, "icon.focusedIndeterminateBorderColor", 0x123456 );
testColor( b, ui, "icon.focusedIndeterminateBackground", 0x123456 );
testColor( b, ui, "icon.focusedIndeterminateCheckmarkColor", 0x123456 );
// hover // hover
testColor( b, ui, "icon.hoverBorderColor", 0x123456 ); testColor( b, ui, "icon.hoverBorderColor", 0x123456 );
@@ -576,6 +692,9 @@ public class TestFlatStyleableValue
testColor( b, ui, "icon.hoverSelectedBorderColor", 0x123456 ); testColor( b, ui, "icon.hoverSelectedBorderColor", 0x123456 );
testColor( b, ui, "icon.hoverSelectedBackground", 0x123456 ); testColor( b, ui, "icon.hoverSelectedBackground", 0x123456 );
testColor( b, ui, "icon.hoverCheckmarkColor", 0x123456 ); testColor( b, ui, "icon.hoverCheckmarkColor", 0x123456 );
testColor( b, ui, "icon.hoverIndeterminateBorderColor", 0x123456 );
testColor( b, ui, "icon.hoverIndeterminateBackground", 0x123456 );
testColor( b, ui, "icon.hoverIndeterminateCheckmarkColor", 0x123456 );
// pressed // pressed
testColor( b, ui, "icon.pressedBorderColor", 0x123456 ); testColor( b, ui, "icon.pressedBorderColor", 0x123456 );
@@ -583,12 +702,16 @@ public class TestFlatStyleableValue
testColor( b, ui, "icon.pressedSelectedBorderColor", 0x123456 ); testColor( b, ui, "icon.pressedSelectedBorderColor", 0x123456 );
testColor( b, ui, "icon.pressedSelectedBackground", 0x123456 ); testColor( b, ui, "icon.pressedSelectedBackground", 0x123456 );
testColor( b, ui, "icon.pressedCheckmarkColor", 0x123456 ); testColor( b, ui, "icon.pressedCheckmarkColor", 0x123456 );
testColor( b, ui, "icon.pressedIndeterminateBorderColor", 0x123456 );
testColor( b, ui, "icon.pressedIndeterminateBackground", 0x123456 );
testColor( b, ui, "icon.pressedIndeterminateCheckmarkColor", 0x123456 );
} }
@Test @Test
void scrollBar() { void scrollBar() {
JScrollBar c = new JScrollBar(); JScrollBar c = new JScrollBar();
FlatScrollBarUI ui = (FlatScrollBarUI) c.getUI(); FlatScrollBarUI ui = (FlatScrollBarUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testColor( c, ui, "track", 0x123456 ); testColor( c, ui, "track", 0x123456 );
testColor( c, ui, "thumb", 0x123456 ); testColor( c, ui, "thumb", 0x123456 );
@@ -621,6 +744,7 @@ public class TestFlatStyleableValue
void scrollPane() { void scrollPane() {
JScrollPane c = new JScrollPane(); JScrollPane c = new JScrollPane();
FlatScrollPaneUI ui = (FlatScrollPaneUI) c.getUI(); FlatScrollPaneUI ui = (FlatScrollPaneUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
// border // border
flatScrollPaneBorder( c, ui ); flatScrollPaneBorder( c, ui );
@@ -632,6 +756,7 @@ public class TestFlatStyleableValue
void separator() { void separator() {
JSeparator c = new JSeparator(); JSeparator c = new JSeparator();
FlatSeparatorUI ui = (FlatSeparatorUI) c.getUI(); FlatSeparatorUI ui = (FlatSeparatorUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
separator( ui, c ); separator( ui, c );
} }
@@ -646,6 +771,7 @@ public class TestFlatStyleableValue
void slider() { void slider() {
JSlider c = new JSlider(); JSlider c = new JSlider();
FlatSliderUI ui = (FlatSliderUI) c.getUI(); FlatSliderUI ui = (FlatSliderUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "trackWidth", 123 ); testInteger( c, ui, "trackWidth", 123 );
testDimension( c, ui, "thumbSize", 1,2 ); testDimension( c, ui, "thumbSize", 1,2 );
@@ -670,6 +796,7 @@ public class TestFlatStyleableValue
void spinner() { void spinner() {
JSpinner c = new JSpinner(); JSpinner c = new JSpinner();
FlatSpinnerUI ui = (FlatSpinnerUI) c.getUI(); FlatSpinnerUI ui = (FlatSpinnerUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "minimumWidth", 123 ); testInteger( c, ui, "minimumWidth", 123 );
testString( c, ui, "buttonStyle", "button" ); testString( c, ui, "buttonStyle", "button" );
@@ -695,6 +822,7 @@ public class TestFlatStyleableValue
void splitPane() { void splitPane() {
JSplitPane c = new JSplitPane(); JSplitPane c = new JSplitPane();
FlatSplitPaneUI ui = (FlatSplitPaneUI) c.getUI(); FlatSplitPaneUI ui = (FlatSplitPaneUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testString( c, ui, "arrowType", "chevron" ); testString( c, ui, "arrowType", "chevron" );
testColor( c, ui, "draggingColor", 0x123456 ); testColor( c, ui, "draggingColor", 0x123456 );
@@ -715,6 +843,7 @@ public class TestFlatStyleableValue
void tabbedPane() { void tabbedPane() {
JTabbedPane c = new JTabbedPane(); JTabbedPane c = new JTabbedPane();
FlatTabbedPaneUI ui = (FlatTabbedPaneUI) c.getUI(); FlatTabbedPaneUI ui = (FlatTabbedPaneUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInsets( c, ui, "tabInsets", 1,2,3,4 ); testInsets( c, ui, "tabInsets", 1,2,3,4 );
testInsets( c, ui, "tabAreaInsets", 1,2,3,4 ); testInsets( c, ui, "tabAreaInsets", 1,2,3,4 );
@@ -793,6 +922,7 @@ public class TestFlatStyleableValue
void table() { void table() {
JTable c = new JTable(); JTable c = new JTable();
FlatTableUI ui = (FlatTableUI) c.getUI(); FlatTableUI ui = (FlatTableUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testBoolean( c, ui, "showTrailingVerticalLine", true ); testBoolean( c, ui, "showTrailingVerticalLine", true );
testColor( c, ui, "selectionBackground", 0x123456 ); testColor( c, ui, "selectionBackground", 0x123456 );
@@ -812,6 +942,7 @@ public class TestFlatStyleableValue
void tableHeader() { void tableHeader() {
JTableHeader c = new JTableHeader(); JTableHeader c = new JTableHeader();
FlatTableHeaderUI ui = (FlatTableHeaderUI) c.getUI(); FlatTableHeaderUI ui = (FlatTableHeaderUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testColor( c, ui, "hoverBackground", 0x123456 ); testColor( c, ui, "hoverBackground", 0x123456 );
testColor( c, ui, "hoverForeground", 0x123456 ); testColor( c, ui, "hoverForeground", 0x123456 );
@@ -835,6 +966,7 @@ public class TestFlatStyleableValue
void textArea() { void textArea() {
JTextArea c = new JTextArea(); JTextArea c = new JTextArea();
FlatTextAreaUI ui = (FlatTextAreaUI) c.getUI(); FlatTextAreaUI ui = (FlatTextAreaUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "minimumWidth", 123 ); testInteger( c, ui, "minimumWidth", 123 );
testColor( c, ui, "disabledBackground", 0x123456 ); testColor( c, ui, "disabledBackground", 0x123456 );
@@ -846,6 +978,7 @@ public class TestFlatStyleableValue
void textField() { void textField() {
JTextField c = new JTextField(); JTextField c = new JTextField();
FlatTextFieldUI ui = (FlatTextFieldUI) c.getUI(); FlatTextFieldUI ui = (FlatTextFieldUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
textField( c, ui ); textField( c, ui );
} }
@@ -870,6 +1003,7 @@ public class TestFlatStyleableValue
void textPane() { void textPane() {
JTextPane c = new JTextPane(); JTextPane c = new JTextPane();
FlatTextPaneUI ui = (FlatTextPaneUI) c.getUI(); FlatTextPaneUI ui = (FlatTextPaneUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "minimumWidth", 123 ); testInteger( c, ui, "minimumWidth", 123 );
testColor( c, ui, "disabledBackground", 0x123456 ); testColor( c, ui, "disabledBackground", 0x123456 );
@@ -881,6 +1015,7 @@ public class TestFlatStyleableValue
void toggleButton() { void toggleButton() {
JToggleButton b = new JToggleButton(); JToggleButton b = new JToggleButton();
FlatToggleButtonUI ui = (FlatToggleButtonUI) b.getUI(); FlatToggleButtonUI ui = (FlatToggleButtonUI) b.getUI();
expectedStyleableInfos = ui.getStyleableInfos( b );
// FlatToggleButtonUI extends FlatButtonUI // FlatToggleButtonUI extends FlatButtonUI
button( b, ui ); button( b, ui );
@@ -900,9 +1035,12 @@ public class TestFlatStyleableValue
void toolBar() { void toolBar() {
JToolBar c = new JToolBar(); JToolBar c = new JToolBar();
FlatToolBarUI ui = (FlatToolBarUI) c.getUI(); FlatToolBarUI ui = (FlatToolBarUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testBoolean( c, ui, "focusableButtons", true ); testBoolean( c, ui, "focusableButtons", true );
testBoolean( c, ui, "arrowKeysOnlyNavigation", true ); testBoolean( c, ui, "arrowKeysOnlyNavigation", true );
testInteger( c, ui, "hoverButtonGroupArc", 12 );
testColor( c, ui, "hoverButtonGroupBackground", 0x123456 );
testInsets( c, ui, "borderMargins", 1,2,3,4 ); testInsets( c, ui, "borderMargins", 1,2,3,4 );
testColor( c, ui, "gripColor", 0x123456 ); testColor( c, ui, "gripColor", 0x123456 );
@@ -915,6 +1053,7 @@ public class TestFlatStyleableValue
void toolBarSeparator() { void toolBarSeparator() {
JToolBar.Separator c = new JToolBar.Separator(); JToolBar.Separator c = new JToolBar.Separator();
FlatToolBarSeparatorUI ui = (FlatToolBarSeparatorUI) c.getUI(); FlatToolBarSeparatorUI ui = (FlatToolBarSeparatorUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testInteger( c, ui, "separatorWidth", 123 ); testInteger( c, ui, "separatorWidth", 123 );
testColor( c, ui, "separatorColor", 0x123456 ); testColor( c, ui, "separatorColor", 0x123456 );
@@ -924,6 +1063,7 @@ public class TestFlatStyleableValue
void tree() { void tree() {
JTree c = new JTree(); JTree c = new JTree();
FlatTreeUI ui = (FlatTreeUI) c.getUI(); FlatTreeUI ui = (FlatTreeUI) c.getUI();
expectedStyleableInfos = ui.getStyleableInfos( c );
testColor( c, ui, "selectionBackground", 0x123456 ); testColor( c, ui, "selectionBackground", 0x123456 );
testColor( c, ui, "selectionForeground", 0x123456 ); testColor( c, ui, "selectionForeground", 0x123456 );
@@ -1029,6 +1169,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatButtonBorder() { void flatButtonBorder() {
FlatButtonBorder border = new FlatButtonBorder(); FlatButtonBorder border = new FlatButtonBorder();
expectedStyleableInfos = border.getStyleableInfos();
// FlatButtonBorder extends FlatBorder // FlatButtonBorder extends FlatBorder
flatBorder( border ); flatBorder( border );
@@ -1063,6 +1204,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatRoundBorder() { void flatRoundBorder() {
FlatRoundBorder border = new FlatRoundBorder(); FlatRoundBorder border = new FlatRoundBorder();
expectedStyleableInfos = border.getStyleableInfos();
// FlatRoundBorder extends FlatBorder // FlatRoundBorder extends FlatBorder
flatBorder( border ); flatBorder( border );
@@ -1074,6 +1216,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatScrollPaneBorder() { void flatScrollPaneBorder() {
FlatScrollPaneBorder border = new FlatScrollPaneBorder(); FlatScrollPaneBorder border = new FlatScrollPaneBorder();
expectedStyleableInfos = border.getStyleableInfos();
// FlatScrollPaneBorder extends FlatBorder // FlatScrollPaneBorder extends FlatBorder
flatBorder( border ); flatBorder( border );
@@ -1084,6 +1227,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatTextBorder() { void flatTextBorder() {
FlatTextBorder border = new FlatTextBorder(); FlatTextBorder border = new FlatTextBorder();
expectedStyleableInfos = border.getStyleableInfos();
// FlatTextBorder extends FlatBorder // FlatTextBorder extends FlatBorder
flatBorder( border ); flatBorder( border );
@@ -1095,6 +1239,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatBorder() { void flatBorder() {
FlatBorder border = new FlatBorder(); FlatBorder border = new FlatBorder();
expectedStyleableInfos = border.getStyleableInfos();
flatBorder( border ); flatBorder( border );
} }
@@ -1117,11 +1262,16 @@ public class TestFlatStyleableValue
testValue( border, "success.borderColor", Color.WHITE ); testValue( border, "success.borderColor", Color.WHITE );
testValue( border, "success.focusedBorderColor", Color.WHITE ); testValue( border, "success.focusedBorderColor", Color.WHITE );
testValue( border, "custom.borderColor", Color.WHITE ); testValue( border, "custom.borderColor", Color.WHITE );
testValue( border, "outline", "error" );
testValue( border, "outlineColor", Color.WHITE );
testValue( border, "outlineFocusedColor", Color.WHITE );
} }
@Test @Test
void flatDropShadowBorder() { void flatDropShadowBorder() {
FlatDropShadowBorder border = new FlatDropShadowBorder(); FlatDropShadowBorder border = new FlatDropShadowBorder();
expectedStyleableInfos = border.getStyleableInfos();
testValue( border, "shadowColor", Color.WHITE ); testValue( border, "shadowColor", Color.WHITE );
testValue( border, "shadowInsets", new Insets( 1, 2, 3, 4 ) ); testValue( border, "shadowInsets", new Insets( 1, 2, 3, 4 ) );
@@ -1131,6 +1281,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatMenuBarBorder() { void flatMenuBarBorder() {
FlatMenuBarBorder border = new FlatMenuBarBorder(); FlatMenuBarBorder border = new FlatMenuBarBorder();
expectedStyleableInfos = border.getStyleableInfos();
testValue( border, "borderColor", Color.WHITE ); testValue( border, "borderColor", Color.WHITE );
} }
@@ -1138,6 +1289,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatPopupMenuBorder() { void flatPopupMenuBorder() {
FlatPopupMenuBorder border = new FlatPopupMenuBorder(); FlatPopupMenuBorder border = new FlatPopupMenuBorder();
expectedStyleableInfos = border.getStyleableInfos();
testValue( border, "borderInsets", new Insets( 1, 2, 3, 4 ) ); testValue( border, "borderInsets", new Insets( 1, 2, 3, 4 ) );
testValue( border, "borderColor", Color.WHITE ); testValue( border, "borderColor", Color.WHITE );
@@ -1146,6 +1298,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatInternalFrameBorder() { void flatInternalFrameBorder() {
FlatInternalFrameBorder border = new FlatInternalFrameBorder(); FlatInternalFrameBorder border = new FlatInternalFrameBorder();
expectedStyleableInfos = border.getStyleableInfos();
testValue( border, "activeBorderColor", Color.WHITE ); testValue( border, "activeBorderColor", Color.WHITE );
testValue( border, "inactiveBorderColor", Color.WHITE ); testValue( border, "inactiveBorderColor", Color.WHITE );
@@ -1166,6 +1319,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatCheckBoxIcon() { void flatCheckBoxIcon() {
FlatCheckBoxIcon icon = new FlatCheckBoxIcon(); FlatCheckBoxIcon icon = new FlatCheckBoxIcon();
expectedStyleableInfos = icon.getStyleableInfos();
flatCheckBoxIcon( icon ); flatCheckBoxIcon( icon );
} }
@@ -1173,6 +1327,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatRadioButtonIcon() { void flatRadioButtonIcon() {
FlatRadioButtonIcon icon = new FlatRadioButtonIcon(); FlatRadioButtonIcon icon = new FlatRadioButtonIcon();
expectedStyleableInfos = icon.getStyleableInfos();
// FlatRadioButtonIcon extends FlatCheckBoxIcon // FlatRadioButtonIcon extends FlatCheckBoxIcon
flatCheckBoxIcon( icon ); flatCheckBoxIcon( icon );
@@ -1244,6 +1399,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatCheckBoxMenuItemIcon() { void flatCheckBoxMenuItemIcon() {
FlatCheckBoxMenuItemIcon icon = new FlatCheckBoxMenuItemIcon(); FlatCheckBoxMenuItemIcon icon = new FlatCheckBoxMenuItemIcon();
expectedStyleableInfos = icon.getStyleableInfos();
flatCheckBoxMenuItemIcon( icon ); flatCheckBoxMenuItemIcon( icon );
} }
@@ -1251,6 +1407,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatRadioButtonMenuItemIcon() { void flatRadioButtonMenuItemIcon() {
FlatRadioButtonMenuItemIcon icon = new FlatRadioButtonMenuItemIcon(); FlatRadioButtonMenuItemIcon icon = new FlatRadioButtonMenuItemIcon();
expectedStyleableInfos = icon.getStyleableInfos();
// FlatRadioButtonMenuItemIcon extends FlatCheckBoxMenuItemIcon // FlatRadioButtonMenuItemIcon extends FlatCheckBoxMenuItemIcon
flatCheckBoxMenuItemIcon( icon ); flatCheckBoxMenuItemIcon( icon );
@@ -1265,6 +1422,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatMenuArrowIcon() { void flatMenuArrowIcon() {
FlatMenuArrowIcon icon = new FlatMenuArrowIcon(); FlatMenuArrowIcon icon = new FlatMenuArrowIcon();
expectedStyleableInfos = icon.getStyleableInfos();
testValue( icon, "arrowType", "chevron" ); testValue( icon, "arrowType", "chevron" );
testValue( icon, "arrowColor", Color.WHITE ); testValue( icon, "arrowColor", Color.WHITE );
@@ -1275,6 +1433,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatHelpButtonIcon() { void flatHelpButtonIcon() {
FlatHelpButtonIcon icon = new FlatHelpButtonIcon(); FlatHelpButtonIcon icon = new FlatHelpButtonIcon();
expectedStyleableInfos = icon.getStyleableInfos();
testValue( icon, "focusWidth", 2 ); testValue( icon, "focusWidth", 2 );
testValue( icon, "focusColor", Color.WHITE ); testValue( icon, "focusColor", Color.WHITE );
@@ -1297,6 +1456,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatClearIcon() { void flatClearIcon() {
FlatClearIcon icon = new FlatClearIcon(); FlatClearIcon icon = new FlatClearIcon();
expectedStyleableInfos = icon.getStyleableInfos();
testValue( icon, "clearIconColor", Color.WHITE ); testValue( icon, "clearIconColor", Color.WHITE );
testValue( icon, "clearIconHoverColor", Color.WHITE ); testValue( icon, "clearIconHoverColor", Color.WHITE );
@@ -1306,6 +1466,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatSearchIcon() { void flatSearchIcon() {
FlatSearchIcon icon = new FlatSearchIcon(); FlatSearchIcon icon = new FlatSearchIcon();
expectedStyleableInfos = icon.getStyleableInfos();
flatSearchIcon( icon ); flatSearchIcon( icon );
} }
@@ -1313,6 +1474,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatSearchWithHistoryIcon() { void flatSearchWithHistoryIcon() {
FlatSearchWithHistoryIcon icon = new FlatSearchWithHistoryIcon(); FlatSearchWithHistoryIcon icon = new FlatSearchWithHistoryIcon();
expectedStyleableInfos = icon.getStyleableInfos();
flatSearchIcon( icon ); flatSearchIcon( icon );
} }
@@ -1326,6 +1488,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatCapsLockIcon() { void flatCapsLockIcon() {
FlatCapsLockIcon icon = new FlatCapsLockIcon(); FlatCapsLockIcon icon = new FlatCapsLockIcon();
expectedStyleableInfos = icon.getStyleableInfos();
testValue( icon, "capsLockIconColor", Color.WHITE ); testValue( icon, "capsLockIconColor", Color.WHITE );
} }
@@ -1333,6 +1496,7 @@ public class TestFlatStyleableValue
@Test @Test
void flatTabbedPaneCloseIcon() { void flatTabbedPaneCloseIcon() {
FlatTabbedPaneCloseIcon icon = new FlatTabbedPaneCloseIcon(); FlatTabbedPaneCloseIcon icon = new FlatTabbedPaneCloseIcon();
expectedStyleableInfos = icon.getStyleableInfos();
testValue( icon, "closeSize", new Dimension( 1, 2 ) ); testValue( icon, "closeSize", new Dimension( 1, 2 ) );
testValue( icon, "closeArc", 123 ); testValue( icon, "closeArc", 123 );

View File

@@ -310,7 +310,15 @@ public class TestFlatStyling
@Test @Test
void checkBox() { void checkBox() {
checkBox( new JCheckBox() ); checkBox( new JCheckBox() );
}
@Test
void checkBox2() {
checkBox( new JCheckBox( new CustomIcon() ) ); checkBox( new JCheckBox( new CustomIcon() ) );
}
@Test
void checkBox3() {
checkBox( new JCheckBox( new CustomCheckBoxIcon() ) ); checkBox( new JCheckBox( new CustomCheckBoxIcon() ) );
} }
@@ -676,7 +684,15 @@ public class TestFlatStyling
@Test @Test
void radioButton() { void radioButton() {
radioButton( new JRadioButton() ); radioButton( new JRadioButton() );
}
@Test
void radioButton2() {
radioButton( new JRadioButton( new CustomIcon() ) ); radioButton( new JRadioButton( new CustomIcon() ) );
}
@Test
void radioButton3() {
radioButton( new JRadioButton( new CustomRadioButtonIcon() ) ); radioButton( new JRadioButton( new CustomRadioButtonIcon() ) );
} }

View File

@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet;
import javax.swing.UIManager; import javax.swing.UIManager;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError; import org.opentest4j.AssertionFailedError;
@@ -71,6 +72,19 @@ public class TestUtils
} }
} }
public static void assertSetEquals( Set<?> expected, Set<?> actual, String message ) {
if( !Objects.equals( expected, actual ) ) {
String expectedStr = String.valueOf( new TreeSet<>( expected ) ).replace( ", ", ",\n" );
String actualStr = String.valueOf( new TreeSet<>( actual ) ).replace( ", ", ",\n" );
String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr );
if( message != null )
msg = message + " ==> " + msg;
// pass expected/actual strings to exception for nice diff in IDE
throw new AssertionFailedError( msg, expectedStr, actualStr );
}
}
public static void checkImplementedTests( Set<String> excludes, Class<?> baseClass, Class<?>... classes ) { public static void checkImplementedTests( Set<String> excludes, Class<?> baseClass, Class<?>... classes ) {
Set<String> expected = getTestMethods( baseClass ); Set<String> expected = getTestMethods( baseClass );