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