IntentHelper { public static Bundle getExtraBundle(final Intent intent, final String key, final Bundle defaultValue) { final Bundle extra = intent.getBundleExtra(key); return extra != null ? extra : defaultValue; } 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 testGetBundleExtra() { final Intent intent = mock(Intent.class); IntentHelper.getExtraBundle(intent, "BundleExtra", null); verify(intent).getBundleExtra("BundleExtra"); verifyNoMoreInteractions(intent); }
@Test public void testGetBundleExtraDefaultValue() { final Bundle defaultValue = new Bundle(); assertEquals(defaultValue, IntentHelper.getExtraBundle(new Intent(), "myBundleKey", defaultValue)); }
@Test public void testGetBundleExtraValue() { final Bundle bundle = new Bundle(); bundle.putString("test", "1234"); assertEquals(bundle, IntentHelper.getExtraBundle(new Intent().putExtra("myBundleKey", bundle), "myBundleKey", null)); }