I needed to do mocking with DAO, but the method receives a worksheet object and according to the id attribute of the Worksheet needs to return a different value.
How do I compare the worksheet ID correctly?
I want to test the readMetadados
that makes use of uploadDAO
, I want the return to be different according to the ID of the spreadsheet that testo. I expect an error, but I get a nullPointer
just because of the DAO mock:
@Bean
UploadDAO getUploadDAO() {
UploadDAO dao = Mockito.mock(UploadDAO.class);
File myFile = new File(URL_TEST, "click/T001.json");
Planilha planilha = new Planilha().setId("invalidFormat").setPath(URL_TEST.concat("click/T001.json"));
when(dao.getPlanilha(eq(planilha))).thenReturn(myFile);
return dao;
}
Test
@Test(expected = InternalServerErrorException.class)
public void testReadMetadados_invalidPlanilha_invalidFormat() throws Exception {
oknok.validacao.entities.Planilha actual = new Planilha().setPath(URL_TEST.concat("click/T001.json"))
.setId("invalidFormat");
planilhaReader.readMetadados(actual);
}