AppUtils { public static boolean wasInstalledFromGooglePlay(Context context) { String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName()); return "com.android.vending".equals(installer); } private  AppUtils(); static String getVersion(); static boolean hasGooglePlayServices(Context context); static boolean wasInstalledFromGooglePlay(Context context); static boolean isGeolocAllowed(Context context);  }
@Test public void should_return_true_when_app_was_installed_from_google_play() { String packageName = "com.nilhcem.bblfr"; String playStorePackageName = "com.android.vending"; when(context.getPackageName()).thenReturn(packageName); when(context.getPackageManager().getInstallerPackageName(packageName)).thenReturn(playStorePackageName); boolean result = AppUtils.wasInstalledFromGooglePlay(context); assertThat(result).isTrue(); }
@Test public void should_return_false_when_app_was_not_installed_from_google_play() { String playStorePackageName = "com.amazon.venezia"; when(context.getPackageManager().getInstallerPackageName(anyString())).thenReturn(playStorePackageName); boolean result = AppUtils.wasInstalledFromGooglePlay(context); assertThat(result).isFalse(); }