### Question:
SRUHttpClient implements ExternalCatalogue { @Override public final SearchResultInfo getByField(String targetString, String term, String parameter, String mediaType) throws IOException { Target target = Target.valueOf(targetString.toUpperCase()); final StringWriter writer; writer = new StringWriter(); long numberOfRecords = 0; long nextRecordPosition = 0; try ( CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse httpResponse = httpClient.execute( new HttpGet(getURL(target, term, target.getParameterMap().getOrDefault(parameter, parameter)))) ) { if (httpResponse.getStatusLine().getStatusCode() == Response.Status.OK.getStatusCode()) { final HttpEntity entity = httpResponse.getEntity(); final byte[] xml = IOUtils.toByteArray(entity.getContent()); DocumentBuilderFactory builderfactory = DocumentBuilderFactory.newInstance(); builderfactory.setNamespaceAware(false); DocumentBuilder builder = builderfactory.newDocumentBuilder(); Document xmlDocument = builder.parse(new ByteArrayInputStream(xml)); XPathFactory factory = javax.xml.xpath.XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression numberOfRecordsXPath = xPath.compile(" numberOfRecords = Math.round((Double) numberOfRecordsXPath.evaluate(xmlDocument, XPathConstants.NUMBER)); XPathExpression nextRecordPositionXPath = xPath.compile(" nextRecordPosition = Math.round((Double) nextRecordPositionXPath.evaluate(xmlDocument, XPathConstants.NUMBER)); Source s = new StreamSource(new ByteArrayInputStream(xml)); final StreamResult streamResult = new StreamResult(writer); try { t.transform(s, streamResult); } catch (TransformerException e) { e.printStackTrace(); } EntityUtils.consume(entity); } } catch (ParserConfigurationException | SAXException | XPathExpressionException e) { e.printStackTrace(); } return new SearchResultInfo(writer.toString(), numberOfRecords, nextRecordPosition); } SRUHttpClient(String url); @Override final SearchResultInfo getByField(String targetString, String term, String parameter, String mediaType);  }### Answer:
@Test public void test_it_gets_a_single_MARC_record_by_isbn() throws IOException { sruServiceMock.getSingleMarcRecordExpectation(); SRUHttpClient sruHttpClient = new SRUHttpClient(String.format("http: SearchResultInfo response = sruHttpClient.getByField("bibbi", "123123123", "isbn", "Book"); final String marcXmlContent = response.getMarcXmlContent(); assertTrue(marcXmlContent.contains("collection")); assertTrue(marcXmlContent.contains("Dostojevskij, Fjodor Mikhajlovitsj")); }
@Test public void test_it_gets_a_single_MARC_record_by_ean() throws IOException { sruServiceMock.getSingleMarcRecordExpectation(); SRUHttpClient sruHttpClient = new SRUHttpClient(String.format("http: SearchResultInfo response = sruHttpClient.getByField("bibbi", "123123123", "ean", "Book"); final String marcXmlContent = response.getMarcXmlContent(); assertTrue(marcXmlContent.contains("collection")); assertTrue(marcXmlContent.contains("Dostojevskij, Fjodor Mikhajlovitsj")); }
@Test public void test_it_gets_a_single_MARC_record_by_isbn_for_micromarc() throws IOException { sruServiceMock.getMicroMarcSingleMarcRecordExpectation(); SRUHttpClient sruHttpClient = new SRUHttpClient(String.format("http: SearchResultInfo response = sruHttpClient.getByField("bibbi", "123123123", "isbn", "Book"); final String marcXmlContent = response.getMarcXmlContent(); assertTrue(marcXmlContent.contains("collection")); assertTrue(marcXmlContent.contains("Verdens fineste julefortellinger")); }