### Question:
OnUpgradeReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { if (intent.getDataString().contains("com.nightscout.android")) { Intent mainActivity = new Intent(context, MainActivity.class); mainActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(mainActivity); } }  @Override void onReceive(final Context context, final Intent intent);  }### Answer:
@Test public void testOnUpgradeReceiverRestartsMainActivity() { Intent intent = new Intent(Intent.ACTION_PACKAGE_REPLACED); Uri dataUri = Uri.parse("package:com.nightscout.android"); intent.setData(dataUri); OnUpgradeReceiver onUpgradeReceiver = new OnUpgradeReceiver(); onUpgradeReceiver.onReceive(activity.getApplicationContext(),intent); Intent anIntent = getShadowApplication().getNextStartedActivity(); assertThat(anIntent.getComponent().getClassName(), is(MainActivity.class.getName())); }