I have a method like below for which I have to write the test case for FileNotFoundException

```
public ResponseEntity<ChefAgent> getClientDetails(String clientName) {

    LogImpl.setLogger(className,
            "Entered RESTAPI method to getClientDetails");
    ResponseEntity<ChefAgent> response = null;
    ResponseBean responseBean = null;
    ErrorBean errorBean = new ErrorBean();
    try {

        requestBean.setChefApi(ChefServiceProvider.getApi());
        requestBean.setService(NodeManagementConstants.CLIENT_DETAILS);
        requestBean.setClientName(clientName);
        responseBean = delegator.handleRequest(requestBean);

        if (null != responseBean.getChefAgent()) {
            response = new ResponseEntity<ChefAgent>(
                    responseBean.getChefAgent(), new HttpHeaders(),
                    HttpStatus.OK);
        } else {
            response = new ResponseEntity<ChefAgent>(
                    responseBean.getChefAgent(), new HttpHeaders(),
                    HttpStatus.BAD_REQUEST);
        }
        ChefServiceProvider.getClose();
    } catch (FileNotFoundException e) {
        LogImpl.setWarning(Segregator.class, e.getMessage());

        LogImpl.setWarning(className, "error occured");

        errorBean.setErrorCode(ErrorCode.FILE_NOT_FOUND_ERROR
                .getErrorCode());
        errorBean.setErrorMessage(ErrorCode.FILE_NOT_FOUND_ERROR
                .getMessage());
        ChefAgent agent = new ChefAgent();
        agent.setErrorBean(errorBean);
        response = new ResponseEntity<ChefAgent>(agent, new HttpHeaders(),
                HttpStatus.BAD_REQUEST);
        return response;
    }
    catch (CustomException e) {
        LogImpl.setWarning(Segregator.class, e.getMessage());
    }
    LogImpl.setLogger(Segregator.class,
            "Ended RESTAPI method to getClientDetails");

    return response;
}

```

Here the method ChefServiceProvider.getApi() have some FileInputStream operation and for which it throws FileNotFoundException. I'm not able to create a scenario in mockito where I can test the catch block in method getClientDetails(String clientName). Tried something like below

```
@Test()
public void testGetClientDetailsFileNotFoundException() throws Exception {

    String clientName = "client";
    ChefAgent chefAgent = new ChefAgent();
    List<ChefClientBean> chefClientBean = new ArrayList<ChefClientBean>();
    chefClientBean.add(new ChefClientBean());
    chefAgent.setChefClientList(chefClientBean);
    responseBean.setChefAgent(chefAgent);
    ResponseEntity<ChefAgent> response;

    try {
        Mockito.doThrow(new RuntimeException()).when(ChefServiceProvider.getApi());
        response = cloudManagementHelper.getClientDetails(clientName);
        Assert.assertEquals(response.getStatusCode(), HttpStatus.BAD_REQUEST);
    } catch (FileNotFoundException e) {
        System.out.println("exception");
    } 
}

```

But it gives error like 

> 
> org.mockito.exceptions.misusing.NotAMockException: Argument passed to
>  when() is not a mock!
> 
> 
> 

Please let me know what is the correct way to do this.
------------------------------------------------------

I'm using below code to mock the method

```
PowerMockito.mockStatic(ChefServiceProvider.class);
PowerMockito.when(ChefServiceProvider.getApi()).thenReturn(chefApi);

Mockito.when(ChefServiceProvider.getApi()).thenThrow(
        new FileNotFoundException());

```

But then I'm getting error like

> 
> org.mockito.exceptions.misusing.MissingMethodInvocationException: 
>  when() requires an argument which has to be 'a method call on a mock'.
> 
> 
>