mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 05:50:53 +03:00
Styling: added missing unit tests; added missing FlatCapsLockIcon.getStyleableInfos()
This commit is contained in:
@@ -25,6 +25,8 @@ import java.awt.geom.Area;
|
|||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
||||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
@@ -54,6 +56,11 @@ public class FlatCapsLockIcon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 3.7 */
|
||||||
|
public Map<String, Class<?>> getStyleableInfos() throws IllegalArgumentException {
|
||||||
|
return Collections.singletonMap( "capsLockIconColor", Color.class );
|
||||||
|
}
|
||||||
|
|
||||||
/** @since 2.5 */
|
/** @since 2.5 */
|
||||||
public Object getStyleableValue( String key ) {
|
public Object getStyleableValue( String key ) {
|
||||||
switch( key ) {
|
switch( key ) {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
@@ -230,7 +229,8 @@ public class FlatPasswordFieldUI
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
Map<String, Class<?>> infos = super.getStyleableInfos( c );
|
Map<String, Class<?>> infos = super.getStyleableInfos( c );
|
||||||
infos.put( "capsLockIconColor", Color.class );
|
if( capsLockIcon instanceof FlatCapsLockIcon )
|
||||||
|
infos.putAll( ((FlatCapsLockIcon)capsLockIcon).getStyleableInfos() );
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1135,6 +1135,16 @@ public class TestFlatStyleableInfo
|
|||||||
assertMapEquals( expected, border.getStyleableInfos() );
|
assertMapEquals( expected, border.getStyleableInfos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatScrollPaneBorder() {
|
||||||
|
FlatScrollPaneBorder border = new FlatScrollPaneBorder();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
||||||
|
flatScrollPaneBorder( expected );
|
||||||
|
|
||||||
|
assertMapEquals( expected, border.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void flatTextBorder() {
|
void flatTextBorder() {
|
||||||
FlatTextBorder border = new FlatTextBorder();
|
FlatTextBorder border = new FlatTextBorder();
|
||||||
@@ -1318,4 +1328,56 @@ public class TestFlatStyleableInfo
|
|||||||
|
|
||||||
assertMapEquals( expected, icon.getStyleableInfos() );
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatClearIcon() {
|
||||||
|
FlatClearIcon icon = new FlatClearIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = expectedMap(
|
||||||
|
"clearIconColor", Color.class,
|
||||||
|
"clearIconHoverColor", Color.class,
|
||||||
|
"clearIconPressedColor", Color.class
|
||||||
|
);
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatSearchIcon() {
|
||||||
|
FlatSearchIcon icon = new FlatSearchIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
||||||
|
flatSearchIcon( expected );
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatSearchWithHistoryIcon() {
|
||||||
|
FlatSearchWithHistoryIcon icon = new FlatSearchWithHistoryIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
||||||
|
flatSearchIcon( expected );
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flatSearchIcon( Map<String, Class<?>> expected ) {
|
||||||
|
expectedMap( expected,
|
||||||
|
"searchIconColor", Color.class,
|
||||||
|
"searchIconHoverColor", Color.class,
|
||||||
|
"searchIconPressedColor", Color.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatCapsLockIcon() {
|
||||||
|
FlatCapsLockIcon icon = new FlatCapsLockIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = expectedMap(
|
||||||
|
"capsLockIconColor", Color.class
|
||||||
|
);
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||||||
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.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import com.formdev.flatlaf.icons.FlatCapsLockIcon;
|
||||||
import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
|
import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
|
||||||
import com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon;
|
import com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon;
|
||||||
import com.formdev.flatlaf.icons.FlatClearIcon;
|
import com.formdev.flatlaf.icons.FlatClearIcon;
|
||||||
@@ -1324,6 +1325,13 @@ public class TestFlatStyleableValue
|
|||||||
testValue( icon, "searchIconPressedColor", Color.WHITE );
|
testValue( icon, "searchIconPressedColor", Color.WHITE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatCapsLockIcon() {
|
||||||
|
FlatCapsLockIcon icon = new FlatCapsLockIcon();
|
||||||
|
|
||||||
|
testValue( icon, "capsLockIconColor", Color.WHITE );
|
||||||
|
}
|
||||||
|
|
||||||
//---- class TestIcon -----------------------------------------------------
|
//---- class TestIcon -----------------------------------------------------
|
||||||
|
|
||||||
@SuppressWarnings( "EqualsHashCode" ) // Error Prone
|
@SuppressWarnings( "EqualsHashCode" ) // Error Prone
|
||||||
|
|||||||
@@ -23,8 +23,11 @@ import java.awt.Component;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.JTableHeader;
|
import javax.swing.table.JTableHeader;
|
||||||
@@ -50,6 +53,14 @@ public class TestFlatStyling
|
|||||||
FlatLaf.setGlobalExtraDefaults( globalExtraDefaults );
|
FlatLaf.setGlobalExtraDefaults( globalExtraDefaults );
|
||||||
|
|
||||||
TestUtils.setup( false );
|
TestUtils.setup( false );
|
||||||
|
|
||||||
|
Set<String> excludes = new HashSet<>();
|
||||||
|
Collections.addAll( excludes,
|
||||||
|
"parse", "parseIfFunction", "parseColorFunctions",
|
||||||
|
"parseReferences", "parseVariables", "parseRecursiveVariables",
|
||||||
|
"enumField", "enumProperty", "enumUIDefaults" );
|
||||||
|
TestUtils.checkImplementedTests( excludes, TestFlatStyling.class,
|
||||||
|
TestFlatStyleableValue.class, TestFlatStyleableInfo.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@@ -1365,6 +1376,16 @@ public class TestFlatStyling
|
|||||||
border.applyStyleProperty( "arc", 6 );
|
border.applyStyleProperty( "arc", 6 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatScrollPaneBorder() {
|
||||||
|
FlatScrollPaneBorder border = new FlatScrollPaneBorder();
|
||||||
|
|
||||||
|
// FlatScrollPaneBorder extends FlatBorder
|
||||||
|
flatBorder( border );
|
||||||
|
|
||||||
|
border.applyStyleProperty( "arc", 6 );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void flatTextBorder() {
|
void flatTextBorder() {
|
||||||
FlatTextBorder border = new FlatTextBorder();
|
FlatTextBorder border = new FlatTextBorder();
|
||||||
@@ -1564,6 +1585,13 @@ public class TestFlatStyling
|
|||||||
icon.applyStyleProperty( "searchIconPressedColor", Color.WHITE );
|
icon.applyStyleProperty( "searchIconPressedColor", Color.WHITE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatCapsLockIcon() {
|
||||||
|
FlatCapsLockIcon icon = new FlatCapsLockIcon();
|
||||||
|
|
||||||
|
icon.applyStyleProperty( "capsLockIconColor", Color.WHITE );
|
||||||
|
}
|
||||||
|
|
||||||
//---- enums --------------------------------------------------------------
|
//---- enums --------------------------------------------------------------
|
||||||
|
|
||||||
enum SomeEnum { enumValue1, enumValue2 }
|
enum SomeEnum { enumValue1, enumValue2 }
|
||||||
|
|||||||
@@ -17,9 +17,14 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeMap;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.opentest4j.AssertionFailedError;
|
import org.opentest4j.AssertionFailedError;
|
||||||
import com.formdev.flatlaf.FlatIntelliJLaf;
|
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||||
import com.formdev.flatlaf.FlatLightLaf;
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
@@ -57,12 +62,44 @@ public class TestUtils
|
|||||||
|
|
||||||
public static void assertMapEquals( Map<?, ?> expected, Map<?, ?> actual ) {
|
public static void assertMapEquals( Map<?, ?> expected, Map<?, ?> actual ) {
|
||||||
if( !Objects.equals( expected, actual ) ) {
|
if( !Objects.equals( expected, actual ) ) {
|
||||||
String expectedStr = String.valueOf( expected ).replace( ", ", ",\n" );
|
String expectedStr = String.valueOf( new TreeMap<>( expected ) ).replace( ", ", ",\n" );
|
||||||
String actualStr = String.valueOf( actual ).replace( ", ", ",\n" );
|
String actualStr = String.valueOf( new TreeMap<>( actual ) ).replace( ", ", ",\n" );
|
||||||
String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr );
|
String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr );
|
||||||
|
|
||||||
// pass expected/actual strings to exception for nice diff in IDE
|
// pass expected/actual strings to exception for nice diff in IDE
|
||||||
throw new AssertionFailedError( msg, expectedStr, actualStr );
|
throw new AssertionFailedError( msg, expectedStr, actualStr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkImplementedTests( Set<String> excludes, Class<?> baseClass, Class<?>... classes ) {
|
||||||
|
Set<String> expected = getTestMethods( baseClass );
|
||||||
|
|
||||||
|
for( Class<?> cls : classes ) {
|
||||||
|
Set<String> actual = getTestMethods( cls );
|
||||||
|
|
||||||
|
for( String methodName : expected ) {
|
||||||
|
if( !actual.contains( methodName ) && !excludes.contains( methodName ) ) {
|
||||||
|
throw new AssertionFailedError( "missing " + cls.getSimpleName() + '.' + methodName
|
||||||
|
+ "() for " + baseClass.getSimpleName() + '.' + methodName + "()" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( String methodName : actual ) {
|
||||||
|
if( !expected.contains( methodName ) && !excludes.contains( methodName ) ) {
|
||||||
|
throw new AssertionFailedError( "missing " + baseClass.getSimpleName() + '.' + methodName
|
||||||
|
+ "() for " + cls.getSimpleName() + '.' + methodName + "()" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<String> getTestMethods( Class<?> cls ) {
|
||||||
|
HashSet<String> tests = new HashSet<>();
|
||||||
|
Method[] methods = cls.getDeclaredMethods();
|
||||||
|
for( Method m : methods ) {
|
||||||
|
if( m.isAnnotationPresent( Test.class ) )
|
||||||
|
tests.add( m.getName() );
|
||||||
|
}
|
||||||
|
return tests;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user