01 /*
02 * Copyright 2010-2012 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 griffon.test.mock
17
18 import griffon.core.UIThreadManager
19 import griffon.util.UIThreadHandler
20 import org.codehaus.griffon.runtime.core.AbstractGriffonApplication
21
22 /**
23 * Customizable implementation og {@code GriffonApplication} useful for testing.<p>
24 * You can override the values of all config classes before {@code initialize()} is called.
25 *
26 * @author Andres Almiray
27 */
28 class MockGriffonApplication extends AbstractGriffonApplication {
29 Closure applicationContainerGenerator
30
31 /** Defaults to {@code griffon.test.mock.MockApplication} */
32 Class appConfigClass = MockApplication
33 /** Defaults to {@code griffon.test.mock.MockConfig} */
34 Class configClass = MockConfig
35 /** Defaults to {@code griffon.test.mock.MockBuilderConfig} */
36 Class builderClass = MockBuilderConfig
37 /** Defaults to {@code griffon.test.mock.MockEvents} */
38 Class eventsClass = MockEvents
39 UIThreadHandler uiThreadHandler
40
41 MockGriffonApplication() {
42 super()
43 }
44
45 MockGriffonApplication(String[] args) {
46 super(args)
47 }
48
49 /**
50 * Returns the value form the execution of {@code applicationContainerGenerator} or an empty map
51 */
52 Object createApplicationContainer() {
53 applicationContainerGenerator?.call() ?: [:]
54 }
55
56 void setUiThreadHandler(UIThreadHandler uiThreadHandler) {
57 UIThreadManager.instance.setUIThreadHandler(uiThreadHandler)
58 }
59
60 Class getAppConfigClass() {
61 this.@appConfigClass
62 }
63
64 Class getConfigClass() {
65 this.@configClass
66 }
67
68 Class getBuilderClass() {
69 this.@builderClass
70 }
71
72 Class getEventsClass() {
73 this.@eventsClass
74 }
75
76 void bootstrap() {
77 // empty
78 }
79
80 void realize() {
81 // empty
82 }
83
84 void show() {
85 // empty
86 }
87 }
|