@Test public void safeExecutorOnExecutor_beforeICS_withNullParam_shouldCallExecute() throws Exception { Robolectric.Reflection.setFinalStaticField( Build.VERSION.class, "SDK_INT", HONEYCOMB_MR2.getApiLevel()); AsyncTasks.safeExecuteOnExecutor(asyncTask, (String) null); verify(asyncTask).execute(eq((String) null)); }
@Test public void safeExecuteOnExecutor_atLeastICS_shouldCallExecuteWithParamsWithExecutor() throws Exception { Robolectric.Reflection.setFinalStaticField( Build.VERSION.class, "SDK_INT", ICE_CREAM_SANDWICH.getApiLevel()); AsyncTasks.safeExecuteOnExecutor(asyncTask, "goodbye"); verify(asyncTask).executeOnExecutor(eq(THREAD_POOL_EXECUTOR), eq("goodbye")); }
@Test public void safeExecutorOnExecutor_atLeastICS_withNullAsyncTask_shouldThrowIllegalArgumentException() throws Exception { Robolectric.Reflection.setFinalStaticField( Build.VERSION.class, "SDK_INT", ICE_CREAM_SANDWICH.getApiLevel()); try { AsyncTasks.safeExecuteOnExecutor(null, "hello"); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException exception) { // pass } }
public static void setSdkVersionInt(int version) { Robolectric.Reflection.setFinalStaticField(Build.VERSION.class, "SDK_INT", version); }