TestDesktopPivotApplication.java
01 /*
02  * SPDX-License-Identifier: Apache-2.0
03  *
04  * Copyright 2008-2017 the original author or authors.
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package org.codehaus.griffon.runtime.pivot;
19 
20 import griffon.core.ApplicationBootstrapper;
21 import griffon.core.GriffonApplication;
22 import griffon.core.test.TestCaseAware;
23 import griffon.pivot.DesktopPivotGriffonApplication;
24 import org.apache.pivot.wtk.Display;
25 
26 import javax.annotation.Nonnull;
27 import java.util.concurrent.CountDownLatch;
28 
29 /**
30  @author Andres Almiray
31  @since 2.0.0
32  */
33 public class TestDesktopPivotApplication extends DesktopPivotGriffonApplication {
34     private static Object testCase;
35     private static GriffonApplication application;
36     private static CountDownLatch latch;
37     private static CountDownLatch readyLatch;
38 
39     @Nonnull
40     public static GriffonApplication getApplication() {
41         return application;
42     }
43 
44     @Nonnull
45     public static CountDownLatch getLatch() {
46         return latch;
47     }
48 
49     @Nonnull
50     public static CountDownLatch getReadyLatch() {
51         return readyLatch;
52     }
53 
54     public static void init(Object testCase) {
55         TestDesktopPivotApplication.testCase = testCase;
56         latch = new CountDownLatch(1);
57         readyLatch = new CountDownLatch(1);
58     }
59 
60     public TestDesktopPivotApplication() {
61     }
62 
63     public TestDesktopPivotApplication(@Nonnull String[] args) {
64         super(args);
65     }
66 
67     @Nonnull
68     @Override
69     @SuppressWarnings("ConstantConditions")
70     protected ApplicationBootstrapper createApplicationBootstrapper(@Nonnull Display display) {
71         ApplicationBootstrapper bootstrapper = new TestPivotApplicationBootstrapper(this, display);
72         if (bootstrapper instanceof TestCaseAware) {
73             ((TestCaseAwarebootstrapper).setTestCase(testCase);
74         }
75         return bootstrapper;
76     }
77 
78     @Override
79     protected void afterStartup() {
80         application = this;
81         application.initialize();
82         latch.countDown();
83     }
84 
85     @Override
86     public void ready() {
87         super.ready();
88         readyLatch.countDown();
89     }
90 
91     @Override
92     public void exit() {
93         // empty
94     }
95 }