I have the following method:
public void ingresarCarga() {
Integer idCarga = ingresoDao.ingresar();
ResultadoIngreso resultado;
do {
resultado = archivoDao.procesar();
try {
if(resultado.getCodigo() == 1){
Thread.sleep(10000);
}
} catch (InterruptedException e) {
LOGGER.info("InterruptedException");
}
}while (resultado.getCodigo() == 1);
}
Clearly you can notice that you can enter an infinite loop, but the code is not wrong. When trying to do the coverage tests I find the problem trying to cover the case when the answer is -60.
I have tried in different ways and none has worked for me:
@Test(timeout=11000, expected = Exception.class)
public void testIngreso2() throws Exception {
Integer retorno = 1;
Mockito.when(archivoDao.procesar()).thenReturn(resultado);
Mockito.when(resultado.getCodigo()).thenReturn(retorno);
instancia.ingresarCarga();
}
In this case the test fails and returns the following error:
java.lang.Exception: test timed out after 11000 milliseconds at java.lang.Thread.sleep (Native Method)
I also thought of a way to change the value of the return in the second iteration but so far I could not get it.
I'm working with java 7 and junit 4.11
Thank you very much for the help in advance: D.