NsClientReceiverDelegate { boolean calculateStatus(final EventChargingState ev) { boolean chargingOnly = SP.getBoolean(R.string.key_ns_chargingonly, false); boolean newAllowedState = true; if (!ev.isCharging() && chargingOnly) { newAllowedState = false; } return newAllowedState; }    }
@Test public void testCalculateStatusChargingState() { PowerMockito.mockStatic(SP.class); when(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(false); EventChargingState ev = new EventChargingState(true); assertTrue(sut.calculateStatus(ev)); ev = new EventChargingState(false); assertTrue(sut.calculateStatus(ev)); when(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(true); ev = new EventChargingState(true); assertTrue(sut.calculateStatus(ev)); ev = new EventChargingState(false); assertTrue(!sut.calculateStatus(ev)); }
@Test public void testCalculateStatusNetworkState() { PowerMockito.mockStatic(SP.class); when(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(false); when(SP.getString(anyInt(), anyString())).thenReturn(""); EventNetworkChange ev = new EventNetworkChange(); ev.setSsid("<unknown ssid>"); ev.setMobileConnected(true); ev.setWifiConnected(true); assertTrue(sut.calculateStatus(ev)); ev.setSsid("test"); when(SP.getString(anyInt(), anyString())).thenReturn("\"test\""); assertTrue(sut.calculateStatus(ev)); ev.setSsid("\"test\""); assertTrue(sut.calculateStatus(ev)); ev.setWifiConnected(false); assertTrue(sut.calculateStatus(ev)); when(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(true); ev.setWifiConnected(true); assertTrue(sut.calculateStatus(ev)); ev.setWifiConnected(false); assertTrue(!sut.calculateStatus(ev)); when(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(false); ev.setWifiConnected(false); ev.setRoaming(true); assertTrue(!sut.calculateStatus(ev)); when(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false); when(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true); ev.setWifiConnected(false); ev.setRoaming(true); assertTrue(sut.calculateStatus(ev)); when(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true); when(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true); ev.setWifiConnected(false); ev.setRoaming(true); assertTrue(!sut.calculateStatus(ev)); when(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true); when(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true); ev.setWifiConnected(true); ev.setRoaming(true); assertTrue(sut.calculateStatus(ev)); when(SP.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false); when(SP.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(false); ev.setWifiConnected(true); ev.setRoaming(true); assertTrue(sut.calculateStatus(ev)); }