@Test
public void testHandleErrorOnNotSuccessfulResponse() {

    RESTWorkItemHandler handler = new RESTWorkItemHandler();
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameter("Url",
                          serverURL + "/notexisting");
    workItem.setParameter("Method",
                          "GET");
    workItem.setParameter("HandleResponseErrors",
                          "true");
    WorkItemManager manager = new TestWorkItemManager();
    try {
        handler.executeWorkItem(workItem,
                                manager);
        fail("Should throw exception as it was instructed to do so");
    } catch (WorkItemHandlerRuntimeException ex) {
        RESTServiceException e = (RESTServiceException) ex.getCause().getCause();
        assertEquals(405,
                     e.getStatus());
        assertEquals(serverURL + "/notexisting",
                     e.getEndoint());
        assertEquals("",
                     e.getResponse());
    }
}