title: Mockito Spring Data Web Support
body: <p>I am new to Mockito and have a bit of a problem concerning the Spring Data Web Support.</p>
  
  <p>I have the following function in my controller.</p>
  
  <pre><code>@DeleteMapping("/")
  public MyObject delete(@RequestParam("id")MyObject object){
  ...do something
  }
  </code></pre>
  
  <p>whats happening here (in real usecases) is decribed <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The problem is, when i use MockMvc and Mockito in my unitTests, there is no database and no persistence Repositories. How can i make Spring use a mockRepository to replace the id handed over in <code>/?id=1</code> by a MyObject-instance of my choice.</p>
  
  <p>This is what the Test looks like:</p>
  
  <pre><code>import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  
  import org.junit.Before;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.mockito.InjectMocks;
  import org.mockito.Mock;
  import org.mockito.MockitoAnnotations;
  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  import org.springframework.test.web.servlet.MockMvc;
  import org.springframework.test.web.servlet.setup.MockMvcBuilders;
  
  import com.mine.OrgUnitController;
  import com.mine.OrgUnitService;
  
  @RunWith(SpringJUnit4ClassRunner.class)
  public class OrgUnitControllerTest2 {
      private MockMvc mockMvc;
      @Mock
      SomeService someService;
      @InjectMocks
      MyController controller;
  
      @Before
      public void init() {
          MockitoAnnotations.initMocks(this);
          mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
      }
  
      @Test
      public void test_delete() throws Exception {
          mockMvc.perform(delete("/?id=1")).andExpect(status().isOk());
      }
  }
  </code></pre>
  
  <p>I really appreciate any help.</p>