下面列出了怎么用android.test.suitebuilder.annotation.SmallTest的API类实例代码及写法,或者点击链接到github查看源代码。
@SmallTest
public void testColorStateList() {
int defaultColor = res.getColor(android.R.color.holo_blue_bright);
int pressedColor = res.getColor(android.R.color.holo_blue_dark);
int[] pressedState = {android.R.attr.state_pressed};
int[] defaultState = {};
assertNotNull(testView.testColorStateList);
assertTrue(testView.testColorStateList.isStateful());
assertEquals(pressedColor, testView.testColorStateList.getColorForState(pressedState, defaultColor));
assertEquals(defaultColor, testView.testColorStateList.getColorForState(defaultState, defaultColor));
assertNotNull(defaultsTestView.testColorStateList);
assertTrue(defaultsTestView.testColorStateList.isStateful());
assertEquals(pressedColor, defaultsTestView.testColorStateList.getColorForState(pressedState, defaultColor));
assertEquals(defaultColor, defaultsTestView.testColorStateList.getColorForState(defaultState, defaultColor));
}
@UiThreadTest
@SmallTest
public void testCustomClassChangedNull() {
final AtomicReference<CustomClass> value = new AtomicReference<>();
final OnPreferenceValueChangedListener<CustomClass> listener =
new OnPreferenceValueChangedListener<CustomClass>() {
@Override
public void onChanged(CustomClass newValue) {
value.set(newValue);
}
};
uut.setCustomClass(new CustomClass("a", "b"));
uut.registerCustomClassChangeListener(listener);
uut.setCustomClass(null);
assertNull(value.get());
}
@SmallTest
public void testNormalRunTaggedSequential() {
final SimpleMockActivity activity = new SimpleMockActivity();
final SimpleMockFragment fragment = new SimpleMockFragment();
activity.addFragment(fragment);
activity.start();
final int firstRunId = fragment.runSimpleTagged(INPUT);
sleep();
assertTrue(fragment.getResultObtained() == 1);
assertTrue(SimpleOperation.isTransform(INPUT, fragment.getResult()));
assertNull(fragment.getError());
final int secondRunId = fragment.runSimpleTagged(INPUT);
assertTrue(firstRunId != secondRunId);
sleep();
assertTrue(fragment.getResultObtained() == 2);
assertTrue(SimpleOperation.isTransform(INPUT, fragment.getResult()));
assertNull(fragment.getError());
}
@SmallTest
public void testDataCacheIsValid() throws SnappydbException {
String key = "asd";
DummyData dummyData = DataGenerator.generateNewDummyData();
rxSnappyClient.setObject(key, dummyData)
.toBlocking().first();
try {
Thread.sleep(2500L);
} catch (InterruptedException e) {
}
DummyData actual = rxSnappyClient.getObject(key, 5000L, DummyData.class)
.toBlocking().first();
assertEquals(dummyData, actual);
}
@UiThreadTest
@SmallTest
public void testIntChanged() {
final AtomicInteger value = new AtomicInteger(-1);
final OnPreferenceValueChangedListener<Integer> listener =
new OnPreferenceValueChangedListener<Integer>() {
@Override
public void onChanged(Integer newValue) {
value.set(newValue);
}
};
uut.registerIntChangeListener(listener);
uut.setInt(1);
assertEquals(1, value.get());
}
@SmallTest
public void testRelaunchCancelledTaggedRunByTag() {
final SimpleMockActivity activity = new SimpleMockActivity();
final SimpleMockFragment fragment = new SimpleMockFragment();
activity.addFragment(fragment);
activity.start();
final int firstRunId = fragment.runSimpleTagged(INPUT);
final boolean cancelResult = fragment.cancelTagged();
assertTrue(cancelResult);
final int secondRunId = fragment.runSimpleTagged(INPUT);
assertTrue(firstRunId != secondRunId);
sleep();
assertTrue(fragment.getResultObtained() == 1);
assertTrue(SimpleOperation.isTransform(INPUT, fragment.getResult()));
assertNull(fragment.getError());
}
@SmallTest
public void testNormalRunTaggedSequential() {
final SimpleMockActivity activity = new SimpleMockActivity();
activity.start();
final int firstRunId = activity.runSimpleTagged(INPUT);
sleep();
assertTrue(activity.getResultObtained() == 1);
assertTrue(SimpleOperation.isTransform(INPUT, activity.getResult()));
assertNull(activity.getError());
final int secondRunId = activity.runSimpleTagged(INPUT);
assertTrue(firstRunId != secondRunId);
sleep();
assertTrue(activity.getResultObtained() == 2);
assertTrue(SimpleOperation.isTransform(INPUT, activity.getResult()));
assertNull(activity.getError());
}
@SmallTest
public void testNormalRunRotateTagged() {
final SimpleMockActivity activity = new SimpleMockActivity();
final SimpleMockFragment fragment = new SimpleMockFragment();
activity.addFragment(fragment);
activity.start();
final int firstRunId = fragment.runSimpleTagged(INPUT);
activity.stop();
activity.start();
final int secondRunId = fragment.runSimpleTagged(INPUT);
assertTrue(firstRunId == secondRunId);
sleep();
assertTrue(fragment.getResultObtained() == 1);
assertTrue(SimpleOperation.isTransform(INPUT, fragment.getResult()));
assertNull(fragment.getError());
}
@SmallTest
public void testKeyByResource() {
uut.getValueAlt();
verify(prefs).getString(eq("string"), any(String.class));
uut.setValueAlt("value");
verify(editor).putString(eq("string"), any(String.class));
}
@SmallTest
public void testActivityLifecycleInvalid1() {
final MockActivity activity = new SimpleMockActivity();
IllegalStateException exception = null;
try {
activity.stop();
} catch (IllegalStateException e) {
exception = e;
}
Assert.assertNotNull(exception);
}
@SmallTest
public void testSaveNullBoolean() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setBoolean(test_key, null)
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testNormalRunRotate() {
final SimpleMockActivity activity = new SimpleMockActivity();
activity.start();
activity.runSimple(INPUT);
activity.stop();
sleep();
activity.start();
assertTrue(activity.getResultObtained() == 1);
assertTrue(SimpleOperation.isTransform(INPUT, activity.getResult()));
assertNull(activity.getError());
}
@SmallTest
public void testBooleanMissingFromCache() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.getBoolean("test123")
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testEditorMethodsForwarded() {
uut.putString("key", "value");
uut.apply();
verify(editor).putString(eq("key"), eq("value"));
verify(editor).apply();
}
@SmallTest
public void testSaveNullString() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setString(test_key, null)
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testSaveNullKeyString() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setString(null, "asd")
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testStringMissingFromCache() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.getString("test123")
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testCancelRunTaggedById() {
final SimpleMockActivity activity = new SimpleMockActivity();
activity.start();
final int runId = activity.runSimpleTagged(INPUT);
final boolean cancelResult = activity.cancel(runId);
assertTrue(cancelResult);
sleep();
assertFalse(activity.gotResult());
}
@SmallTest
public void testCancelRunRotate() {
final SimpleMockActivity activity = new SimpleMockActivity();
final SimpleMockFragment fragment = new SimpleMockFragment();
activity.addFragment(fragment);
activity.start();
final int runId = fragment.runSimple(INPUT);
final boolean cancelResult = fragment.cancel(runId);
assertTrue(cancelResult);
activity.stop();
sleep();
activity.start();
assertFalse(fragment.gotResult());
}
@SmallTest
public void testFraction() {
assertEquals(res.getFraction(R.fraction.fraction, 2, 2), testView.testFractionBase);
assertEquals(res.getFraction(R.fraction.parent_fraction, 2, 2), testView.testFracionPBase);
assertEquals(res.getFraction(R.fraction.fraction, 2, 2), defaultsTestView.testFractionBase);
assertEquals(res.getFraction(R.fraction.parent_fraction, 2, 2), defaultsTestView.testFracionPBase);
}
@SmallTest
public void testSaveNullInteger() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setInteger(test_key, null)
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testCancelRunTaggedByTag() {
final SimpleMockActivity activity = new SimpleMockActivity();
activity.start();
activity.runSimpleTagged(INPUT);
final boolean cancelResult = activity.cancelTagged();
assertTrue(cancelResult);
sleep();
assertFalse(activity.gotResult());
}
@SmallTest
public void testSaveNullStringList() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setStringList(test_key, null)
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testStringListMissingFromCache() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.getStringList("test123")
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testCancelAfterRun() {
final SimpleMockActivity activity = new SimpleMockActivity();
final SimpleMockFragment fragment = new SimpleMockFragment();
activity.addFragment(fragment);
activity.start();
final int runId = fragment.runSimple(INPUT);
sleep();
final boolean cancelResult = fragment.cancel(runId);
assertFalse(cancelResult);
assertTrue(fragment.gotResult());
}
@SmallTest
public void testSaveNullKeyObjectList() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setList(null, DataGenerator.dummyDataGenerator(3))
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testSaveNullObjectList() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setList(test_key, null)
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testObjectListMissingFromCache() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.getList("test123", DummyData.class)
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testSaveNullObject() throws Exception {
boolean isExceptionThrown = false;
try {
rxSnappyClient.setObject(test_key, null)
.toBlocking().first();
} catch (RxSnappyException ex) {
isExceptionThrown = true;
}
assertEquals(true, isExceptionThrown);
}
@SmallTest
public void testCancelRunTaggedByTag() {
final SimpleMockActivity activity = new SimpleMockActivity();
final SimpleMockFragment fragment = new SimpleMockFragment();
activity.addFragment(fragment);
activity.start();
fragment.runSimpleTagged(INPUT);
final boolean cancelResult = fragment.cancelTagged();
assertTrue(cancelResult);
sleep();
assertFalse(fragment.gotResult());
}