diff --git a/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingTest.java b/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingTest.java index ae8dd3f6c09..3787dba816f 100644 --- a/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingTest.java +++ b/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/BidirectionalBindingTest.java @@ -25,19 +25,35 @@ package test.com.sun.javafx.binding; -import com.sun.javafx.binding.BidirectionalBinding; -import javafx.beans.binding.Bindings; -import javafx.beans.property.*; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collection; +import javafx.beans.binding.Bindings; +import javafx.beans.property.Property; +import javafx.beans.property.ReadOnlyBooleanWrapper; +import javafx.beans.property.ReadOnlyDoubleWrapper; +import javafx.beans.property.ReadOnlyFloatWrapper; +import javafx.beans.property.ReadOnlyIntegerWrapper; +import javafx.beans.property.ReadOnlyLongWrapper; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleLongProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; import javafx.beans.value.ObservableValue; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import com.sun.javafx.binding.BidirectionalBinding; +import test.javafx.util.OutputRedirect; public class BidirectionalBindingTest { @@ -69,6 +85,16 @@ public T[] getValues() { private Property op4; private T[] v; + @BeforeEach + public void beforeEach() { + OutputRedirect.suppressStderr(); + } + + @AfterEach + public void afterEach() { + OutputRedirect.checkAndRestoreStderr(); + } + private void setUp(Factory factory) { this.factory = factory; op1 = factory.createProperty(); @@ -305,6 +331,8 @@ public void testBrokenBind(Factory factory) { op2.setValue(v[2]); assertEquals(op3.getValue(), op1.getValue()); assertEquals(op2.getValue(), op1.getValue()); + + OutputRedirect.checkAndRestoreStderr(RuntimeException.class); } @ParameterizedTest @@ -325,6 +353,8 @@ public void testDoubleBrokenBind(Factory factory) { assertEquals(op3.getValue(), op1.getValue()); assertEquals(v[0], op1.getValue()); assertEquals(v[1], op2.getValue()); + + OutputRedirect.checkAndRestoreStderr(RuntimeException.class); } @ParameterizedTest diff --git a/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperTest.java b/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperTest.java index ac31894ea27..45c64cd09ff 100644 --- a/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperTest.java +++ b/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/ExpressionHelperTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,22 +27,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows; - - +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.BitSet; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import com.sun.javafx.binding.ExpressionHelper; -import com.sun.javafx.binding.ExpressionHelperShim; - import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.property.ObjectProperty; @@ -52,10 +43,15 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValueStub; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import com.sun.javafx.binding.ExpressionHelper; +import com.sun.javafx.binding.ExpressionHelperShim; import test.javafx.beans.InvalidationListenerMock; import test.javafx.beans.WeakInvalidationListenerMock; import test.javafx.beans.value.ChangeListenerMock; import test.javafx.beans.value.WeakChangeListenerMock; +import test.javafx.util.OutputRedirect; import test.util.memory.JMemoryBuddy; public class ExpressionHelperTest { @@ -566,7 +562,13 @@ public void testExceptionNotPropagatedFromMultipleInvalidation() { public void testExceptionNotPropagatedFromSingleChange() { helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {throw new RuntimeException();}); observable.set(null); - ExpressionHelperShim.fireValueChangedEvent(helper); + + OutputRedirect.suppressStderr(); + try { + ExpressionHelperShim.fireValueChangedEvent(helper); + } finally { + OutputRedirect.checkAndRestoreStderr(RuntimeException.class); + } } @Test @@ -576,7 +578,13 @@ public void testExceptionNotPropagatedFromMultipleChange() { helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(0); throw new RuntimeException();}); helper = ExpressionHelper.addListener(helper, observable, (value, o1, o2) -> {called.set(1); throw new RuntimeException();}); observable.set(null); - ExpressionHelperShim.fireValueChangedEvent(helper); + + OutputRedirect.suppressStderr(); + try { + ExpressionHelperShim.fireValueChangedEvent(helper); + } finally { + OutputRedirect.checkAndRestoreStderr(RuntimeException.class, RuntimeException.class); + } assertTrue(called.get(0)); assertTrue(called.get(1)); diff --git a/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/SelectBindingTest.java b/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/SelectBindingTest.java index 6a28697ccf2..f2152c1daba 100644 --- a/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/SelectBindingTest.java +++ b/modules/javafx.base/src/test/java/test/com/sun/javafx/binding/SelectBindingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,13 +24,17 @@ */ package test.com.sun.javafx.binding; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; -import test.javafx.beans.Person; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; import javafx.beans.binding.DoubleBinding; @@ -39,13 +43,14 @@ import javafx.beans.binding.LongBinding; import javafx.beans.binding.ObjectBinding; import javafx.beans.binding.StringBinding; -import test.javafx.binding.Variable; import javafx.collections.ObservableList; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; +import test.javafx.beans.Person; +import test.javafx.binding.Variable; +import test.javafx.util.OutputRedirect; public class SelectBindingTest { @@ -103,12 +108,13 @@ public void removePropertyChangeListener(String property, PropertyChangeListener @BeforeAll public static void setUpClass() { - System.err.println("SelectBindingTest : log messages are expected from these tests."); ErrorLoggingUtiltity.reset(); } @BeforeEach - public void setUp() throws Exception { + public void setUp() { + OutputRedirect.suppressStderr(); + a = new Variable("a"); b = new Variable("b"); c = new Variable("c"); @@ -119,6 +125,11 @@ public void setUp() throws Exception { dependencies = select.getDependencies(); } + @AfterEach + public void afterEach() { + OutputRedirect.checkAndRestoreStderr(); + } + @Test public void testObject() { final Person person1 = new Person(); @@ -397,6 +408,7 @@ public void createWithNoSteps() { a.setName(null); assertNull(select.get()); ErrorLoggingUtiltity.checkWarning(NullPointerException.class); + OutputRedirect.checkAndRestoreStderr(NullPointerException.class); } @Test diff --git a/modules/javafx.base/src/test/java/test/javafx/binding/BindingsCreateBindingTest.java b/modules/javafx.base/src/test/java/test/javafx/binding/BindingsCreateBindingTest.java index a96245b6937..16ecafc0a00 100644 --- a/modules/javafx.base/src/test/java/test/javafx/binding/BindingsCreateBindingTest.java +++ b/modules/javafx.base/src/test/java/test/javafx/binding/BindingsCreateBindingTest.java @@ -25,6 +25,8 @@ package test.javafx.binding; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Collection; import java.util.concurrent.Callable; @@ -39,14 +41,13 @@ import javafx.beans.property.SimpleLongProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; -import test.com.sun.javafx.binding.ErrorLoggingUtiltity; - +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; - -import static org.junit.jupiter.api.Assertions.*; +import test.com.sun.javafx.binding.ErrorLoggingUtiltity; +import test.javafx.util.OutputRedirect; /** */ @@ -72,6 +73,16 @@ public static void setUpClass() { ErrorLoggingUtiltity.reset(); } + @BeforeEach + public void beforeEach() { + OutputRedirect.suppressStderr(); + } + + @AfterEach + public void afterEach() { + OutputRedirect.checkAndRestoreStderr(); + } + private void setup(Property p0, Property p1, Functions f, T value0, T value1, T defaultValue) { this.p0 = p0; this.p1 = p1; diff --git a/modules/javafx.base/src/test/java/test/javafx/util/AccumulatingPrintStream.java b/modules/javafx.base/src/test/java/test/javafx/util/AccumulatingPrintStream.java new file mode 100644 index 00000000000..1001b555aa7 --- /dev/null +++ b/modules/javafx.base/src/test/java/test/javafx/util/AccumulatingPrintStream.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.javafx.util; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +/** + * PrintStream that accumulates output in memory. + */ +public class AccumulatingPrintStream extends PrintStream { + + private final ByteArrayOutputStream out; + + private AccumulatingPrintStream(ByteArrayOutputStream out) { + super(out); + this.out = out; + } + + public static AccumulatingPrintStream create() { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + return new AccumulatingPrintStream(out); + } + + public String getAccumulatedOutput() { + byte[] b = out.toByteArray(); + return new String(b, charset()); + } +} diff --git a/modules/javafx.base/src/test/java/test/javafx/util/OutputRedirect.java b/modules/javafx.base/src/test/java/test/javafx/util/OutputRedirect.java new file mode 100644 index 00000000000..0eac968223a --- /dev/null +++ b/modules/javafx.base/src/test/java/test/javafx/util/OutputRedirect.java @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.javafx.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import java.io.PrintStream; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.junit.jupiter.api.Test; + +/// This facility is used in the tests to redirect stderr output to an in-memory buffer +/// for two reasons: +/// 1. to suppress unrelated output in the logs +/// 2. to check for the presence of expected exceptions and patterns +/// +public class OutputRedirect { + private static PrintStream stderr; + private static AccumulatingPrintStream stderrCapture; + + /// Redirects the stderr to an internal buffer, for the purpose of avoiding polluting the test logs. + /// This method is typically placed inside of the `@BeforeEach` block. + /// + /// Once the test is finished, the output can be checked for thrown exceptions using {@link #checkStderr(Class...)}. + /// or {@link #checkAndRestoreStderr(Class...)}. + /// + /// The redirection needs to be undone by calling either {@link #restoreStderr()} or + /// {@link #checkAndRestoreStderr(Class...)} method. + /// + public static void suppressStderr() { + if (stderrCapture == null) { + stderr = System.err; + stderrCapture = AccumulatingPrintStream.create(); + System.setErr(stderrCapture); + } + } + + /// Restores stderr redirection (typically done inside of a `@AfterEach` block). + /// It is safe to call this method multiple times. + public static void restoreStderr() { + if (stderr != null) { + System.setErr(stderr); + stderr = null; + stderrCapture = null; + } + } + + /// Checks the accumulated stderr buffer for the expected exceptions and string patterns. + /// + /// This method expects the arguments to contain either instances of `Class`, + /// or `String` patterns. For exceptions, multiple instances of the same type are allowed so both the type + /// and a number of exceptions can be verified. + /// + /// For `String` patterns, the check is done via `String.contains()` on the entire captured output. + /// + /// When mismatch occurs, the accumulated output is dumped to the actual stderr, and the test `fail()`s. + /// + /// @param expected the expected exception classes (duplicates allowed), and/or string patterns + /// + public static void checkStderr(Object ... expected) { + if (stderrCapture != null) { + boolean err = false; + String text = stderrCapture.getAccumulatedOutput(); + + // exceptions + Map errors = findErrors(text); + Map exp = toMap(expected); + if (!errors.equals(exp)) { + stderr.println("Mismatch in thrown exceptions:\n expected=" + exp + "\n observed=" + errors); + err = true; + } + + // patterns + for (Object x : expected) { + if (x instanceof String s) { + if (!text.contains(s)) { + stderr.println("Expected pattern not found: " + s); + err = true; + } + } + } + + if (err) { + stderr.println(text); + // mismatch fails the test + fail("Unexpected stderr output"); + } + } + } + + /// Checks the accumulated stderr buffer for the expected exceptions and string patterns, + /// then restores the redirection. + /// + /// This method is equivalent to calling {@link #checkStderr(Object...)} followed by + /// {@link #restoreStderr()}. + /// + /// @param expected the expected exception classes (duplicates allowed), and/or string patterns + /// + public static void checkAndRestoreStderr(Object ... expected) { + try { + checkStderr(expected); + } finally { + restoreStderr(); + } + } + + private static Map toMap(Object... expected) { + HashMap m = new HashMap<>(); + for (Object x : expected) { + if (x instanceof Class c) { + if (Throwable.class.isAssignableFrom(c)) { + String name = c.getName(); + Integer v = m.get(name); + if (v == null) { + m.put(name, Integer.valueOf(1)); + } else { + m.put(name, Integer.valueOf(v + 1)); + } + } else { + throw new IllegalArgumentException("must specify Class: " + c); + } + } else if (x instanceof String) { + // ok + } else { + throw new IllegalArgumentException("must specify either Class or String: " + x); + } + } + return m; + } + + private static Map findErrors(String text) { + HashMap m = new HashMap<>(); + text.lines(). + map((s) -> findException(s)). + filter((c) -> c != null). + forEach((c) -> { + Integer v = m.get(c); + if (v == null) { + m.put(c, Integer.valueOf(1)); + } else { + m.put(c, Integer.valueOf(v + 1)); + } + }); + return m; + } + + /// This regex matches either of the two patterns which might appear in the output: + /// + /// `Exception in thread "main" java.lang.RuntimeException:` + /// + /// or + /// + /// `java.lang.NullPointerException: ...` + private static final Pattern EXCEPTION_PATTERN = Pattern.compile( + "(?:" + + // catches lines starting with things like "Exception in thread "main" java.lang.RuntimeException:" + "^" + // start of line + "(?:" + // non-capturing group + "Exception in thread\s+\"[^\"]*\"\\s+" + + "(" + // capture group 1 + "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*" + + "(?:" + + "(?:[A-Z][a-zA-Z0-9]*)*" + + "(?:Exception|Error)" + + ")" + + ")" + + ")" + + ")" + + "|" + // or + "(?:" + + // catches lines starting with things like "java.lang.NullPointerException: Cannot invoke..." + "^" + + "(" + // capture group 2 + "(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*" + + "(?:[A-Z][a-zA-Z0-9]*)*" + + "(?:Exception|Error)" + + ")" + + ")"); + + private static String findException(String text) { + Matcher m = EXCEPTION_PATTERN.matcher(text); + String name; + if (m.find()) { + name = m.group(1); + if (name == null) { + name = m.group(2); + } + return name; + } + return null; + } + + @Test + public void testFindException() { + t("Exception in thread \"main\" java.lang.Error", "java.lang.Error"); + t("Exception in thread \"main\" java.lang.RuntimeException: blah blah", "java.lang.RuntimeException"); + t("java.lang.NullPointerException: Cannot invoke \"Object.toString(", "java.lang.NullPointerException"); + t(" at javafx.base/com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:392)", null); + } + + private void t(String text, String expected) { + String s = findException(text); + assertEquals(expected, s); + } +} diff --git a/modules/javafx.base/src/test/java/test/util/ReflectionUtils.java b/modules/javafx.base/src/test/java/test/javafx/util/ReflectionUtils.java similarity index 99% rename from modules/javafx.base/src/test/java/test/util/ReflectionUtils.java rename to modules/javafx.base/src/test/java/test/javafx/util/ReflectionUtils.java index 645fb3e15f5..4da60a51243 100644 --- a/modules/javafx.base/src/test/java/test/util/ReflectionUtils.java +++ b/modules/javafx.base/src/test/java/test/javafx/util/ReflectionUtils.java @@ -23,7 +23,7 @@ * questions. */ -package test.util; +package test.javafx.util; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; diff --git a/modules/javafx.fxml/.classpath b/modules/javafx.fxml/.classpath index baa51d5e361..ce92f414ca5 100644 --- a/modules/javafx.fxml/.classpath +++ b/modules/javafx.fxml/.classpath @@ -32,7 +32,7 @@ - + diff --git a/modules/javafx.fxml/src/test/java/test/javafx/fxml/RT_27529Test.java b/modules/javafx.fxml/src/test/java/test/javafx/fxml/RT_27529Test.java index a30cdc6fa66..3797d9ed1af 100644 --- a/modules/javafx.fxml/src/test/java/test/javafx/fxml/RT_27529Test.java +++ b/modules/javafx.fxml/src/test/java/test/javafx/fxml/RT_27529Test.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,16 +25,19 @@ package test.javafx.fxml; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.net.URL; import java.util.Arrays; import java.util.ResourceBundle; import javafx.fxml.FXMLLoader; import org.junit.jupiter.api.Test; +import test.javafx.util.OutputRedirect; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - +/** + * https://bugs.openjdk.org/browse/JDK-8119985 + */ public class RT_27529Test { @Test @@ -50,14 +53,26 @@ public void testListAndArrayWithResources() throws IOException { @Test public void testListAndArrayWithEscapes() throws IOException { - System.err.println("Below warnings about - deprecated escape sequence - are expected from this test."); - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("rt_27529_2.fxml"), - ResourceBundle.getBundle("test/javafx/fxml/rt_27529")); - fxmlLoader.load(); + OutputRedirect.suppressStderr(); + try { + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("rt_27529_2.fxml"), + ResourceBundle.getBundle("test/javafx/fxml/rt_27529")); + fxmlLoader.load(); - Widget widget = (Widget)fxmlLoader.getNamespace().get("widget1"); - assertEquals(Arrays.asList(new String[]{"@a", "%b", "$c", "@c", "%d", "$e"}), widget.getStyles()); - assertTrue(Arrays.equals( new String[]{"@a", "%b", "$c", "@c", "%d", "$e"}, widget.getNames())); + Widget widget = (Widget)fxmlLoader.getNamespace().get("widget1"); + assertEquals(Arrays.asList(new String[]{"@a", "%b", "$c", "@c", "%d", "$e"}), widget.getStyles()); + assertTrue(Arrays.equals( new String[]{"@a", "%b", "$c", "@c", "%d", "$e"}, widget.getNames())); + OutputRedirect.checkStderr( + "@@ is a deprecated escape sequence. Please use \\@ instead.", + "%% is a deprecated escape sequence. Please use \\% instead.", + "$$ is a deprecated escape sequence. Please use \\$ instead.", + "@@ is a deprecated escape sequence. Please use \\@ instead.", + "%% is a deprecated escape sequence. Please use \\% instead.", + "$$ is a deprecated escape sequence. Please use \\$ instead." + ); + } finally { + OutputRedirect.restoreStderr(); + } } @Test diff --git a/modules/javafx.graphics/.classpath b/modules/javafx.graphics/.classpath index 9cb07d59136..750790720c0 100644 --- a/modules/javafx.graphics/.classpath +++ b/modules/javafx.graphics/.classpath @@ -31,7 +31,7 @@ - + diff --git a/modules/javafx.graphics/src/test/java/test/com/sun/glass/ui/HeaderButtonOverlayTest.java b/modules/javafx.graphics/src/test/java/test/com/sun/glass/ui/HeaderButtonOverlayTest.java index 06a8be9dcdc..bd45ce99b82 100644 --- a/modules/javafx.graphics/src/test/java/test/com/sun/glass/ui/HeaderButtonOverlayTest.java +++ b/modules/javafx.graphics/src/test/java/test/com/sun/glass/ui/HeaderButtonOverlayTest.java @@ -28,6 +28,7 @@ import com.sun.glass.events.MouseEvent; import com.sun.glass.ui.HeaderButtonOverlay; import com.sun.javafx.binding.ObjectConstant; +import test.javafx.util.ReflectionUtils; import javafx.beans.value.ObservableValue; import javafx.geometry.Dimension2D; import javafx.geometry.NodeOrientation; @@ -40,7 +41,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import test.util.ReflectionUtils; import java.nio.charset.StandardCharsets; import java.util.Base64; diff --git a/modules/javafx.graphics/src/test/java/test/javafx/css/StyleableProperty_transition_Test.java b/modules/javafx.graphics/src/test/java/test/javafx/css/StyleableProperty_transition_Test.java index 8c49d828162..77cef9a2234 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/css/StyleableProperty_transition_Test.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/css/StyleableProperty_transition_Test.java @@ -72,7 +72,7 @@ import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.*; -import static test.util.ReflectionUtils.*; +import static test.javafx.util.ReflectionUtils.*; public class StyleableProperty_transition_Test { diff --git a/modules/javafx.graphics/src/test/java/test/javafx/scene/layout/HeaderBarTest.java b/modules/javafx.graphics/src/test/java/test/javafx/scene/layout/HeaderBarTest.java index 866b79c5fe9..7732f6a58b7 100644 --- a/modules/javafx.graphics/src/test/java/test/javafx/scene/layout/HeaderBarTest.java +++ b/modules/javafx.graphics/src/test/java/test/javafx/scene/layout/HeaderBarTest.java @@ -46,8 +46,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import test.com.sun.javafx.pgstub.StubScene; -import test.util.ReflectionUtils; - +import test.javafx.util.ReflectionUtils; import static org.junit.jupiter.api.Assertions.*; @SuppressWarnings("deprecation") diff --git a/tests/system/src/test/.classpath b/tests/system/src/test/.classpath index 6b29c22e703..66f8ed8bd71 100644 --- a/tests/system/src/test/.classpath +++ b/tests/system/src/test/.classpath @@ -8,7 +8,7 @@ - + diff --git a/tests/system/src/test/java/test/com/sun/javafx/application/ListenerTestCommon.java b/tests/system/src/test/java/test/com/sun/javafx/application/ListenerTestCommon.java index cfb91ebeddc..797043b3fd1 100644 --- a/tests/system/src/test/java/test/com/sun/javafx/application/ListenerTestCommon.java +++ b/tests/system/src/test/java/test/com/sun/javafx/application/ListenerTestCommon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,6 +41,7 @@ import javafx.stage.Stage; import com.sun.javafx.application.PlatformImpl; import com.sun.javafx.application.PlatformImplShim; +import test.javafx.util.OutputRedirect; import test.util.Util; /** @@ -158,8 +159,24 @@ public void doTestExit() { listener = null; } - public void doTestIdleImplicit(final boolean implicit, - final ThrowableType throwableType) { + public void doTestIdleImplicit(boolean implicit, ThrowableType throwableType) { + Object[] expected = switch(throwableType) { + case ERROR -> + new Object[] { InternalError.class }; + case EXCEPTION -> + new Object[] { RuntimeException.class }; + case NONE -> + new Object[0]; + }; + OutputRedirect.suppressStderr(); + try { + doTestIdleImplicit2(implicit, throwableType); + } finally { + OutputRedirect.checkAndRestoreStderr(expected); + } + } + + private void doTestIdleImplicit2(boolean implicit, ThrowableType throwableType) { setup(); assertNotNull(listener); diff --git a/tests/system/src/test/java/test/com/sun/javafx/application/PlatformStartupCommon.java b/tests/system/src/test/java/test/com/sun/javafx/application/PlatformStartupCommon.java index 93c503dd15d..aa2a483f4db 100644 --- a/tests/system/src/test/java/test/com/sun/javafx/application/PlatformStartupCommon.java +++ b/tests/system/src/test/java/test/com/sun/javafx/application/PlatformStartupCommon.java @@ -39,6 +39,7 @@ import javafx.scene.paint.Color; import javafx.stage.Stage; import com.sun.javafx.application.PlatformImplShim; +import test.javafx.util.OutputRedirect; import test.util.Util; /** @@ -69,7 +70,16 @@ private void createMainStage() { mainStage.setHeight(180); } - private void doTestCommon(final boolean implicitExit) { + private void doTestCommon(boolean implicitExit) { + OutputRedirect.suppressStderr(); + try { + doTestCommon2(implicitExit); + } finally { + OutputRedirect.checkAndRestoreStderr(RuntimeException.class); + } + } + + private void doTestCommon2(boolean implicitExit) { final Throwable[] testError = new Throwable[1]; final Thread testThread = Thread.currentThread(); diff --git a/tests/system/src/test/java/test/com/sun/javafx/application/SingleExitCommon.java b/tests/system/src/test/java/test/com/sun/javafx/application/SingleExitCommon.java index 10d7b37a797..fa265233be0 100644 --- a/tests/system/src/test/java/test/com/sun/javafx/application/SingleExitCommon.java +++ b/tests/system/src/test/java/test/com/sun/javafx/application/SingleExitCommon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,6 +39,7 @@ import javafx.scene.paint.Color; import javafx.stage.Stage; import com.sun.javafx.application.PlatformImplShim; +import test.javafx.util.OutputRedirect; import test.util.Util; /** @@ -142,8 +143,28 @@ private void doTestCommon(boolean implicitExit, } private void doTestCommon(boolean implicitExit, + boolean reEnableImplicitExit, boolean stageShown, + ThrowableType throwableType, boolean appShouldExit) { + + Object[] expected = switch(throwableType) { + case ERROR -> + new Object[] { InternalError.class }; + case EXCEPTION -> + new Object[] { RuntimeException.class }; + case NONE -> + new Object[0]; + }; + OutputRedirect.suppressStderr(); + try { + doTestCommon2(implicitExit, reEnableImplicitExit, stageShown, throwableType, appShouldExit); + } finally { + OutputRedirect.checkAndRestoreStderr(expected); + } + } + + private void doTestCommon2(boolean implicitExit, boolean reEnableImplicitExit, boolean stageShown, - final ThrowableType throwableType, boolean appShouldExit) { + ThrowableType throwableType, boolean appShouldExit) { SingleExitCommon.implicitExit = implicitExit; SingleExitCommon.stageShown = stageShown; diff --git a/tests/system/src/test/java/test/launchertest/ModuleLauncherTest.java b/tests/system/src/test/java/test/launchertest/ModuleLauncherTest.java index 43d77a5f292..bd486230b82 100644 --- a/tests/system/src/test/java/test/launchertest/ModuleLauncherTest.java +++ b/tests/system/src/test/java/test/launchertest/ModuleLauncherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; +import test.javafx.util.OutputRedirect; /** * Unit test for launching modular FX applications @@ -57,6 +58,15 @@ public class ModuleLauncherTest { private final int testExitCode = ERROR_NONE; private void doTestLaunchModule(String appModulePath, String testAppName) throws Exception { + OutputRedirect.suppressStderr(); + try { + doTestLaunchModule2(appModulePath, testAppName); + } finally { + OutputRedirect.checkAndRestoreStderr(); + } + } + + private void doTestLaunchModule2(String appModulePath, String testAppName) throws Exception { final String javafxModulePath = System.getProperty("worker.module.path"); String modulePath; if (javafxModulePath != null) {