|
1 | | -/** |
2 | | - * Copyright (C) 2010-2016 eBusiness Information, Excilys Group |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 | | - * use this file except in compliance with the License. You may obtain a copy of |
6 | | - * the License at |
7 | | - * |
8 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed To in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 | | - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 | | - * License for the specific language governing permissions and limitations under |
14 | | - * the License. |
15 | | - */ |
16 | | -package org.androidannotations.test; |
17 | | - |
18 | | -import static org.fest.reflect.core.Reflection.staticField; |
19 | | - |
20 | | -import java.lang.reflect.Method; |
21 | | - |
22 | | -import org.androidannotations.api.UiThreadExecutor; |
23 | | -import org.robolectric.Robolectric; |
24 | | -import org.robolectric.TestLifecycleApplication; |
25 | | -import org.robolectric.shadows.ShadowHandler; |
26 | | - |
27 | | -import android.app.Application; |
28 | | -import android.os.Handler; |
29 | | -import android.os.Message; |
30 | | - |
31 | | -public class TestApplication extends Application implements TestLifecycleApplication { |
32 | | - |
33 | | - @Override |
34 | | - public void beforeTest(Method method) { |
35 | | - } |
36 | | - |
37 | | - @Override |
38 | | - public void prepareTest(Object test) { |
39 | | - hackHandler(); |
40 | | - } |
41 | | - |
42 | | - @Override |
43 | | - public void afterTest(Method method) { |
44 | | - } |
45 | | - |
46 | | - // TODO remove this after upgrading robolectric to 3+ |
47 | | - private void hackHandler() { |
48 | | - final Handler handler = staticField("HANDLER").ofType(Handler.class).in(UiThreadExecutor.class).get(); |
49 | | - ShadowHandler shadowHandler = Robolectric.shadowOf_(handler); |
50 | | - shadowHandler.__constructor__(new Handler.Callback() { |
51 | | - @Override |
52 | | - public boolean handleMessage(Message msg) { |
53 | | - // in the robolectric 2.4 there is a strange code - they call |
54 | | - // Handler's handleMessage (it do nothing) |
55 | | - // instead of dispatch, that actually do the job. This is just a |
56 | | - // dirty work-around. It should be removed |
57 | | - // with newer version of robolectric. |
58 | | - handler.dispatchMessage(msg); |
59 | | - return true; |
60 | | - } |
61 | | - }); |
62 | | - } |
63 | | -} |
0 commit comments