I have the following method in my controller that sends a call to a prop class to manage the file download ArchivoUtils.generaArchivo(response, factList);
@RequestMapping(value="view/obtieneArchivo")
public void obtieneArchivo(HttpServletRequest request, HttpServletResponse response) throws ControlException{
Object attribute = (Object) request.getSession.getAttribute(factuList);
List<Factura> factuList =(List(Factura)) attribute;
try{
if(factuList !=null && !factuList.isEmpty){
ArchivoUtils.generaArchivo(response, factList);
}else{
log.info("Esta vacio");
}
}catch(ControlException e){
throw new ControlException("Error", e);
}
}
This is the method that manages the download
public static void main generaArchivo(ServletResponse response, List<Factura> factuList ){
PrintWriter out = response.getWriter();
out.write("ID,CODIGO PROD,FEC INICIO, FEC FIN, NUM REGISTROS, NUUM REGISTROS NUEVOS, FEC CARGA, NUM INVEN, NUM PROD, NUM PRODUCT OLD, RFC, NUM VENTA, NUM VENTA OLD");
out.write("\n");
for(Factura factu: factuList){
out.write(factu.toCSV());
out.write("\n");
}
out.flush();
out.close();
}else{
log.info("Esta vacio");
}
}catch(ControlException e){
throw new ControlException("Error", e);
}
}
Now what I want to do is the unit test of this method, and I have the following but it does not cover the whole scenario of the method, as I can improve it or make the whole method pass, it is with a tool that indicates that the test it does not cover the whole method.
@InjectMocks
DescargaArchivoUtil descargaArchivoUtil;
@Test
public void pruebaArchivo(){
try{
HttpServletResponse response = null;
List<Factura> factuList =null;
descargaArchivoUtil.generaArchivo(response,factuList);
fail(“Error”);
}catch(Exception e){
Assert.assertNotNull(e);
}
}