IntentHelper { public static CharSequence getExtraCharSequence(final Intent intent, final String key, final CharSequence defaultValue) { final CharSequence extra = intent.getCharSequenceExtra(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 testGetCharSequenceExtra() { final Intent intent = mock(Intent.class); IntentHelper.getExtraCharSequence(intent, "CharSequenceExtra", null); verify(intent).getCharSequenceExtra("CharSequenceExtra"); verifyNoMoreInteractions(intent); }
@Test public void testGetCharSequenceExtraDefaultValue() { assertEquals("another_default", IntentHelper.getExtraCharSequence(new Intent(), "myCharSequenceKey", "another_default")); }
@Test public void testGetCharSequenceExtraValue() { assertEquals("awesomeness", IntentHelper.getExtraCharSequence(new Intent().putExtra("myCharSequenceKey", (CharSequence) "awesomeness"), "myCharSequenceKey", "default")); }