Skip to content

Commit 16f446a

Browse files
committed
8234876: Unit test classes should not extend Application
Reviewed-by: kcr
1 parent 2d98fe6 commit 16f446a

File tree

2 files changed

+26
-47
lines changed

2 files changed

+26
-47
lines changed

tests/system/src/test/java/test/com/sun/javafx/image/impl/ImageRaceTest.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, 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
@@ -38,13 +38,10 @@
3838
import com.sun.javafx.image.impl.IntArgbPre;
3939
import java.util.ArrayList;
4040
import java.util.List;
41-
import javafx.application.Application;
42-
import javafx.application.Platform;
43-
import javafx.stage.Stage;
4441
import org.junit.Test;
4542
import static test.util.Util.TIMEOUT;
4643

47-
public class ImageRaceTest extends Application {
44+
public class ImageRaceTest {
4845
static boolean verbose;
4946
static List<Initializer> initalizers = new ArrayList<>();
5047
static volatile boolean ready = false;
@@ -74,13 +71,6 @@ public void run() {
7471
}
7572
}
7673

77-
@Override
78-
public void start(Stage stage) {
79-
forkAndJoinInitializers();
80-
81-
Platform.exit();
82-
}
83-
8474
void forkAndJoinInitializers() {
8575
long limit = System.currentTimeMillis() + TIMEOUT;
8676
for (Initializer i : initalizers) {
@@ -113,11 +103,6 @@ void forkAndJoinInitializers() {
113103
} catch (InterruptedException ex) {}
114104
}
115105

116-
public static void main(String[] args) {
117-
init(args);
118-
Application.launch(args);
119-
}
120-
121106
static void init(String[] args) {
122107
boolean getters, setters, converters;
123108
if (args.length == 0) {

tests/system/src/test/java/test/javafx/scene/control/AccordionTitlePaneLeakTest.java

+24-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, 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
@@ -32,7 +32,6 @@
3232
import javafx.scene.control.TitledPane;
3333
import javafx.scene.layout.StackPane;
3434
import javafx.stage.Stage;
35-
import javafx.stage.WindowEvent;
3635

3736
import test.util.Util;
3837

@@ -45,37 +44,40 @@
4544
import org.junit.BeforeClass;
4645
import org.junit.Test;
4746

48-
public class AccordionTitlePaneLeakTest extends Application {
47+
public class AccordionTitlePaneLeakTest {
4948

5049
static private CountDownLatch startupLatch;
5150
static private Accordion accordion;
5251
static private StackPane root;
5352
static private Stage stage;
5453

55-
@Override
56-
public void start(Stage primaryStage) throws Exception {
57-
stage = primaryStage;
58-
accordion = new Accordion();
59-
root = new StackPane(accordion);
60-
stage.setScene(new Scene(root));
61-
stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e -> {
62-
Platform.runLater(() -> startupLatch.countDown());
63-
});
64-
stage.show();
54+
public static class TestApp extends Application {
55+
@Override
56+
public void start(Stage primaryStage) throws Exception {
57+
stage = primaryStage;
58+
accordion = new Accordion();
59+
root = new StackPane(accordion);
60+
stage.setScene(new Scene(root));
61+
stage.setOnShown(l -> {
62+
Platform.runLater(() -> startupLatch.countDown());
63+
});
64+
stage.show();
65+
}
6566
}
6667

6768
@BeforeClass
68-
public static void initFX() {
69+
public static void initFX() throws Exception {
6970
startupLatch = new CountDownLatch(1);
70-
new Thread(() -> Application.launch(AccordionTitlePaneLeakTest.class, (String[]) null)).start();
71+
new Thread(() -> Application.launch(TestApp.class, (String[])null)).start();
72+
Assert.assertTrue("Timeout waiting for FX runtime to start", startupLatch.await(15, TimeUnit.SECONDS));
73+
}
7174

72-
try {
73-
if (!startupLatch.await(15, TimeUnit.SECONDS)) {
74-
Assert.fail("Timeout waiting for FX runtime to start");
75-
}
76-
} catch (InterruptedException ex) {
77-
Assert.fail("Unexpected exception: " + ex);
78-
}
75+
@AfterClass
76+
public static void teardownOnce() {
77+
Platform.runLater(() -> {
78+
stage.hide();
79+
Platform.exit();
80+
});
7981
}
8082

8183
@Test
@@ -96,12 +98,4 @@ public void testForTitledPaneLeak() throws Exception {
9698
// Ensure accordion's skin no longer hold a ref to titled pane.
9799
Assert.assertNull("Couldn't collect TitledPane", weakRefToPane.get());
98100
}
99-
100-
@AfterClass
101-
public static void teardownOnce() {
102-
Platform.runLater(() -> {
103-
stage.hide();
104-
Platform.exit();
105-
});
106-
}
107101
}

0 commit comments

Comments
 (0)