@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); }
@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 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 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); }
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); }
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);  }