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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to