NotificationIconDecorator extends HaloNotificationDecorator { @Override public NotificationCompat.Builder decorate(@NonNull NotificationCompat.Builder builder, @NonNull Bundle bundle) { String iconName = bundle.getString("icon"); if (TextUtils.isEmpty(iconName)) { iconName = ""; } Resources resources = mContext.getResources(); int drawableId = resources.getIdentifier(iconName, "drawable", mContext.getPackageName()); if (drawableId == 0) { drawableId = resources.getIdentifier(iconName, "mipmap", mContext.getPackageName()); } if (drawableId == 0) { try { drawableId = mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), PackageManager.GET_META_DATA).icon; } catch (PackageManager.NameNotFoundException e) { Halog.e(getClass(), "Could not get the application icon."); } } builder.setSmallIcon(drawableId); return chain(builder, bundle); } NotificationIconDecorator(Context context, HaloNotificationDecorator decorator); @Override NotificationCompat.Builder decorate(@NonNull NotificationCompat.Builder builder, @NonNull Bundle bundle);  }
@Test public void emptyIconTest() { final boolean[] marker = new boolean[1]; PackageManager manager = mock(PackageManager.class); when(mContext.getPackageManager()).thenReturn(manager); ApplicationInfo info = mock(ApplicationInfo.class); info.icon = 2; try { when(manager.getApplicationInfo(null, PackageManager.GET_META_DATA)).thenReturn(info); } catch (PackageManager.NameNotFoundException e) { Assert.fail(); } Bundle bundle = BundleTestUtils.builder().build(); when(getBuilder().setSmallIcon(any(Integer.class))).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { marker[0] = true; return null; } }); getDecorator().decorate(getBuilder(), bundle); Assert.assertTrue(marker[0]); }