From 7eb642dd13d394750f466ad78dfe69f0fae2ea88 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Wed, 16 Jun 2021 21:23:57 +0200 Subject: [PATCH] Styling: added simple unit tests --- flatlaf-core/build.gradle.kts | 9 ++ .../formdev/flatlaf/ui/FlatStylingTests.java | 91 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java diff --git a/flatlaf-core/build.gradle.kts b/flatlaf-core/build.gradle.kts index 01f7576c..19db78cc 100644 --- a/flatlaf-core/build.gradle.kts +++ b/flatlaf-core/build.gradle.kts @@ -21,6 +21,11 @@ plugins { `flatlaf-publish` } +dependencies { + testImplementation( "org.junit.jupiter:junit-jupiter-api:5.7.2" ) + testRuntimeOnly( "org.junit.jupiter:junit-jupiter-engine" ) +} + java { withSourcesJar() withJavadocJar() @@ -52,6 +57,10 @@ tasks { named( "javadocJar" ) { archiveBaseName.set( "flatlaf" ) } + + test { + useJUnitPlatform() + } } flatlafPublish { diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java new file mode 100644 index 00000000..8f232bf4 --- /dev/null +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/FlatStylingTests.java @@ -0,0 +1,91 @@ +/* + * Copyright 2021 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.ui; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; + +/** + * @author Karl Tauber + */ +public class FlatStylingTests +{ + @Test + void parse() { + assertEquals( null, FlatStyleSupport.parse( null ) ); + assertEquals( null, FlatStyleSupport.parse( "" ) ); + assertEquals( null, FlatStyleSupport.parse( " " ) ); + assertEquals( null, FlatStyleSupport.parse( ";" ) ); + assertEquals( null, FlatStyleSupport.parse( " ; ; " ) ); + + assertEquals( + expectedMap( "background", Color.WHITE ), + FlatStyleSupport.parse( "background: #fff" ) ); + assertEquals( + expectedMap( "background", Color.WHITE, "foreground", Color.BLACK ), + FlatStyleSupport.parse( "background: #fff; foreground: #000" ) ); + assertEquals( + expectedMap( "background", Color.WHITE, "foreground", Color.BLACK, "someWidth", 20 ), + FlatStyleSupport.parse( "background: #fff; foreground: #000; someWidth: 20" ) ); + } + + private Map expectedMap( Object... keyValuePairs ) { + Map map = new HashMap<>(); + for( int i = 0; i < keyValuePairs.length; i += 2 ) + map.put( keyValuePairs[i], keyValuePairs[i+1] ); + return map; + } + + @Test + void checkbox() { + FlatCheckBoxUI ui = new FlatCheckBoxUI( false ); + + ui.applyStyle( "disabledText: #fff" ); + } + + @Test + void radiobutton() { + FlatRadioButtonUI ui = new FlatRadioButtonUI( false ); + + ui.applyStyle( "disabledText: #fff" ); + } + + @Test + void slider() { + FlatSliderUI ui = new FlatSliderUI(); + + ui.applyStyle( "trackWidth: 2" ); + ui.applyStyle( "thumbSize: 12,12" ); + ui.applyStyle( "focusWidth: 4" ); + + ui.applyStyle( "trackValueColor: #fff" ); + ui.applyStyle( "trackColor: #fff" ); + ui.applyStyle( "thumbColor: #fff" ); + ui.applyStyle( "thumbBorderColor: #fff" ); + ui.applyStyle( "focusedColor: #fff" ); + ui.applyStyle( "focusedThumbBorderColor: #fff" ); + ui.applyStyle( "hoverThumbColor: #fff" ); + ui.applyStyle( "pressedThumbColor: #fff" ); + ui.applyStyle( "disabledTrackColor: #fff" ); + ui.applyStyle( "disabledThumbColor: #fff" ); + ui.applyStyle( "disabledThumbBorderColor: #fff" ); + ui.applyStyle( "tickColor: #fff" ); + } +}