This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new 2ca7cf9 Keep JSyntaxTextArea text value for use in headless mode
2ca7cf9 is described below
commit 2ca7cf98cba881298220f4ce06445ff7883f5ba9
Author: Peter Paul Bakker <[email protected]>
AuthorDate: Mon Jan 17 16:15:05 2022 +0100
Keep JSyntaxTextArea text value for use in headless mode
Closes #696
---
.../apache/jmeter/gui/util/JSyntaxTextArea.java | 11 ++++++-
.../jmeter/gui/util/JSyntaxTextAreaTest.java | 36 ++++++++++++++++++++--
xdocs/changes.xml | 2 ++
3 files changed, 45 insertions(+), 4 deletions(-)
diff --git
a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
index 4b6d629..b0bd5c0 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
@@ -101,6 +101,7 @@ public class JSyntaxTextArea extends RSyntaxTextArea {
// Allow override for unit testing only
if ("true".equals(System.getProperty("java.awt.headless"))) { //
$NON-NLS-1$ $NON-NLS-2$
return new JSyntaxTextArea(disableUndo) {
+ private String savedText = "";
private static final long serialVersionUID = 1L;
@Override
protected void init() {
@@ -118,7 +119,15 @@ public class JSyntaxTextArea extends RSyntaxTextArea {
@Override
public void discardAllEdits() { }
@Override
- public void setText(String t) { }
+ public void setText(String t) {
+ savedText = t;
+ }
+
+ @Override
+ public String getText() {
+ return savedText;
+ }
+
@Override
public boolean isCodeFoldingEnabled(){ return true; }
};
diff --git
a/src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
b/src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
index 149edc3..5e4d5cc 100644
--- a/src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
+++ b/src/core/src/test/java/org/apache/jmeter/gui/util/JSyntaxTextAreaTest.java
@@ -17,8 +17,8 @@
package org.apache.jmeter.gui.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.awt.HeadlessException;
import java.lang.reflect.Field;
@@ -30,7 +30,11 @@ import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.util.JMeterUtils;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Isolated;
+// should not run in parallel due to using a System property that can impact
+// other tests
+@Isolated
public class JSyntaxTextAreaTest extends JMeterTestCase {
@Test
@@ -41,7 +45,33 @@ public class JSyntaxTextAreaTest extends JMeterTestCase {
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 testHeadlessGetText() {
+ String key = "java.awt.headless";
+ String initialValue = System.getProperty(key);
+ try {
+ System.setProperty(key, "true");
+ // getInstance() returns anonymous class with some overridden
methods
+ // to avoid errors due to 'java.awt.headless=true'.
+ // E.g. it should not throw a HeadlessException.
+ JSyntaxTextArea textArea = JSyntaxTextArea.getInstance(10,20);
+
+ String myText = "my text";
+ textArea.setText(myText);
+ assertEquals(myText, textArea.getText());
+ } finally {
+ if (initialValue != null) {
+ System.setProperty(key, initialValue);
+ }
+ else {
+ System.clearProperty(key);
+ }
}
}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 5f9dbee..2a63a54 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -287,6 +287,7 @@ however, the profile can't be updated while the test is
running.
<li><bug>65336</bug>Blank labels when different elements had the same
name</li>
<li><bug>65522</bug>Restart doesn't work, when parameters contain spaces</li>
<li><bug>63914</bug>Simplify <code>:src:dist:clean</code> configuration,
ensure <code>/lib/junit/test.jar</code> is removed on clean</li>
+ <li><pr>696</pr>Keep JSyntaxTextArea text value for use in headless mode.
Contributed by Peter Paul Bakker (peter.paul.bakker at stokpop.nl)</li>
</ul>
<!-- =================== Thanks =================== -->
@@ -313,6 +314,7 @@ however, the profile can't be updated while the test is
running.
<li>Piotr Smietana (piotrsmietana1998 at gmail.com)</li>
<li>Sampath Kumar Krishnasamy (sampathkumar.krishnasamykuppusamy at
aexp.com)</li>
<li>Ji Hun (jihunkimkw at gmail.com)</li>
+ <li>Peter Paul Bakker (peter.paul.bakker at stokpop.nl)</li>
</ul>
<p>We also thank bug reporters who helped us improve JMeter.</p>
<ul>