/** Call this in a {@link TestSubtype} public method asserting subtype relationship. */ final <T> T isSubtype(T sub) { Type returnType = method.getGenericReturnType(); Type paramType = getOnlyParameterType(); TestSubtype spec = method.getAnnotation(TestSubtype.class); assertThat(TypeToken.of(paramType).isSubtypeOf(returnType)) .named("%s is subtype of %s", paramType, returnType) .isTrue(); assertThat(TypeToken.of(returnType).isSupertypeOf(paramType)) .named("%s is supertype of %s", returnType, paramType) .isTrue(); if (!spec.suppressGetSubtype()) { assertThat(getSubtype(returnType, TypeToken.of(paramType).getRawType())).isEqualTo(paramType); } if (!spec.suppressGetSupertype()) { assertThat(getSupertype(paramType, TypeToken.of(returnType).getRawType())) .isEqualTo(returnType); } return sub; }
boolean expectedChanged = iterableToAdd.iterator().hasNext(); assertThat(Lists.addAllImpl(toTest, index, iterableToAdd)) .named(format, iterableToAdd, index) .isEqualTo(expectedChanged); assertThat(toTest)
@Test public void shouldMakeBuildVersionIntsNonFinal() throws Exception { Class<?> versionClass = loadClass(Build.VERSION.class); int modifiers = versionClass.getDeclaredField("SDK_INT").getModifiers(); assertThat(Modifier.isFinal(modifiers)).named("SDK_INT should be non-final").isFalse(); }
@Test public void idleMainLooper_executesScheduledTasks() { final boolean[] wasRun = new boolean[]{false}; new Handler().postDelayed(new Runnable() { @Override public void run() { wasRun[0] = true; } }, 2000); assertThat(wasRun[0]).named("first").isFalse(); ShadowLooper.idleMainLooper(1999); assertThat(wasRun[0]).named("second").isFalse(); ShadowLooper.idleMainLooper(1); assertThat(wasRun[0]).named("last").isTrue(); }
TestSubtype spec = method.getAnnotation(TestSubtype.class); assertThat(TypeToken.of(paramType).isSubtypeOf(returnType)) .named("%s is subtype of %s", paramType, returnType) .isFalse(); assertThat(TypeToken.of(returnType).isSupertypeOf(paramType)) .named("%s is supertype of %s", returnType, paramType) .isFalse(); if (!spec.suppressGetSubtype()) {
@Test public void testIsEmptyElementTag() throws Exception { assertThat(parser.isEmptyElementTag()).named("Before START_DOCUMENT should return false.").isEqualTo(false); forgeAndOpenDocument("<foo><bar/></foo>"); assertThat(parser.isEmptyElementTag()).named("Not empty tag should return false.").isEqualTo(false); forgeAndOpenDocument("<foo/>"); assertThat(parser.isEmptyElementTag()).named( "In the Android implementation this method always return false.").isEqualTo(false); }
@Test public void resetThreadLoopers_shouldQuitAllNonMainLoopers() throws InterruptedException { QuitThread test = getQuitThread(); assertThat(test.hasContinued).named("hasContinued:before").isFalse(); ShadowLooper.resetThreadLoopers(); test.join(5000); assertThat(test.hasContinued).named("hasContinued:after").isTrue(); }
@Test public void enqueueMessage_returnsTrue() { assertThat(enqueueMessage(testMessage, 100)).named("retval").isTrue(); }
@Test public void nativeOpen_addsConnectionToPool() { assertThat(conn).isNotNull(); assertThat(conn.isOpen()).named("open").isTrue(); }
@Test public void reset_shouldClearMessageQueue() { Message msg = handler.obtainMessage(1234); Message msg2 = handler.obtainMessage(5678); handler.sendMessage(msg); handler.sendMessage(msg2); assertThat(handler.hasMessages(1234)).named("before-1234").isTrue(); assertThat(handler.hasMessages(5678)).named("before-5678").isTrue(); shadowQueue.reset(); assertThat(handler.hasMessages(1234)).named("after-1234").isFalse(); assertThat(handler.hasMessages(5678)).named("after-5678").isFalse(); }
public void testEqualsImpl() { List<Integer> base = createList(Integer.class, 1, 2, 2); List<Integer> copy = createList(Integer.class, 1, 2, 2); ImmutableList<Integer> otherType = ImmutableList.of(1, 2, 2); List<Integer> outOfOrder = createList(Integer.class, 2, 2, 1); List<Integer> diffValue = createList(Integer.class, 1, 2, 3); List<Integer> diffLength = createList(Integer.class, 1, 2); List<Integer> empty = createList(Integer.class); assertThat(Lists.equalsImpl(base, copy)).isTrue(); assertThat(Lists.equalsImpl(base, otherType)).isTrue(); List<Object> unEqualItems = Arrays.asList(outOfOrder, diffValue, diffLength, empty, null, new Object()); for (Object other : unEqualItems) { assertThat(Lists.equalsImpl(base, other)).named("%s", other).isFalse(); } }
@Test public void nativeClose_closesConnection() { ShadowSQLiteConnection.nativeClose(ptr); assertThat(conn.isOpen()).named("open").isFalse(); }
@Test public void enqueueMessage_returnsFalse_whenQuitting() { setField(queue, quitField, true); assertThat(enqueueMessage(testMessage, 1)).named("enqueueMessage()").isFalse(); }
public CursorAssert hasRow(Object... values) { assertThat(cursor.moveToNext()).named("row " + (row + 1) + " exists").isTrue(); row += 1; assertThat(cursor.getColumnCount()).named("column count").isEqualTo(values.length); for (int i = 0; i < values.length; i++) { assertThat(cursor.getString(i)) .named("row " + row + " column '" + cursor.getColumnName(i) + "'") .isEqualTo(values[i]); } return this; }
@Test public void reset_closesConnection() { ShadowSQLiteConnection.reset(); assertThat(conn.isOpen()).named("open").isFalse(); }
@Override public void handleMessage(Message msg) { boolean inUse = callInstanceMethod(msg, "isInUse"); assertThat(inUse).named(msg.what + ":inUse").isTrue(); Message next = reflector(_Message_.class, msg).getNext(); assertThat(next).named(msg.what + ":next").isNull(); } };
@Test public void delayedTasks_areNotRunEagerly_whenActivityIsStarted_andSchedulerUnPaused() { // Regression test for issue #1509 final Scheduler s = Robolectric.getForegroundThreadScheduler(); final long startTime = s.getCurrentTime(); TestDelayedPostActivity activity = Robolectric.setupActivity(TestDelayedPostActivity.class); assertThat(activity.r2.wasRun).named("before flush").isFalse(); assertThat(s.getCurrentTime()).named("currentTime before flush").isEqualTo(startTime); s.advanceToLastPostedRunnable(); assertThat(activity.r2.wasRun).named("after flush").isTrue(); assertThat(s.getCurrentTime()).named("currentTime after flush").isEqualTo(startTime + 60000); }
@Test public void shouldKnowIfThisOrAncestorsAreVisible() throws Exception { assertThat(view.isShown()).named("view isn't considered shown unless it has a view root").isFalse(); shadowOf(view).setMyParent(ReflectionHelpers.createNullProxy(ViewParent.class)); assertThat(view.isShown()).isTrue(); shadowOf(view).setMyParent(null); ViewGroup parent = new LinearLayout(context); parent.addView(view); ViewGroup grandParent = new LinearLayout(context); grandParent.addView(parent); grandParent.setVisibility(View.GONE); assertFalse(view.isShown()); }
@Test public void pendingTasks_areRunEagerly_whenActivityIsStarted_andSchedulerUnPaused() { final Scheduler s = Robolectric.getForegroundThreadScheduler(); final long startTime = s.getCurrentTime(); TestDelayedPostActivity activity = Robolectric.setupActivity(TestDelayedPostActivity.class); assertThat(activity.r1.wasRun).named("immediate task").isTrue(); assertThat(s.getCurrentTime()).named("currentTime").isEqualTo(startTime); }