8289238: Refactoring changes to PassFailJFrame Test Framework

Reviewed-by: azvegint, aivanov
This commit is contained in:
Harshitha Onkar 2022-06-29 18:36:38 +00:00 committed by Alexey Ivanov
parent b6bd190d8d
commit 15efb2bdeb
8 changed files with 41 additions and 40 deletions

View File

@ -125,8 +125,8 @@ public class ClippedImages {
frame.pack();
frame.setVisible(true);
PassFailJFrame.addTestFrame(frame);
PassFailJFrame.positionTestFrame(frame, PassFailJFrame.Position.HORIZONTAL);
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
}
private static void printOne() {

View File

@ -152,10 +152,10 @@ public class PrintGlyphVectorTest extends Component implements Printable {
f.setVisible(true);
// add the test frame to dispose
PassFailJFrame.addTestFrame(f);
PassFailJFrame.addTestWindow(f);
// Arrange the test instruction frame and test frame side by side
PassFailJFrame.positionTestFrame(f, PassFailJFrame.Position.HORIZONTAL);
PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
}
public static void main(String[] arg) throws Exception {

View File

@ -78,10 +78,10 @@ public class PrintLatinCJKTest implements Printable {
frame.setVisible(true);
// add the test frame to dispose
PassFailJFrame.addTestFrame(frame);
PassFailJFrame.addTestWindow(frame);
// Arrange the test instruction frame and test frame side by side
PassFailJFrame.positionTestFrame(frame,
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
});
}

View File

@ -23,8 +23,8 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.InvocationTargetException;
@ -51,7 +51,7 @@ public class PassFailJFrame {
private static final int ROWS = 10;
private static final int COLUMNS = 40;
private static final List<Frame> frameList = new ArrayList<>();
private static final List<Window> windowList = new ArrayList<>();
private static final Timer timer = new Timer(0, null);
private static final CountDownLatch latch = new CountDownLatch(1);
@ -172,7 +172,7 @@ public class PassFailJFrame {
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frameList.add(frame);
windowList.add(frame);
}
private static String convertMillisToTimeStr(long millis) {
@ -201,7 +201,7 @@ public class PassFailJFrame {
throw new IllegalStateException("awaitAndCheck() should not be called on EDT");
}
latch.await();
invokeAndWait(PassFailJFrame::disposeFrames);
invokeAndWait(PassFailJFrame::disposeWindows);
if (timeout) {
throw new RuntimeException(testFailedReason);
@ -215,12 +215,12 @@ public class PassFailJFrame {
}
/**
* Dispose all the frame(s) i,e both the test instruction frame as
* well as the frame that is added via addTestFrame(Frame frame)
* Dispose all the window(s) i,e both the test instruction frame and
* the window(s) that is added via addTestWindow(Window testWindow)
*/
private static synchronized void disposeFrames() {
for (Frame f : frameList) {
f.dispose();
private static synchronized void disposeWindows() {
for (Window win : windowList) {
win.dispose();
}
}
@ -257,42 +257,42 @@ public class PassFailJFrame {
}
/**
* Position the instruction frame with testFrame ( testcase created
* frame) by the specified position
* Position the instruction frame with testWindow (testcase created
* window) by the specified position.
* Note: This method should be invoked from the method that creates
* testFrame
* testWindow.
*
* @param testFrame test frame that the test is created
* @param testWindow test window that the test is created
* @param position position can be either HORIZONTAL (both test
* instruction frame and test frame as arranged side by
* side or VERTICAL ( both test instruction frame and
* test frame as arranged up and down)
* instruction frame and test window as arranged
* side by side) or VERTICAL (both test instruction
* frame and test window as arranged up and down)
*/
public static void positionTestFrame(Frame testFrame, Position position) {
public static void positionTestWindow(Window testWindow, Position position) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
if (position.equals(Position.HORIZONTAL)) {
int newX = ((screenSize.width / 2) - frame.getWidth());
frame.setLocation(newX, frame.getY());
testFrame.setLocation((frame.getLocation().x + frame.getWidth() + 5), frame.getY());
testWindow.setLocation((frame.getLocation().x + frame.getWidth() + 5), frame.getY());
} else if (position.equals(Position.VERTICAL)) {
int newY = ((screenSize.height / 2) - frame.getHeight());
frame.setLocation(frame.getX(), newY);
testFrame.setLocation(frame.getX(),
testWindow.setLocation(frame.getX(),
(frame.getLocation().y + frame.getHeight() + 5));
}
}
/**
* Add the testFrame to the frameList so that test instruction frame
* and testFrame and any other frame used in this test is disposed
* via disposeFrames()
* Add the testWindow to the windowList so that test instruction frame
* and testWindow and any other windows used in this test is disposed
* via disposeWindows().
*
* @param testFrame testFrame that needs to be disposed
* @param testWindow testWindow that needs to be disposed
*/
public static synchronized void addTestFrame(Frame testFrame) {
frameList.add(testFrame);
public static synchronized void addTestWindow(Window testWindow) {
windowList.add(testWindow);
}
/**
@ -315,7 +315,8 @@ public class PassFailJFrame {
*/
public static void forceFail() {
failed = true;
testFailedReason = "Failure Reason:\n" +
"forceFail called";
latch.countDown();
}
}

View File

@ -68,8 +68,8 @@ public class bug4380543 {
passFailJFrame = new PassFailJFrame(instructions);
testObj = new TestFrame();
//Adding the Test Frame to handle dispose
PassFailJFrame.addTestFrame(testObj);
PassFailJFrame.positionTestFrame(testObj, PassFailJFrame.Position.HORIZONTAL);
PassFailJFrame.addTestWindow(testObj);
PassFailJFrame.positionTestWindow(testObj, PassFailJFrame.Position.HORIZONTAL);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -67,8 +67,8 @@ public final class bug4209065 {
frame.setVisible(true);
PassFailJFrame.addTestFrame(frame);
PassFailJFrame.positionTestFrame(frame,
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
});
}

View File

@ -68,10 +68,10 @@ public class PrintAllPagesTest {
});
// add the test frame to dispose
PassFailJFrame.addTestFrame(f);
PassFailJFrame.addTestWindow(f);
// Arrange the test instruction frame and test frame side by side
PassFailJFrame.positionTestFrame(f, PassFailJFrame.Position.HORIZONTAL);
PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
SwingUtilities.invokeAndWait(() -> {
try {

View File

@ -67,8 +67,8 @@ public class HtmlScriptTagParserTest {
frame.pack();
frame.setLocationRelativeTo(null);
PassFailJFrame.addTestFrame(frame);
PassFailJFrame.positionTestFrame(frame,
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
});
}