Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public class CustomGradleTestRunner extends RobolectricGradleTestRunner {
private static final int MAX_SDK_LEVEL = 21;
public CustomGradleTestRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
public Config getConfig(Method method) {
Config config = super.getConfig(method);
/*
Fixing up the Config:
* SDK can not be higher than 21
* constants must point to a real BuildConfig class
*/
config = new Config.Implementation(ensureSdkLevel(
config.emulateSdk()),
config.manifest(),
config.qualifiers(),
config.resourceDir(),
config.assetDir(),
ensureSdkLevel(config.reportSdk()),
config.shadows(),
config.application(),
config.libraries(),
ensureBuildConfig(config.constants()));
return config;
}
private Class<?> ensureBuildConfig(Class<?> constants) {
if (constants == Void.class) return BuildConfig.class;
return constants;
}
private int ensureSdkLevel(int sdkLevel) {
if (sdkLevel > MAX_SDK_LEVEL) return MAX_SDK_LEVEL;
if (sdkLevel <= 0) return MAX_SDK_LEVEL;
return sdkLevel;
}
}
android {
testOptions {
unitTests.all {
maxHeapSize = "2048m"
}
}
}
import android.content.IntentFilter;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
import java.util.Iterator;
public class IntentFilterEqualMatcher extends ArgumentMatcher<IntentFilter> {
private final IntentFilter mTargetIntentFilter;
public IntentFilterEqualMatcher(IntentFilter intentFilter) {
mTargetIntentFilter = intentFilter;
}
public static IntentFilter eq(IntentFilter intentFilter) {
return Mockito.argThat(new IntentFilterEqualMatcher(intentFilter));
}
@Override
public boolean matches(Object argument) {
if (argument instanceof IntentFilter) {
IntentFilter other = (IntentFilter) argument;
return isSimilar(mTargetIntentFilter, other);
}
return false;
}
public static boolean isSimilar(IntentFilter a, IntentFilter b) {
for (Iterator<String> actions = a.actionsIterator(); actions.hasNext(); ) {
String action = actions.next();
if (b.hasAction(action)) {
return true;
}
}
return false;
}
}
public static boolean isSimilar(IntentFilter a, IntentFilter b) {
for (Iterator<String> actions = a.actionsIterator(); actions.hasNext(); ) {
String action = actions.next();
if (b.hasAction(action)) {
return true;
}
}
return false;
}
CC0 is the "no copyright reserved" option in the Creative Commons toolkit - it effectively means relinquishing all copyright and similar rights that you hold in a work and dedicating those rights to the public domain.
CC0 is a single purpose tool, designed to take on the dedication function of the former, deprecated Public Domain Dedication and Certification.
How effectively CC0 works will depend on the legal regime in which the work is used, but the tool is intended to effectively release rights even in jurisdictions where it is difficult to do so.
Note that CC0 is a three-tier instrument. We recognize that a waiver may not be effective in some jurisdictions. CC0's enforceability is not solely dependent on the waiver. The fall back public license -- the second tier -- is similar to our Attribution-only license but without the attribution requirement. The third tier is a non-assertion by the copyright holder that even if the waiver and license do not operate as intended, the copyright holder will not take any actions that prevent a user of the work from exercising rights consistent with the intention of the copyright holder as expressed in CC0.
https://wiki.creativecommons.org/CC0/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)
public class MainActivityTest {
sourceSets {
androidTest {
setRoot('src/test')
}
}
testCompile ('com.squareup:fest-android:1.0.8') {
exclude module: 'support-v4'
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
@Before
public void setup() {
TimeZone.setDefault(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment