title: Spring Boot RestController testing returns 404
body: <p>I'm trying to test my code (Spring-Boot project) of a RestController, but I always get 404. 
  Here is what I have so far:</p>
  
  <pre><code>@RestController("/service")
  public class ServiceInteractionController {
  
  @Autowired
  private PairingService pairingService;
  
  @GetMapping("/registered/{sensorId}")
  public ResponseEntity isSensorRegistered(@PathVariable String sensorId) {
      return ResponseEntity.ok(pairingService.isSensorRegistered(sensorId));
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(ServiceInteractionController.class)
  public class ServiceInteractionControllerTest {
  
  @Autowired
  private MockMvc mockMvc;
  
  @MockBean
  private PairingService pairingService;
  
  @Before
  public void setUp() {
      Mockito.when(pairingService.isSensorRegistered(TestConstants.TEST_SENSOR_ID))
              .thenReturn(true);
  }
  
  @Test
  public void testIsSensorRegistered() throws Exception {
      mockMvc.perform(MockMvcRequestBuilders.get("service/registered/{sensorId}", TestConstants.TEST_SENSOR_ID))
              .andExpect(MockMvcResultMatchers.status().isOk());
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The result always looks like this:</p>
  
  <pre><code>MockHttpServletRequest:
        HTTP Method = GET
        Request URI = service/registered/test123Id
         Parameters = {}
            Headers = []
               Body = &lt;no character encoding set&gt;
      Session Attrs = {}
  
  Handler:
               Type = null
  
  Async:
      Async started = false
       Async result = null
  
  Resolved Exception:
               Type = null
  
  ModelAndView:
          View name = null
               View = null
              Model = null
  
  FlashMap:
         Attributes = null
  
  MockHttpServletResponse:
             Status = 404
      Error message = null
            Headers = []
       Content type = null
               Body = 
      Forwarded URL = null
     Redirected URL = null
            Cookies = []
  
  java.lang.AssertionError: Status 
  Expected :200
  Actual   :404
  </code></pre>
  
  <p>What am I doing wrong? I already tried to initialize mockmvc directly in setUp method with standaloneSetup() and I have also used @SpringBootTest combined with @AutoConfigureMockMvc.</p>
  
  <p>Does anyone have some useful hints? I use spring boot 2.1.4.</p>
  
  <p>Thanks!</p>