Skip to content

Commit

Permalink
8234876: Unit test classes should not extend Application
Browse files Browse the repository at this point in the history
Reviewed-by: kcr
  • Loading branch information
arapte committed May 27, 2020
1 parent 2d98fe6 commit 16f446a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
Expand Down Expand Up @@ -38,13 +38,10 @@
import com.sun.javafx.image.impl.IntArgbPre;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import org.junit.Test;
import static test.util.Util.TIMEOUT;

public class ImageRaceTest extends Application {
public class ImageRaceTest {
static boolean verbose;
static List<Initializer> initalizers = new ArrayList<>();
static volatile boolean ready = false;
Expand Down Expand Up @@ -74,13 +71,6 @@ public void run() {
}
}

@Override
public void start(Stage stage) {
forkAndJoinInitializers();

Platform.exit();
}

void forkAndJoinInitializers() {
long limit = System.currentTimeMillis() + TIMEOUT;
for (Initializer i : initalizers) {
Expand Down Expand Up @@ -113,11 +103,6 @@ void forkAndJoinInitializers() {
} catch (InterruptedException ex) {}
}

public static void main(String[] args) {
init(args);
Application.launch(args);
}

static void init(String[] args) {
boolean getters, setters, converters;
if (args.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
Expand Down Expand Up @@ -32,7 +32,6 @@
import javafx.scene.control.TitledPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import test.util.Util;

Expand All @@ -45,37 +44,40 @@
import org.junit.BeforeClass;
import org.junit.Test;

public class AccordionTitlePaneLeakTest extends Application {
public class AccordionTitlePaneLeakTest {

static private CountDownLatch startupLatch;
static private Accordion accordion;
static private StackPane root;
static private Stage stage;

@Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
accordion = new Accordion();
root = new StackPane(accordion);
stage.setScene(new Scene(root));
stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e -> {
Platform.runLater(() -> startupLatch.countDown());
});
stage.show();
public static class TestApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
accordion = new Accordion();
root = new StackPane(accordion);
stage.setScene(new Scene(root));
stage.setOnShown(l -> {
Platform.runLater(() -> startupLatch.countDown());
});
stage.show();
}
}

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

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

@Test
Expand All @@ -96,12 +98,4 @@ public void testForTitledPaneLeak() throws Exception {
// Ensure accordion's skin no longer hold a ref to titled pane.
Assert.assertNull("Couldn't collect TitledPane", weakRefToPane.get());
}

@AfterClass
public static void teardownOnce() {
Platform.runLater(() -> {
stage.hide();
Platform.exit();
});
}
}

0 comments on commit 16f446a

Please sign in to comment.