ComponentNameUtils { @NonNull public static ComponentName fromFlattenString(@Nullable final String flattenComponentName) { val parts = nullToEmpty(flattenComponentName).split(COMPONENT_NAME_SEPARATOR); return (parts.length == 2) ? new ComponentName(parts[0], parts[1]) : DUMMY_COMPONENT; } private  ComponentNameUtils(); @NonNull static String packageNameFrom(@Nullable final String flattenComponentName); @NonNull static ComponentName fromFlattenString(@Nullable final String flattenComponentName); static final ComponentName DUMMY_COMPONENT; }
@Test public void shouldBuildComponentNameFromFlattenString() { val componentName = ComponentNameUtils.fromFlattenString("com.abc/MyActivity"); assertThat(componentName.getPackageName(), is("com.abc")); assertThat(componentName.getClassName(), is("MyActivity")); }
@Test public void shouldReturnDummyComponentNameForInvalidFlattenString() { val resultForNull = ComponentNameUtils.fromFlattenString(null); assertThat(resultForNull, is(ComponentNameUtils.DUMMY_COMPONENT)); val resultForEmpty = ComponentNameUtils.fromFlattenString(""); assertThat(resultForEmpty, is(ComponentNameUtils.DUMMY_COMPONENT)); val resultForInvalidFormat = ComponentNameUtils.fromFlattenString("com.abc.MyActivity"); assertThat(resultForInvalidFormat, is(ComponentNameUtils.DUMMY_COMPONENT)); }