-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobolectricCustomRunner.java
42 lines (32 loc) · 1.13 KB
/
RobolectricCustomRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.htoyama.robolectricconfigshare;
import org.junit.runners.model.InitializationError;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
import java.lang.reflect.Method;
import htoyama.com.robolectricconfigshare.BuildConfig;
public class RobolectricCustomRunner extends RobolectricGradleTestRunner {
private static final int[] SDK = new int[]{21};
public RobolectricCustomRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override public Config getConfig(Method method) {
Config c = super.getConfig(method);
return new Config.Implementation(
pickSdkLevel(c.sdk()),
c.manifest(),
c.qualifiers(),
c.packageName(),
c.resourceDir(),
c.assetDir(),
c.shadows(),
c.application(),
c.libraries(),
pickConstants(c.constants())
);
}
private static int[] pickSdkLevel(int[] sdkArray) {
return sdkArray.length == 0 ? SDK : sdkArray; }
private static Class<?> pickConstants(Class<?> constants) {
return constants == Void.class ? BuildConfig.class : constants;
}
}