Skip to content

Commit 5aec50a

Browse files
committed
JDK-8360562: sun/security/tools/keytool/i18n.java add an ability to add comment for failures
1 parent aa19111 commit 5aec50a

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

test/jdk/sun/security/tools/keytool/i18n.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -63,11 +63,21 @@
6363

6464
import jdk.test.lib.UIBuilder;
6565

66-
import javax.swing.*;
66+
import javax.swing.JDialog;
67+
import javax.swing.SwingUtilities;
68+
import javax.swing.JTextArea;
69+
import javax.swing.JButton;
70+
import javax.swing.JPanel;
71+
import javax.swing.JScrollPane;
72+
import javax.swing.JFrame;
73+
import java.awt.FlowLayout;
74+
import java.awt.BorderLayout;
6775
import java.io.ByteArrayOutputStream;
6876
import java.io.PrintStream;
6977
import java.util.Locale;
7078

79+
import static javax.swing.BorderFactory.createEmptyBorder;
80+
7181
public class i18n {
7282
private static final String[][] TABLE = new String[][]{
7383
{"-help", "All the output in this test should be in ${LANG}. "
@@ -238,11 +248,12 @@ public class i18n {
238248
"Output in ${LANG}. Check keytool error: java.lang"
239249
+ ".IllegalArgumentException: if -protected is "
240250
+ "specified, then -storepass, -keypass, and -new "
241-
+ "must not be specified."},
251+
+ "must not be specified."}
242252
};
243253
private static String TEST_SRC = System.getProperty("test.src");
244254
private static int TIMEOUT_MS = 120000;
245255
private volatile boolean failed = false;
256+
private volatile String failureReason = "";
246257
private volatile boolean aborted = false;
247258
private Thread currentThread = null;
248259

@@ -334,6 +345,7 @@ public boolean validate(String command, String instruction, String message) {
334345

335346
if (failed) {
336347
System.out.println(command + ": TEST FAILED");
348+
System.out.println("REASON: " + failureReason);
337349
System.out.println(message);
338350
} else {
339351
System.out.println(command + ": TEST PASSED");
@@ -352,11 +364,46 @@ public void pass() {
352364

353365
public void fail() {
354366
failed = true;
367+
failureReason = requestFailDescription();
355368
currentThread.interrupt();
356369
}
357370

358371
public void abort() {
359372
aborted = true;
360373
currentThread.interrupt();
361374
}
375+
376+
/**
377+
* Opens a prompt to enter a failure reason to be filled by the tester
378+
*/
379+
private String requestFailDescription() {
380+
381+
final JDialog dialogWindow = new JDialog(new JFrame(), "Failure Description", true);
382+
final JTextArea reasonTextArea = new JTextArea(5, 20);
383+
384+
final JButton okButton = new JButton("OK");
385+
okButton.addActionListener(_ -> dialogWindow.setVisible(false));
386+
387+
final JPanel okayBtnPanel = new JPanel(
388+
new FlowLayout(FlowLayout.CENTER,
389+
4,
390+
0));
391+
okayBtnPanel.setBorder(createEmptyBorder(4,
392+
0,
393+
0,
394+
0));
395+
okayBtnPanel.add(okButton);
396+
397+
final JPanel mainPanel = new JPanel(new BorderLayout());
398+
mainPanel.add(new JScrollPane(reasonTextArea), BorderLayout.CENTER);
399+
mainPanel.add(okayBtnPanel, BorderLayout.SOUTH);
400+
401+
dialogWindow.add(mainPanel);
402+
dialogWindow.pack();
403+
dialogWindow.setVisible(true);
404+
405+
dialogWindow.dispose();
406+
407+
return reasonTextArea.getText();
408+
}
362409
}

0 commit comments

Comments
 (0)