### Question:
MetadataHandler extends AbstractClientProxyHandler { @Override MessageProcessorBase createRequestProcessor(String target, HttpServletRequest request, HttpServletResponse response, OpMonitoringData opMonitoringData) { log.trace("createRequestProcessor({})", target); if (!isGetRequest(request)) { return null; } if (target == null) { throw new CodedException(X_INVALID_REQUEST, "Target must not be null"); } MetadataClientRequestProcessor processor = new MetadataClientRequestProcessor(target, request, response); if (processor.canProcess()) { log.trace("Processing with MetadataClientRequestProcessor"); return processor; } return null; } MetadataHandler(HttpClient client);   }### Answer:
@Test public void shouldNotCreateProcessorForPostRequest() throws Exception { when(mockRequest.getMethod()).thenReturn("POST"); MetadataHandler handlerToTest = new MetadataHandler(httpClientMock); MessageProcessorBase returnValue = handlerToTest.createRequestProcessor("something", mockRequest, mockResponse, null); assertNull("Was expecting a null return value", returnValue); }
@Test public void shouldNotCreateProcessorForUnprocessableRequest() throws Exception { when(mockRequest.getMethod()).thenReturn("GET"); MetadataHandler handlerToTest = new MetadataHandler(httpClientMock); MessageProcessorBase returnValue = handlerToTest.createRequestProcessor("something", mockRequest, mockResponse, null); assertNull("Was expecting a null return value", returnValue); }
@Test public void shouldThrowWhenTargetNull() throws Exception { MetadataHandler handlerToTest = new MetadataHandler(httpClientMock); when(mockRequest.getMethod()).thenReturn("GET"); thrown.expect(CodedException.class); thrown.expect(hasProperty("faultCode", is(X_INVALID_REQUEST))); thrown.expectMessage(CoreMatchers.containsString("Target must not be null")); handlerToTest.createRequestProcessor(null, mockRequest, mockResponse, null); }
@Test public void shouldReturnProcessorWhenAbleToProcess() throws Exception { when(mockRequest.getMethod()).thenReturn("GET"); MetadataHandler handlerToTest = new MetadataHandler(httpClientMock); MessageProcessorBase result = handlerToTest.createRequestProcessor( LIST_CLIENTS, mockRequest, mockResponse, null); assertNotNull("Was expecting actual message processor"); assertThat("Message processor is of wrong type", result, instanceOf(MetadataClientRequestProcessor.class)); }