Skip to content

Commit 03b7a1c

Browse files
committed
Styling: added missing unit tests; added missing FlatCapsLockIcon.getStyleableInfos()
1 parent 60968f7 commit 03b7a1c

File tree

6 files changed

+146
-4
lines changed

6 files changed

+146
-4
lines changed

flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCapsLockIcon.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.awt.geom.Path2D;
2626
import java.awt.geom.Rectangle2D;
2727
import java.awt.geom.RoundRectangle2D;
28+
import java.util.Collections;
29+
import java.util.Map;
2830
import javax.swing.UIManager;
2931
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
3032
import com.formdev.flatlaf.ui.FlatUIUtils;
@@ -54,6 +56,11 @@ public Object applyStyleProperty( String key, Object value ) {
5456
}
5557
}
5658

59+
/** @since 3.7 */
60+
public Map<String, Class<?>> getStyleableInfos() throws IllegalArgumentException {
61+
return Collections.singletonMap( "capsLockIconColor", Color.class );
62+
}
63+
5764
/** @since 2.5 */
5865
public Object getStyleableValue( String key ) {
5966
switch( key ) {

flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPasswordFieldUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.formdev.flatlaf.ui;
1818

19-
import java.awt.Color;
2019
import java.awt.Graphics;
2120
import java.awt.Rectangle;
2221
import java.awt.Toolkit;
@@ -230,7 +229,8 @@ protected Object applyStyleProperty( String key, Object value ) {
230229
@Override
231230
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
232231
Map<String, Class<?>> infos = super.getStyleableInfos( c );
233-
infos.put( "capsLockIconColor", Color.class );
232+
if( capsLockIcon instanceof FlatCapsLockIcon )
233+
infos.putAll( ((FlatCapsLockIcon)capsLockIcon).getStyleableInfos() );
234234
return infos;
235235
}
236236

flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,16 @@ void flatRoundBorder() {
11351135
assertMapEquals( expected, border.getStyleableInfos() );
11361136
}
11371137

1138+
@Test
1139+
void flatScrollPaneBorder() {
1140+
FlatScrollPaneBorder border = new FlatScrollPaneBorder();
1141+
1142+
Map<String, Class<?>> expected = new LinkedHashMap<>();
1143+
flatScrollPaneBorder( expected );
1144+
1145+
assertMapEquals( expected, border.getStyleableInfos() );
1146+
}
1147+
11381148
@Test
11391149
void flatTextBorder() {
11401150
FlatTextBorder border = new FlatTextBorder();
@@ -1318,4 +1328,56 @@ void flatHelpButtonIcon() {
13181328

13191329
assertMapEquals( expected, icon.getStyleableInfos() );
13201330
}
1331+
1332+
@Test
1333+
void flatClearIcon() {
1334+
FlatClearIcon icon = new FlatClearIcon();
1335+
1336+
Map<String, Class<?>> expected = expectedMap(
1337+
"clearIconColor", Color.class,
1338+
"clearIconHoverColor", Color.class,
1339+
"clearIconPressedColor", Color.class
1340+
);
1341+
1342+
assertMapEquals( expected, icon.getStyleableInfos() );
1343+
}
1344+
1345+
@Test
1346+
void flatSearchIcon() {
1347+
FlatSearchIcon icon = new FlatSearchIcon();
1348+
1349+
Map<String, Class<?>> expected = new LinkedHashMap<>();
1350+
flatSearchIcon( expected );
1351+
1352+
assertMapEquals( expected, icon.getStyleableInfos() );
1353+
}
1354+
1355+
@Test
1356+
void flatSearchWithHistoryIcon() {
1357+
FlatSearchWithHistoryIcon icon = new FlatSearchWithHistoryIcon();
1358+
1359+
Map<String, Class<?>> expected = new LinkedHashMap<>();
1360+
flatSearchIcon( expected );
1361+
1362+
assertMapEquals( expected, icon.getStyleableInfos() );
1363+
}
1364+
1365+
private void flatSearchIcon( Map<String, Class<?>> expected ) {
1366+
expectedMap( expected,
1367+
"searchIconColor", Color.class,
1368+
"searchIconHoverColor", Color.class,
1369+
"searchIconPressedColor", Color.class
1370+
);
1371+
}
1372+
1373+
@Test
1374+
void flatCapsLockIcon() {
1375+
FlatCapsLockIcon icon = new FlatCapsLockIcon();
1376+
1377+
Map<String, Class<?>> expected = expectedMap(
1378+
"capsLockIconColor", Color.class
1379+
);
1380+
1381+
assertMapEquals( expected, icon.getStyleableInfos() );
1382+
}
13211383
}

flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableValue.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.junit.jupiter.api.Assertions;
6868
import org.junit.jupiter.api.BeforeAll;
6969
import org.junit.jupiter.api.Test;
70+
import com.formdev.flatlaf.icons.FlatCapsLockIcon;
7071
import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
7172
import com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon;
7273
import com.formdev.flatlaf.icons.FlatClearIcon;
@@ -1324,6 +1325,13 @@ private void flatSearchIcon( FlatSearchIcon icon ) {
13241325
testValue( icon, "searchIconPressedColor", Color.WHITE );
13251326
}
13261327

1328+
@Test
1329+
void flatCapsLockIcon() {
1330+
FlatCapsLockIcon icon = new FlatCapsLockIcon();
1331+
1332+
testValue( icon, "capsLockIconColor", Color.WHITE );
1333+
}
1334+
13271335
//---- class TestIcon -----------------------------------------------------
13281336

13291337
@SuppressWarnings( "EqualsHashCode" ) // Error Prone

flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyling.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
import java.awt.Dimension;
2424
import java.awt.Graphics;
2525
import java.awt.Insets;
26+
import java.util.Collections;
2627
import java.util.HashMap;
28+
import java.util.HashSet;
2729
import java.util.Map;
30+
import java.util.Set;
2831
import java.util.function.Consumer;
2932
import javax.swing.*;
3033
import javax.swing.table.JTableHeader;
@@ -50,6 +53,14 @@ static void setup() {
5053
FlatLaf.setGlobalExtraDefaults( globalExtraDefaults );
5154

5255
TestUtils.setup( false );
56+
57+
Set<String> excludes = new HashSet<>();
58+
Collections.addAll( excludes,
59+
"parse", "parseIfFunction", "parseColorFunctions",
60+
"parseReferences", "parseVariables", "parseRecursiveVariables",
61+
"enumField", "enumProperty", "enumUIDefaults" );
62+
TestUtils.checkImplementedTests( excludes, TestFlatStyling.class,
63+
TestFlatStyleableValue.class, TestFlatStyleableInfo.class );
5364
}
5465

5566
@AfterAll
@@ -1365,6 +1376,16 @@ void flatRoundBorder() {
13651376
border.applyStyleProperty( "arc", 6 );
13661377
}
13671378

1379+
@Test
1380+
void flatScrollPaneBorder() {
1381+
FlatScrollPaneBorder border = new FlatScrollPaneBorder();
1382+
1383+
// FlatScrollPaneBorder extends FlatBorder
1384+
flatBorder( border );
1385+
1386+
border.applyStyleProperty( "arc", 6 );
1387+
}
1388+
13681389
@Test
13691390
void flatTextBorder() {
13701391
FlatTextBorder border = new FlatTextBorder();
@@ -1564,6 +1585,13 @@ private void flatSearchIcon( FlatSearchIcon icon ) {
15641585
icon.applyStyleProperty( "searchIconPressedColor", Color.WHITE );
15651586
}
15661587

1588+
@Test
1589+
void flatCapsLockIcon() {
1590+
FlatCapsLockIcon icon = new FlatCapsLockIcon();
1591+
1592+
icon.applyStyleProperty( "capsLockIconColor", Color.WHITE );
1593+
}
1594+
15671595
//---- enums --------------------------------------------------------------
15681596

15691597
enum SomeEnum { enumValue1, enumValue2 }

flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestUtils.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
package com.formdev.flatlaf.ui;
1818

1919
import java.awt.Font;
20+
import java.lang.reflect.Method;
21+
import java.util.HashSet;
2022
import java.util.Map;
2123
import java.util.Objects;
24+
import java.util.Set;
25+
import java.util.TreeMap;
2226
import javax.swing.UIManager;
27+
import org.junit.jupiter.api.Test;
2328
import org.opentest4j.AssertionFailedError;
2429
import com.formdev.flatlaf.FlatIntelliJLaf;
2530
import com.formdev.flatlaf.FlatLightLaf;
@@ -57,12 +62,44 @@ public static void resetFont() {
5762

5863
public static void assertMapEquals( Map<?, ?> expected, Map<?, ?> actual ) {
5964
if( !Objects.equals( expected, actual ) ) {
60-
String expectedStr = String.valueOf( expected ).replace( ", ", ",\n" );
61-
String actualStr = String.valueOf( actual ).replace( ", ", ",\n" );
65+
String expectedStr = String.valueOf( new TreeMap<>( expected ) ).replace( ", ", ",\n" );
66+
String actualStr = String.valueOf( new TreeMap<>( actual ) ).replace( ", ", ",\n" );
6267
String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr );
6368

6469
// pass expected/actual strings to exception for nice diff in IDE
6570
throw new AssertionFailedError( msg, expectedStr, actualStr );
6671
}
6772
}
73+
74+
public static void checkImplementedTests( Set<String> excludes, Class<?> baseClass, Class<?>... classes ) {
75+
Set<String> expected = getTestMethods( baseClass );
76+
77+
for( Class<?> cls : classes ) {
78+
Set<String> actual = getTestMethods( cls );
79+
80+
for( String methodName : expected ) {
81+
if( !actual.contains( methodName ) && !excludes.contains( methodName ) ) {
82+
throw new AssertionFailedError( "missing " + cls.getSimpleName() + '.' + methodName
83+
+ "() for " + baseClass.getSimpleName() + '.' + methodName + "()" );
84+
}
85+
}
86+
87+
for( String methodName : actual ) {
88+
if( !expected.contains( methodName ) && !excludes.contains( methodName ) ) {
89+
throw new AssertionFailedError( "missing " + baseClass.getSimpleName() + '.' + methodName
90+
+ "() for " + cls.getSimpleName() + '.' + methodName + "()" );
91+
}
92+
}
93+
}
94+
}
95+
96+
private static Set<String> getTestMethods( Class<?> cls ) {
97+
HashSet<String> tests = new HashSet<>();
98+
Method[] methods = cls.getDeclaredMethods();
99+
for( Method m : methods ) {
100+
if( m.isAnnotationPresent( Test.class ) )
101+
tests.add( m.getName() );
102+
}
103+
return tests;
104+
}
68105
}

0 commit comments

Comments
 (0)