1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
32
32
import javafx .scene .control .TitledPane ;
33
33
import javafx .scene .layout .StackPane ;
34
34
import javafx .stage .Stage ;
35
- import javafx .stage .WindowEvent ;
36
35
37
36
import test .util .Util ;
38
37
45
44
import org .junit .BeforeClass ;
46
45
import org .junit .Test ;
47
46
48
- public class AccordionTitlePaneLeakTest extends Application {
47
+ public class AccordionTitlePaneLeakTest {
49
48
50
49
static private CountDownLatch startupLatch ;
51
50
static private Accordion accordion ;
52
51
static private StackPane root ;
53
52
static private Stage stage ;
54
53
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
+ }
65
66
}
66
67
67
68
@ BeforeClass
68
- public static void initFX () {
69
+ public static void initFX () throws Exception {
69
70
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
+ }
71
74
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
+ });
79
81
}
80
82
81
83
@ Test
@@ -96,12 +98,4 @@ public void testForTitledPaneLeak() throws Exception {
96
98
// Ensure accordion's skin no longer hold a ref to titled pane.
97
99
Assert .assertNull ("Couldn't collect TitledPane" , weakRefToPane .get ());
98
100
}
99
-
100
- @ AfterClass
101
- public static void teardownOnce () {
102
- Platform .runLater (() -> {
103
- stage .hide ();
104
- Platform .exit ();
105
- });
106
- }
107
101
}
0 commit comments