mardi 26 mai 2015

How to mocking according to the received parameter?

According to the parameters that the method receives, desire to return something different.
How to do it using the Mockito?

For example, according to the id of "Planilha" I desire a different return but do not know how to make this equality.

My 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);
    }

My 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(Matchers.eq(planilha))).thenReturn(myFile);
            return dao;
        }

Aucun commentaire:

Enregistrer un commentaire