### Question:
ClientConverter { public Client convertToClient(String clientId, int statusCode, String xml) throws ParserConfigurationException, SAXException, IOException { LOG.debug("oauthAuthorize returned the following xml for client '{}': statuscode='{}' xml: '{}'", clientId, statusCode, xml); Map<String, MetricUsage> limitedMetricUsages = new HashMap<>(); final ClientSyncState state; if (isServerError(statusCode)) { state = ClientSyncState.SERVER_ERROR; } else if (isApplicationNotFound(clientId, statusCode, xml)) { state = ClientSyncState.APPLICATION_NOT_FOUND; } else if (xml == null || xml.isEmpty()) { LOG.warn(APIM_2002.pattern(), clientId, statusCode); state = ClientSyncState.UNKNOWN; } else { final Element xmlRoot = createXMLRoot(xml); limitedMetricUsages = parseLimitedMetricUsagesFromXml(xmlRoot, clientId); if (statusCode == HttpResponseCodes.SC_OK) { state = ClientSyncState.OK; }else if (isConflictAndLimitExceeded(statusCode, xmlRoot)) { state = ClientSyncState.USAGE_LIMITS_EXCEEDED; } else { state = ClientSyncState.UNKNOWN; } } return new Client(clientId, limitedMetricUsages, state); }  Client convertToClient(String clientId, int statusCode, String xml);  }### Answer:
@Test public void convert200Ok() throws IOException, ParserConfigurationException, SAXException { String text = loadTextFromResource("stubs/plan/watchdog-200.xml"); Client client = testee.convertToClient(CLIENT_ID, SC_OK, text); assertThat(client.getId(), is(CLIENT_ID)); assertThat(client.getSyncState(), is(OK)); assertThat(client.getUsage("hits").getMetricSysName(), is("hits")); }
@Test public void convert409Conflict() throws IOException, ParserConfigurationException, SAXException { String text = loadTextFromResource("stubs/plan/watchdog-409.xml"); Client client = testee.convertToClient(CLIENT_ID, SC_CONFLICT, text); assertThat(client.getId(), is(CLIENT_ID)); assertThat(client.getSyncState(), is(USAGE_LIMITS_EXCEEDED)); assertThat(client.getUsage("hits").getMetricSysName(), is("hits")); }
@Test public void convert500ServerError() throws IOException, ParserConfigurationException, SAXException { Client client = testee.convertToClient(CLIENT_ID, SC_SERVICE_UNAVAILABLE, ""); assertThat(client.getId(), is(CLIENT_ID)); assertThat(client.getSyncState(), is(SERVER_ERROR)); assertThat(client.getUsage("hits"), is(nullValue())); }
@Test public void convert200Empty() throws IOException, ParserConfigurationException, SAXException { Client client = testee.convertToClient(CLIENT_ID, SC_OK, ""); assertThat(client.getId(), is(CLIENT_ID)); assertThat(client.getSyncState(), is(UNKNOWN)); assertThat(client.getUsage("hits"), is(nullValue())); }
@Test public void convert404ApplicationNotFound() throws IOException, ParserConfigurationException, SAXException { Client client = testee.convertToClient(CLIENT_ID, SC_NOT_FOUND, "application_not_found"); assertThat(client.getId(), is(CLIENT_ID)); assertThat(client.getSyncState(), is(APPLICATION_NOT_FOUND)); assertThat(client.getUsage("hits"), is(nullValue())); }