### Question:
BatteryNotLowTracker extends BroadcastReceiverConstraintTracker<Boolean> { @Override public void onBroadcastReceive(Context context, @NonNull Intent intent) { if (intent.getAction() == null) { return; } Log.d(TAG, String.format("Received %s", intent.getAction())); switch (intent.getAction()) { case Intent.ACTION_BATTERY_OKAY: setState(true); break; case Intent.ACTION_BATTERY_LOW: setState(false); break; } } BatteryNotLowTracker(Context context); @Override Boolean getInitialState(); @Override IntentFilter getIntentFilter(); @Override void onBroadcastReceive(Context context, @NonNull Intent intent);  }### Answer:
@Test @SmallTest public void testOnBroadcastReceive_invalidIntentAction_doesNotNotifyListeners() { mockContextReturns( createBatteryChangedIntent(PLUGGED_IN, KNOWN_STATUS, ABOVE_LOW_PERCENTAGE)); mTracker.addListener(mListener); verify(mListener).onConstraintChanged(true); mTracker.onBroadcastReceive(mMockContext, new Intent("INVALID")); verifyNoMoreInteractions(mListener); }
@Test @SmallTest public void testOnBroadcastReceive_notifiesListeners() { mockContextReturns( createBatteryChangedIntent(NOT_PLUGGED_IN, KNOWN_STATUS, AT_LOW_PERCENTAGE)); mTracker.addListener(mListener); verify(mListener).onConstraintChanged(false); mTracker.onBroadcastReceive(mMockContext, new Intent(Intent.ACTION_BATTERY_OKAY)); verify(mListener).onConstraintChanged(true); mTracker.onBroadcastReceive(mMockContext, new Intent(Intent.ACTION_BATTERY_LOW)); verify(mListener, times(2)).onConstraintChanged(false); }