DeviceService { public Boolean isBlacklisted() throws IOException, JSONException { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId(); FluentResponse response = http() .context(context) .path(String.format("/api/is_blacklisted/%s", imei)) .get(); String responseAsString = CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); JSONObject device = new JSONObject(responseAsString); return device.optBoolean("blacklisted", false); } @Inject  DeviceService(RapidFtrApplication context); Boolean isBlacklisted(); void wipeData();  }
@Test public void shouldSetBlacklistedFlagToTrueIfDeviceBlacklistedRequestIsTrue() throws IOException, JSONException { getFakeHttpLayer() .addHttpResponseRule("GET", "http: new TestHttpResponse(200, "{\"blacklisted\":\"true\"}")); assertTrue(deviceService.isBlacklisted()); }
@Test public void shouldSetBlacklistedFlagToFalseIfDeviceBlacklistedRequestIsFalse() throws IOException, JSONException { getFakeHttpLayer() .addHttpResponseRule("GET", "http: new TestHttpResponse(200, "{\"blacklisted\":\"false\"}")); DeviceService service = new DeviceService(context); assertFalse(service.isBlacklisted()); }