jeudi 3 septembre 2015

Mocking for arbitrary input parameters Spring MVC Unit Tests

I have a method in a class (we'll call it mock) accessed by a controller

getBlah( Map<String, String> params )
{
    // DO STUFF
}

It is called by the controller to access a repository and filter on some parameters passed in via the URL.

In my test I would like to mock this to just throw an exception to test how the controller will handle this.

I use mockito and generally am able to just throw an exception but I must specify inputs.

doThrow( new Exception() )
    .when(mock).getBlah( /*NOT SURE WHAT TO PUT HERE */ );

mvc.perform(MockMvcRequestBuilders.get(BASE_URL+filterArgs)
    .andExpect(Status.isNotFound() );

I would like this to just throw for ALL inputs to getBlah. However I do not know how I would specify this in the argument.

Any insight out there?

Aucun commentaire:

Enregistrer un commentaire