Skip to content

Commit 311fa51

Browse files
committed
* Fixes build fail due to an update of Robolectric, which seems to create services the wrong way
* Catching Throwable when trying to load classes, to prevent exceptions in static blocks
1 parent bfade7e commit 311fa51

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/processing/EBeansHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public JClass refClass(String fullyQualifiedClassName) {
169169
if (refClass == null) {
170170
try {
171171
refClass = codeModel.ref(fullyQualifiedClassName);
172-
} catch (NoClassDefFoundError ignored) {
172+
} catch (Throwable ignored) {
173173
refClass = codeModel.directClass(fullyQualifiedClassName);
174174
}
175175
loadedClasses.put(fullyQualifiedClassName, refClass);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.googlecode.androidannotations.test15;
2+
3+
import android.text.ClipboardManager;
4+
5+
import com.xtremelabs.robolectric.internal.Implementation;
6+
import com.xtremelabs.robolectric.internal.Implements;
7+
8+
public class FakeClipboardManager extends ClipboardManager {
9+
10+
private CharSequence text;
11+
12+
@Override
13+
public CharSequence getText() {
14+
return text;
15+
}
16+
17+
@Override
18+
public void setText(CharSequence text) {
19+
this.text = text;
20+
}
21+
22+
@Override
23+
public boolean hasText() {
24+
return text != null;
25+
}
26+
}

AndroidAnnotations/functional-test-1-5-tests/src/test/java/com/googlecode/androidannotations/test15/ServiceInjectionTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,30 @@
1717

1818
import static org.fest.assertions.Assertions.assertThat;
1919

20+
import java.lang.reflect.Field;
21+
import java.util.Map;
22+
23+
import org.junit.Before;
2024
import org.junit.Test;
2125
import org.junit.runner.RunWith;
2226

27+
import android.content.Context;
28+
29+
import com.xtremelabs.robolectric.shadows.ShadowApplication;
30+
2331
@RunWith(AndroidAnnotationsTestRunner.class)
2432
public class ServiceInjectionTest {
2533

34+
@Before
35+
public void setup() throws Exception {
36+
Field serviceMapField = ShadowApplication.class.getDeclaredField("SYSTEM_SERVICE_MAP");
37+
serviceMapField.setAccessible(true);
38+
@SuppressWarnings("unchecked")
39+
Map<String, String> SYSTEM_SERVICE_MAP = (Map<String, String>) serviceMapField.get(null);
40+
41+
SYSTEM_SERVICE_MAP.put(Context.CLIPBOARD_SERVICE, "com.googlecode.androidannotations.test15.FakeClipboardManager");
42+
}
43+
2644
@Test
2745
public void servicesAreInjected() {
2846
ActivityWithServices_ activity = new ActivityWithServices_();

0 commit comments

Comments
 (0)