0

I just finished a development in Java 8 that i was working on, so now i need to make some unit tests with Mockito and JUnit, i already could make some of them with no problems but i just reached to a part of my code where i need to test a private method (imprimeDocumento) that is being called inside a public method (generarArchivoProd).

i read something about reflection to test private methods but i cannot understand that approach completely.

Could you help me to get an idea on how to achieve this?

My code looks like this:

    //PUBLIC METHOD
public void generarArchivoProd(int anio, int mes, int dia, String paginacion){
 
if("1".equals(paginacion){

 do this....

}
else{ 

do this instead....

}
 //PRIVATE METHOD CALLING
 this.imprimeDocumento(Long.value("0"),"",mes,anio,dia, paginacion);

}


//PRIVATE METHOD
private void imprimeDocumento(Long, int, int, int, String){
 ...............
}

Thanks in advance for your help

Erick Finn
  • 141
  • 7
  • 1
    You can't test that method independently. You'll have to call `generarArchivoProd` and verify that whatever `imprimeDocumento`'s side-effects are happened. Or create a new class and move `imprimeDocumento` into that. – tgdavies Nov 10 '22 at 20:36
  • Does this answer your question? [Testing Private method using mockito](https://stackoverflow.com/questions/8799439/testing-private-method-using-mockito) – fantaghirocco Nov 11 '22 at 00:17

0 Answers0