'Test Method with HttpServletResponse argument

I have a method in my SpringBoot app, in GenerateZipServiceImpl class:

    @Override
    public void generateZipFile(final Parameters parameters, final HttpServletResponse response){
      ...
      ...
      ...
    }

In this method I get request body as an Parameters object called parameters and I generate zip with some files(using this parameters to generate files).

I want to write some unit tests for this method. But I couldn't understand how to use this HttpServletResponse here(. Maybe I have to use Mockito or I don't know.

Can someone give me any suggestions?

This is the endpoint where I execute this method in my controller:

@PostMapping("generate")
@ResponseStatus(HttpStatus.OK)
public void downloadZipFile(@RequestBody final Parameters parameter, final HttpServletResponse response) throws FileReadingException, IOException {
    response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
    response.setHeader(CONTENT_DISPOSITION, HEADER_VALUE_STR);
    response.setStatus(HttpServletResponse.SC_OK);
    this.generateZipServiceImpl.generateZipFile(parameter, response);
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source