[ 
https://issues.apache.org/jira/browse/GROOVY-12376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112181#comment-18112181
 ] 

ASF GitHub Bot commented on GROOVY-12376:
-----------------------------------------

paulk-asert commented on code in PR #2899:
URL: https://github.com/apache/groovy/pull/2899#discussion_r3947159284


##########
subprojects/groovy-swing/src/test/groovy/groovy/swing/LookAndFeelHelperThemeTest.groovy:
##########
@@ -0,0 +1,65 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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
+ *
+ *    http://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 groovy.swing
+
+import org.junit.jupiter.api.Test
+
+import javax.swing.plaf.metal.DefaultMetalTheme
+import javax.swing.plaf.metal.MetalLookAndFeel
+
+import static groovy.test.GroovyAssert.shouldFail
+
+class LookAndFeelHelperThemeTest {
+
+    // the Metal 'theme' attribute handler; invoked directly so the test does 
not
+    // touch UIManager and therefore runs headless
+    private static metalThemeHandler() {
+        
LookAndFeelHelper.instance.@extendedAttributes['javax.swing.plaf.metal.MetalLookAndFeel'].theme
+    }
+
+    @Test
+    void rejectsNonMetalThemeClassWithoutConstructingIt() {
+        ThemeProbeFlag.constructed = false
+        def handler = metalThemeHandler()
+        shouldFail(IllegalArgumentException) {
+            handler(null, 'groovy.swing.NonMetalThemeProbe')
+        }
+        assert !ThemeProbeFlag.constructed: 'a non-MetalTheme class must not 
be constructed'
+    }
+
+    @Test
+    void acceptsMetalThemeSubclass() {
+        def handler = metalThemeHandler()
+        handler(null, 'groovy.swing.CustomMetalThemeProbe')
+        assert MetalLookAndFeel.currentTheme instanceof CustomMetalThemeProbe

Review Comment:
   Good thinking. I did the same using @Before/AfterEach.





> LookAndFeelHelper: detect non-metal classes rather than fail with an obscure 
> error
> ----------------------------------------------------------------------------------
>
>                 Key: GROOVY-12376
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12376
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to