/** * Inject app name version and version code in a format string. */ private String formatAppNameAndVersion(String format) { String appName = AppNameHelper.getAppName(mContext); return String.format(format, appName, mReleaseDetails.getShortVersion(), mReleaseDetails.getVersion()); }
@Test public void init() { new AppNameHelper(); }
@Test public void handleNotificationWithNullTitle() { String appName = "app-name"; mockStatic(AppNameHelper.class); when(AppNameHelper.getAppName(mContextMock)).thenReturn(appName); when(PushIntentUtils.getTitle(any(Intent.class))).thenReturn(null); PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationBuilderMock).setContentTitle(appName); verify(mNotificationManagerMock).notify(mDummyGoogleMessageId.hashCode(), mNotificationMock); }
notificationTitle = AppNameHelper.getAppName(context);
@Test public void handleNotificationWithEmptyTitle() { String appName = "app-name"; mockStatic(AppNameHelper.class); when(AppNameHelper.getAppName(mContextMock)).thenReturn(appName); when(PushIntentUtils.getTitle(any(Intent.class))).thenReturn(""); PushNotifier.handleNotification(mContextMock, new Intent()); verify(mNotificationBuilderMock).setContentTitle(appName); }
when(AppNameHelper.getAppName(mContext)).thenReturn("hardcoded-app-name");
@Test public void localizedAppName() { String appName = "localized-app-name"; int resId = 42; Context context = mock(Context.class); ApplicationInfo applicationInfo = mock(ApplicationInfo.class); when(context.getApplicationInfo()).thenReturn(applicationInfo); Whitebox.setInternalState(applicationInfo, "labelRes", resId); when(context.getString(resId)).thenReturn(appName); String retrievedAppName = AppNameHelper.getAppName(context); assertEquals(appName, retrievedAppName); }
@Test public void nonLocalizedAppName() { String appName = "non-localized-app-name"; Context context = mock(Context.class); ApplicationInfo applicationInfo = mock(ApplicationInfo.class); when(context.getApplicationInfo()).thenReturn(applicationInfo); Whitebox.setInternalState(applicationInfo, "labelRes", 0); Whitebox.setInternalState(applicationInfo, "nonLocalizedLabel", appName); String retrievedAppName = AppNameHelper.getAppName(context); assertEquals(appName, retrievedAppName); } }
when(AppNameHelper.getAppName(mContext)).thenReturn("unit-test-app"); when(mContext.getString(R.string.appcenter_distribute_update_dialog_message_optional)).thenReturn("%s%s%d"); when(mContext.getString(R.string.appcenter_distribute_update_dialog_message_mandatory)).thenReturn("%s%s%d");