### Question:
MarcXmlRecordToMarcRecordTranslator implements Processor { @Override public void process(final Exchange exchange) throws Exception { final String marcXmlRecord = exchange.getIn().getBody(String.class); try { final MarcReader reader = new MarcXmlReader(new ByteArrayInputStream(marcXmlRecord.getBytes("UTF-8"))); if (reader.hasNext()) { final Record record = reader.next(); exchange.getIn().setBody(record); } else { log.error(MessageCatalog._00047_EMPTY_INCOMING_RECORD_STREAM); throw new IllegalArgumentException(MessageCatalog._00047_EMPTY_INCOMING_RECORD_STREAM); } } catch (final IllegalArgumentException exception) { throw exception; } catch (final Exception exception) { log.error(MessageCatalog._00047_EMPTY_INCOMING_RECORD_STREAM, exception); throw exception; } }  @Override void process(final Exchange exchange);  }### Answer:
@Test public void invalidStream() { final String invalidMarcXMLStream = randomString(); when (message.getBody(String.class)).thenReturn(invalidMarcXMLStream); try { cut.process(exchange); fail(); } catch (final Exception expected) { assertTrue(expected instanceof MarcException); } }
@Test public void nullStream() { when (message.getBody(String.class)).thenReturn(null); try { cut.process(exchange); fail(); } catch (final Exception expected) { assertTrue(expected instanceof NullPointerException); } }
@Test public void emptyStream() { final String emptyStream = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> " + "<marc:collection xmlns:marc=\"http: "xmlns:xsi=\"http: "xsi:schemaLocation=\"http: "</marc:collection>"; when (message.getBody(String.class)).thenReturn(emptyStream); try { cut.process(exchange); fail(); } catch (final Exception expected) { assertTrue(expected instanceof IllegalArgumentException); } }
@Test public void positive() throws Exception { final String stream = new String(Files.readAllBytes(Paths.get(new File("./src/test/resources/marcxml-artium.xml").toURI()))); when (message.getBody(String.class)).thenReturn(stream); cut.process(exchange); verify(message).setBody(any(Record.class)); }