Skip to content

Commit d22b612

Browse files
committed
add test for method injected system services
1 parent 5169a33 commit d22b612

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/main/java/org/androidannotations/test/ActivityWithServices.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,28 @@ public class ActivityWithServices extends Activity {
279279
@SystemService
280280
WindowManager windowManager;
281281

282+
AppWidgetManager methodInjectedAppWidgetManager;
283+
ActivityManager serviceWithMethodAnnotation;
284+
WindowManager serviceWithParameterAnnotation;
285+
ActivityManager firstMultipleService;
286+
WindowManager secondMultipleService;
287+
288+
@SystemService
289+
void injectAppWidgetManager(AppWidgetManager methodInjectedAppWidgetManager) {
290+
this.methodInjectedAppWidgetManager = methodInjectedAppWidgetManager;
291+
}
292+
293+
@SystemService
294+
void injectSingleServiceWithMethodAnnotation(ActivityManager serviceWithMethodAnnotation) {
295+
this.serviceWithMethodAnnotation = serviceWithMethodAnnotation;
296+
}
297+
298+
void injectSingleServiceWithParameterAnnotation(@SystemService WindowManager serviceWithParameterAnnotation) {
299+
this.serviceWithParameterAnnotation = serviceWithParameterAnnotation;
300+
}
301+
302+
void injectMultipleServices(@SystemService ActivityManager firstMultipleService, @SystemService WindowManager secondMultipleService) {
303+
this.firstMultipleService = firstMultipleService;
304+
this.secondMultipleService = secondMultipleService;
305+
}
282306
}

‎AndroidAnnotations/androidannotations-core/androidannotations-test/src/test/java/org/androidannotations/test/ServiceInjectionTest.java‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

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

20+
import org.junit.Before;
2021
import org.junit.Test;
2122
import org.junit.runner.RunWith;
2223
import org.robolectric.Robolectric;
@@ -25,10 +26,15 @@
2526
@RunWith(RobolectricTestRunner.class)
2627
public class ServiceInjectionTest {
2728

29+
private ActivityWithServices_ activity;
30+
31+
@Before
32+
public void setUp() {
33+
activity = Robolectric.buildActivity(ActivityWithServices_.class).create().get();
34+
}
35+
2836
@Test
2937
public void servicesAreInjected() {
30-
ActivityWithServices_ activity = Robolectric.buildActivity(ActivityWithServices_.class).create().get();
31-
3238
// in alphabetical order
3339

3440
assertThat(activity.accessibilityManager).isNotNull();
@@ -101,4 +107,25 @@ public void servicesAreInjected() {
101107
assertThat(activity.windowManager).isNotNull();
102108
}
103109

110+
@Test
111+
public void methodInjectedAppWidgetManager() {
112+
assertThat(activity.methodInjectedAppWidgetManager).isNotNull();
113+
}
114+
115+
@Test
116+
public void serviceWithMethodAnnotation() {
117+
assertThat(activity.serviceWithMethodAnnotation).isNotNull();
118+
}
119+
120+
@Test
121+
public void serviceWithParameterAnnotation() {
122+
assertThat(activity.serviceWithParameterAnnotation).isNotNull();
123+
}
124+
125+
@Test
126+
public void multipleService() {
127+
assertThat(activity.firstMultipleService).isNotNull();
128+
assertThat(activity.secondMultipleService).isNotNull();
129+
}
130+
104131
}

0 commit comments

Comments
 (0)