IntentHelper { public static String getExtraString(final Intent intent, final String key, final String defaultValue) { final String extra = intent.getStringExtra(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 testGetStringExtraDefaultValue() { assertEquals("my_default", IntentHelper.getExtraString(new Intent(), "myStringKey", "my_default")); }
@Test public void testGetStringExtraValue() { assertEquals("awesomey", IntentHelper.getExtraString(new Intent().putExtra("myStringKey", "awesomey"), "myStringKey", "default")); }
@Test public void testGetStringExtra() { final Intent intent = mock(Intent.class); IntentHelper.getExtraString(intent, "StringExtra", null); verify(intent).getStringExtra("StringExtra"); verifyNoMoreInteractions(intent); }