I am trying to write a unit test for a controller that does different things depending on the device type. 

The first controller method and its test works fine, the method paramater *model* has a value and I can validate the value in the test.

The second controller method which expects a device works when called from a brwoser, but **not** in a unit test. When the test method `doSomething2Test()` is called I get a 

```
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.mobile.device.Device]: Specified class is an interface

```

My question: Why is the parameter *model* instantiated correctly but *device* is not? Is there a way to set the device in the MockMvc request or can I mock the device somehow?

Controller:

```
@Controller
@RequestMapping("home")
public class MyController {

    @RequestMapping("/test1")
    public String doSomething1(Model model) {
        String value = "foo";
        model.addAttribute("attribute1", value);        
        return "newUrl";
    }

    @RequestMapping("/test2")
    public String doSomething2(Model model, Device device) {
        if (device.isNormal()) {
          // do stuff
        }
        return "newUrl";
    }
}

```

Test: 

```
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
@WithMockUser(username="admin", authorities = {"ALL"})
public class MyControllerTest {

    private MockMvc mockMvc;

    @InjectMocks
    private MyController controllerUnderTest;   

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/classes/templates");
        viewResolver.setSuffix(".html");
        this.mockMvc =
                MockMvcBuilders.standaloneSetup(this.controllerUnderTest)
                        .setViewResolvers(viewResolver)
                        .build();
    }

    @Test
    public void doSomething1Test() throws Exception {
        this.mockMvc.perform(get("/home/test1"))
        .andExpect(status().isOk())
        .andExpect(model().attribute("attribute1", contains("foo")));   
    }

    @Test
    public void doSomething2Test() throws Exception {
        this.mockMvc.perform(get("/home/test2"))
        .andExpect(status().isOk()));   
    }
}

```