Spring Boot Testing: exception in REST controller
<p>I have a Spring Boot application and want to cover my REST controllers by integration test.
Here is my controller:</p>

<pre><code>@RestController
@RequestMapping("/tools/port-scan")
public class PortScanController {
    private final PortScanService service;

    public PortScanController(final PortScanService portScanService) {
        service = portScanService;
    }

    @GetMapping("")
    public final PortScanInfo getInfo(
            @RequestParam("address") final String address,
            @RequestParam(name = "port") final int port)
            throws InetAddressException, IOException {
        return service.scanPort(address, port);
    }
}
</code></pre>

<p>In one of test cases I want to test that endpoint throws an exception in some circumstances. Here is my test class:</p>

<pre><code>@RunWith(SpringRunner.class)
@WebMvcTest(PortScanController.class)
public class PortScanControllerIT {
    @Autowired
    private MockMvc mvc;

    private static final String PORT_SCAN_URL = "/tools/port-scan";

    @Test
    public void testLocalAddress() throws Exception {
        mvc.perform(get(PORT_SCAN_URL).param("address", "192.168.1.100").param("port", "53")).andExpect(status().isInternalServerError());
    }
}
</code></pre>

<p>What is the best way to do that? Current implementation doesn't handle InetAddressException which is thrown from PortScanController.getInfo() and when I start test, I receive and error: </p>

<pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.handytools.webapi.exceptions.InetAddressException: Site local IP is not supported
</code></pre>

<p>It is not possible to specify expected exception in @Test annotation since original InetAddressException is wrapped with NestedServletException.</p>