stokpop commented on a change in pull request #696:
URL: https://github.com/apache/jmeter/pull/696#discussion_r793040752



##########
File path: 
src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
##########
@@ -41,7 +45,37 @@ public void testSetLanguage() {
             textArea.setLanguage(null);
             assertEquals(SyntaxConstants.SYNTAX_STYLE_NONE, 
textArea.getSyntaxEditingStyle());
         } catch (HeadlessException he) {
-            // Does not work in headless mode
+            // Does not work in headless mode, which depends on value of 
java.awt.headless property
+            // and the OS (e.g. might work on MacOS and not on Linux due to 
missing X11).

Review comment:
       How I got here: I have Kotlin code (to generate a jmx file based on 
open-api spec) that calls setText() and getText() for the json payload. When 
running from Kotlin code on MacOS laptop, the code runs fine in Intellij: 
getText() returns a value. When running it from Kotlin _script_, the getText() 
returns null after setText(). Why? Debugging shows that 
`java.awt.headless=true` when running Kotlin _script_. When running Kotlin code 
the `java.awt.headless` property is not present, so does not run headless. (In 
that case it I guess it might work because 
`awt.toolkit=sun.lwawt.macosx.LWCToolkit` is present). Then on linux docker 
(target system) running non-headless does not work because it says no DISPLAY 
is set (awt.toolkit is missing?). And running headless (with 
`java.awt.headless=true`), the getText() returns null. 

##########
File path: 
src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
##########
@@ -41,7 +45,37 @@ public void testSetLanguage() {
             textArea.setLanguage(null);
             assertEquals(SyntaxConstants.SYNTAX_STYLE_NONE, 
textArea.getSyntaxEditingStyle());
         } catch (HeadlessException he) {
-            // Does not work in headless mode
+            // Does not work in headless mode, which depends on value of 
java.awt.headless property
+            // and the OS (e.g. might work on MacOS and not on Linux due to 
missing X11).
+            System.out.println("WARNING for 
JSyntaxTextAreaTest.testSetLanguage test: does not work in headless mode");
+        }
+    }
+
+    @Test
+    public void testHeadless() {
+        String key = "java.awt.headless";
+        String initialValue = System.getProperty(key);
+        try {
+            System.setProperty(key, "true");

Review comment:
       Maybe there is a better way? It is indeed tricky as it might impact 
other tests, that's why the `@Isolated` is added. The code directly depends on 
the property value in its behaviour. I've seen some mock framework code that 
overrides the System.getProperty() to return a certain value, but there might 
be classloading issues. 




-- 
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