### Question:
PowerTracker { public boolean isCharging() { return mIsCharging.get(); } PowerTracker(Context context, PowerManager powerManager); void onBootCompleted(); void addListener(Listener listener); boolean isInPowerSave(); boolean isCharging(); boolean isDeviceIdle(); void dump(IndentingPrintWriter ipw);  }### Answer:
@Test public void testChargingState() { Assert.assertFalse(powerTracker.isCharging()); shadowApplication.sendBroadcast(new Intent(Intent.ACTION_POWER_CONNECTED)); Assert.assertTrue(powerTracker.isCharging()); verify(mockListener).onChargingStateChanged(); reset(mockListener); shadowApplication.sendBroadcast(new Intent(Intent.ACTION_POWER_DISCONNECTED)); Assert.assertFalse(powerTracker.isCharging()); verify(mockListener).onChargingStateChanged(); }
@Test public void testChargingState() { assertFalse(powerTracker.isCharging()); context.sendBroadcast(new Intent(Intent.ACTION_POWER_CONNECTED)); assertTrue(powerTracker.isCharging()); verify(mockListener).onChargingStateChanged(); reset(mockListener); context.sendBroadcast(new Intent(Intent.ACTION_POWER_DISCONNECTED)); assertFalse(powerTracker.isCharging()); verify(mockListener).onChargingStateChanged(); }