@Test public void responseOk () throws Exception { Chave request = new Chave();
ResponseService responseMock = mock(ResponseService.class);
when(responseMock.getResponseBody(Mensagem[].class)).thenReturn(new Mensagem[0]);
RequestService requestMock = mock(RequestService.class);
when(requestMock.post("{\"texto\":\"oi\"}")).thenReturn(responseMock);
ConnectionTemplate connectionMock = mock(ConnectionTemplate.class);
when(connectionMock.start()).thenReturn(requestMock); // aqui quando roda lança uma null pointer exception, ppois o método .start() eh final
Factory factoryMock = Mockito.mock(Factory.class);
when(factoryMock.getICPConnectionTemplate()).thenReturn(connectionMock);
controller.setFactory(factoryMock);
Response response = controller.alteraChave(request);
assertNotNull(response);
}