IntentUtils { @NonNull public static String packageNameFrom(final String intentDataString) { val dataArray = nullToEmpty(intentDataString).split(":"); return (dataArray.length == 2) ? dataArray[1] : ""; } private  IntentUtils(); @NonNull static String packageNameFrom(final String intentDataString);  }
@Test public void shouldResultEmptyPackageNameForInvalidDataString() { val resultForNull = IntentUtils.packageNameFrom(null); assertThat(resultForNull, is("")); val resultForEmpty = IntentUtils.packageNameFrom(""); assertThat(resultForEmpty, is("")); val resultForInvalidFormat = IntentUtils.packageNameFrom("com.abc"); assertThat(resultForInvalidFormat, is("")); }
@Test public void shouldReturnPackageNameIfDataStringFollowsSpecificPattern() { val packageName = IntentUtils.packageNameFrom("package:com.abc"); assertThat(packageName, is("com.abc")); }