### Question:
PRClient { public List<Provider> getProviders() { ClientResponse response = webResource.accept(MediaType.APPLICATION_XML).get(ClientResponse.class); if (response.getStatus() != 200) { logger.info("ERROR getting list of providers: " + response.getEntity(String.class)); return new ArrayList<Provider>(); } Collection collection; try { JAXBContext jaxbContext = JAXBContext.newInstance(Collection.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); collection = (Collection) jaxbUnmarshaller.unmarshal(new StringReader(response.getEntity(String.class))); } catch(Exception exception) { logger.info("Imposible to parse this list of providers"); logger.info("Exception: " + exception.toString()); return new ArrayList<Provider>(); } if(collection != null) { Items items = collection.getItems(); if(items != null) { return items.getProviders(); } else { return new ArrayList<Provider>(); } } else { return new ArrayList<Provider>(); } } PRClient(); List<Provider> getProviders(); VmManagerClient getVMMClient(int id);  }### Answer:
@Test public void getProvidersTest() { Configuration.providerRegistryEndpoint = mBaseURL; String collection = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<collection xmlns=\"http: "<items offset=\"0\" total=\"1\">" + "<provider href=\"/1\">" + "<id>1</id>" + "<name>default</name>" + "<vmm-url>http: "<slam-url>http: "<amqp-url>amqp: "<link rel=\"parent\" href=\"/\" type=\"application/xml\"/>" + "<link rel=\"self\" href=\"/1\" type=\"application/xml\"/>" + "</provider>" + "</items>" + "<link rel=\"self\" href=\"/\" type=\"application/xml\"/>" + "</collection>"; mServer.addPath("/", collection); PRClient client = new PRClient(); assertEquals(1, client.getProviders().size()); assertEquals("default", client.getProviders().get(0).getName()); }
@Test public void getProvidersNoItemsTest() { Configuration.providerRegistryEndpoint = mBaseURL; String collection = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<collection xmlns=\"http: "<link rel=\"self\" href=\"/\" type=\"application/xml\"/>" + "</collection>"; mServer.addPath("/", collection); PRClient client = new PRClient(); assertEquals(0, client.getProviders().size()); }
@Test public void getProvidersParsingErrorTest() { Configuration.providerRegistryEndpoint = mBaseURL; String collection = ""; mServer.addPath("/", collection); PRClient client = new PRClient(); assertEquals(0, client.getProviders().size()); }
@Test public void getProvidersWrongResponseCodeTest() { Configuration.providerRegistryEndpoint = mBaseURL; String collection = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<collection xmlns=\"http: "<items offset=\"0\" total=\"1\">" + "<provider href=\"/1\">" + "<id>1</id>" + "<name>default</name>" + "<vmm-url>http: "<slam-url>http: "<amqp-url>amqp: "<link rel=\"parent\" href=\"/\" type=\"application/xml\"/>" + "<link rel=\"self\" href=\"/1\" type=\"application/xml\"/>" + "</provider>" + "</items>" + "<link rel=\"self\" href=\"/\" type=\"application/xml\"/>" + "</collection>"; mServer.addPath("/", collection, 500); PRClient client = new PRClient(); assertEquals(0, client.getProviders().size()); }