Skip to content

Commit b0c75b4

Browse files
committed
8341235: Improve default instruction frame title in PassFailJFrame
Backport-of: 4ba170c403ae85576f84dafd4a157ba0db99873f
1 parent eb46442 commit b0c75b4

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

test/jdk/java/awt/regtesthelpers/PassFailJFrame.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.File;
4646
import java.io.IOException;
4747
import java.lang.reflect.InvocationTargetException;
48+
import java.nio.file.Paths;
4849
import java.util.ArrayList;
4950
import java.util.Arrays;
5051
import java.util.Collection;
@@ -289,9 +290,15 @@
289290
*/
290291
public final class PassFailJFrame {
291292

292-
private static final String TITLE = "Test Instruction Frame";
293+
/** A default title for the instruction frame. */
294+
private static final String TITLE = "Test Instructions";
295+
296+
/** A default test timeout. */
293297
private static final long TEST_TIMEOUT = 5;
298+
299+
/** A default number of rows for displaying the test instructions. */
294300
private static final int ROWS = 10;
301+
/** A default number of columns for displaying the test instructions. */
295302
private static final int COLUMNS = 40;
296303

297304
/**
@@ -304,7 +311,7 @@ public final class PassFailJFrame {
304311
*/
305312
private static final String FAILURE_REASON = "Failure Reason:\n";
306313
/**
307-
* The failure reason message when the user didn't provide one.
314+
* The failure reason message when the user doesn't provide one.
308315
*/
309316
private static final String EMPTY_REASON = "(no reason provided)";
310317

@@ -1824,9 +1831,41 @@ public PassFailJFrame build() throws InterruptedException,
18241831
return new PassFailJFrame(this);
18251832
}
18261833

1834+
/**
1835+
* Returns the file name of the test, if the {@code test.file} property
1836+
* is defined, concatenated with {@code " - "} which serves as a prefix
1837+
* to the default instruction frame title;
1838+
* or an empty string if the {@code test.file} property is not defined.
1839+
*
1840+
* @return the prefix to the default title:
1841+
* either the file name of the test or an empty string
1842+
*
1843+
* @see <a href="https://openjdk.org/jtreg/tag-spec.html#testvars">jtreg
1844+
* test-specific system properties and environment variables</a>
1845+
*/
1846+
private static String getTestFileNamePrefix() {
1847+
String testFile = System.getProperty("test.file");
1848+
if (testFile == null) {
1849+
return "";
1850+
}
1851+
1852+
return Paths.get(testFile).getFileName().toString()
1853+
+ " - ";
1854+
}
1855+
1856+
/**
1857+
* Validates the state of the builder and
1858+
* expands parameters that have no assigned values
1859+
* to their default values.
1860+
*
1861+
* @throws IllegalStateException if no instructions are provided,
1862+
* or if {@code PositionWindows} implementation is
1863+
* provided but neither window creator nor
1864+
* test window list are set
1865+
*/
18271866
private void validate() {
18281867
if (title == null) {
1829-
title = TITLE;
1868+
title = getTestFileNamePrefix() + TITLE;
18301869
}
18311870

18321871
if (instructions == null || instructions.isEmpty()) {

0 commit comments

Comments
 (0)