ServiceData { static ServiceData fromJsonString(final String jsonString) { if (jsonString == null || jsonString.isEmpty()) { throw new IllegalArgumentException("json string can not be null or empty"); } final List<Endpoint> endpoints = new ArrayList<>(); final JSONObject json = new JSONObject(jsonString); final JSONArray epList = json.getJSONArray("endpoints"); for (int i = 0; i < epList.length(); i++) { endpoints.add(Endpoint.fromJson(epList.getJSONObject(i).toString())); } return new ServiceData(endpoints); } ServiceData();   ServiceData(final List<Endpoint> endpointList); Endpoint getEndpoint(final String name); boolean addEndpoint(final Endpoint endpoint); boolean removeEndpoint(final Endpoint endpoint);  }
@Test (expected = IllegalArgumentException.class) public void testInvalidJson1() { final String nullStr = null; ServiceData.fromJsonString(nullStr); }
@Test (expected = IllegalArgumentException.class) public void testInvalidJson2() { ServiceData.fromJsonString(""); }
@Test (expected = org.json.JSONException.class) public void testInvalidJson3() { ServiceData.fromJsonString("}{"); }
@Test (expected = org.json.JSONException.class) public void testInvalidJson4() { ServiceData.fromJsonString("{ \"foo\": 12 }"); }