title: Mock Principal for Spring Rest controller
body: <p>I have the following REST controller: </p>
  
  <pre><code>@RequestMapping(path = "", method = RequestMethod.GET)
  public ExtendedGetUserDto getCurrentUser(Principal principal) {
      CustomUserDetails userDetails = userDetailsService.loadByUsername(principal.getName())
      // .....
  }
  </code></pre>
  
  <p><code>CustomUserDetails</code> has a number of fields, including <code>username</code> and <code>password</code></p>
  
  <p>I want to mock principal in the controller method (or pass from test to the controller method). How should I do that ? I read many posts, but none of them actually answered this question.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <pre><code>@Test
  public void testGetCurrentUser() throws Exception {
  
      RequestBuilder requestBuilder = MockMvcRequestBuilders.get(
              USER_ENDPOINT_URL).accept(MediaType.APPLICATION_JSON);
  
      MvcResult result = mockMvc.perform(requestBuilder).andReturn();
  
      MockHttpServletResponse response = result.getResponse();
      int status = response.getStatus();
      Assert.assertEquals("response status is wrong", 200, status);
  }
  </code></pre>