### Question:
JobHttpMessageConverter implements HttpMessageConverter<Job> { @Override public Job read(Class<? extends Job> clazz, HttpInputMessage inputMessage) throws IOException { XmlResponse response = new XmlResponse(inputMessage.getBody()); return new Job() .setName(response.evaluateAsString("displayName/text()")) .setUrl(response.evaluateAsString("buildable")) .setInQueue(response.evaluateAsBoolean("nextBuildNumber")) .setLastBuildNumber(response.evaluateAsLong("/*/lastBuild/number")); }  @Override boolean canRead(Class<?> clazz); @Override boolean canWrite(Class<?> clazz); @Override Job read(Class<? extends Job> clazz, HttpInputMessage inputMessage); @Override void write(Job t, String contentType, HttpOutputMessage outputMessage);  }### Answer:
@Test public void read_SimpleJob() throws Exception { HttpInputMessage inputMessage = new MockHttpInputMessage("" + "<freeStyleProject>" + "<name>vacuum.my.room</name>" + "<displayName>Vacuum my room</displayName>" + "<url>http: + "<buildable>true</buildable>" + "<nextBuildNumber>23</nextBuildNumber>" + "<inQueue>false</inQueue>" + "</freeStyleProject>"); Job job = converter.read(Job.class, inputMessage); assertEquals("vacuum.my.room", job.getName()); assertEquals("Vacuum my room", job.getDisplayName()); assertEquals("http: assertTrue(job.getBuildable()); assertEquals(new Long(23), job.getNextBuildNumber()); assertFalse(job.getInQueue()); assertNull(job.getLastBuildNumber()); }
@Test public void read_JobWithParameters() throws Exception { HttpInputMessage inputMessage = new MockHttpInputMessage("" + "<freeStyleProject>" + "<action>" + "<parameterDefinition>" + "<defaultParameterValue>" + "<value>Daniel</value>" + "</defaultParameterValue>" + "<description/>" + "<name>FIRST_NAME</name>" + "<type>StringParameterDefinition</type>" + "</parameterDefinition>" + "</action>" + "<name>vacuum.my.room</name>" + "<displayName>Vacuum my room</displayName>" + "</freeStyleProject>"); Job job = converter.read(Job.class, inputMessage); assertEquals("vacuum.my.room", job.getName()); assertEquals("Vacuum my room", job.getDisplayName()); }
@Test public void read_JobWithLastBuild() throws IOException { HttpInputMessage inputMessage = new MockHttpInputMessage("" + "<freeStyleProject>" + "<name>vacuum.my.room</name>" + "<displayName>Vacuum my room</displayName>" + "<url>http: + "<buildable>true</buildable>" + "<nextBuildNumber>23</nextBuildNumber>" + "<inQueue>false</inQueue>" + "<lastBuild>" + "<number>42</number>" + "<url>http: + "</lastBuild>" + "</freeStyleProject>"); Job job = converter.read(Job.class, inputMessage); assertEquals(Long.valueOf(42L), job.getLastBuildNumber()); }