IntentHelper { @NonNull public static Uri getIntentDataNonNull(final Intent intent) { checkNotNull(intent, "intent is null"); return checkNotNull(intent.getData(), "intentData is null"); } private  IntentHelper(); @NonNull static Uri getIntentData(final Intent intent); @NonNull static Uri getIntentDataNonNull(final Intent intent); @Nullable static Uri getIntentDataNullable(final Intent intent); static String getExtraString(final Intent intent, final String key, final String defaultValue); static int getExtraInt(final Intent intent, final String key, final int defaultValue); static boolean getExtraBoolean(final Intent intent, final String key, final boolean defaultValue); static float getExtraFloat(final Intent intent, final String key, final float defaultValue); static double getExtraDouble(final Intent intent, final String key, final double defaultValue); static byte getExtraByte(final Intent intent, final String key, final byte defaultValue); static short getExtraShort(final Intent intent, final String key, final short defaultValue); static char getExtraChar(final Intent intent, final String key, final char defaultValue); static long getExtraLong(final Intent intent, final String key, final long defaultValue); static CharSequence getExtraCharSequence(final Intent intent, final String key, final CharSequence defaultValue); static Bundle getExtraBundle(final Intent intent, final String key, final Bundle defaultValue); static T getExtraSerializable(final Intent intent, final String key, final T defaultValue); static T getExtraParcelable(final Intent intent, final String key, final T defaultValue);  }
@Test public void testGetIntentDataNonNullWithNullIntent() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("intent is null"); IntentHelper.getIntentDataNonNull(null); }
@Test public void testGetIntentDataNonNullWithNullIntentData() { final Intent intent = mock(Intent.class); doReturn(null).when(intent).getData(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("intentData is null"); IntentHelper.getIntentDataNonNull(intent); }
@Test public void testGetIntentDataNonNullWithNonNullIntentData() { final Intent intent = mock(Intent.class); final Uri uri = mock(Uri.class); doReturn(uri).when(intent).getData(); assertEquals(uri, IntentHelper.getIntentDataNonNull(intent)); }