title: java.lang.AssertionError: Status expected:<200> but was:<404> in Junit test
body: <p>I want to create JUnit test for Rest api and generate api doc. I want to test this code:</p>
  
  <p>Rest controller</p>
  
  <pre><code>@RestController
  @RequestMapping("/transactions")
  public class PaymentTransactionsController {
  
  @Autowired
  private PaymentTransactionRepository transactionRepository;
  
  @GetMapping("{id}")
      public ResponseEntity&lt;?&gt; get(@PathVariable String id) {
          return transactionRepository
                  .findById(Integer.parseInt(id))
                  .map(mapper::toDTO)
                  .map(ResponseEntity::ok)
                  .orElseGet(() -&gt; notFound().build());
      }
  }
  </code></pre>
  
  <p>Repository interface</p>
  
  <pre><code>public interface PaymentTransactionRepository extends CrudRepository&lt;PaymentTransactions, Integer&gt;, JpaSpecificationExecutor&lt;PaymentTransactions&gt; {
  
      Optional&lt;PaymentTransactions&gt; findById(Integer id);
  }
  </code></pre>
  
  <p>I tried to implement this JUnit5 test with mockito:</p>
  
  <pre><code>@ExtendWith({ RestDocumentationExtension.class, SpringExtension.class })
  @SpringBootTest(classes = PaymentTransactionsController.class)
  @WebAppConfiguration
  public class PaymentTransactionRepositoryIntegrationTest {
      .....
      private MockMvc mockMvc;
  
      @MockBean
      private PaymentTransactionRepository transactionRepository;
  
      @BeforeEach
      void setUp(WebApplicationContext webApplicationContext,
                RestDocumentationContextProvider restDocumentation) {
  
          PaymentTransactions obj = new PaymentTransactions(1);
  
          Optional&lt;PaymentTransactions&gt; optional = Optional.of(obj);      
  
          PaymentTransactionRepository processor = Mockito.mock(PaymentTransactionRepository.class);
          Mockito.when(processor.findById(Integer.parseInt("1"))).thenReturn(optional);       
  
          this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
                .apply(documentationConfiguration(restDocumentation))
                .alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
                .build();
      }
  
      @Test
      public void testNotNull() {
          assertNotNull(target);
      }
  
      @Test
      public void testFindByIdFound() {
          Optional&lt;PaymentTransactions&gt; res = target.findById(Integer.parseInt("1"));
  //        assertTrue(res.isPresent());
      }
  
      @Test
      public void indexExample() throws Exception {
              this.mockMvc.perform(get("/transactions").param("id", "1"))
                  .andExpect(status().isOk())
                  .andExpect(content().contentType("application/xml;charset=UTF-8"))
                  .andDo(document("index-example", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), links(linkWithRel("crud").description("The CRUD resource")), responseFields(subsectionWithPath("_links").description("Links to other resources")),
                      responseHeaders(headerWithName("Content-Type").description("The Content-Type of the payload, e.g. `application/hal+json`"))));
      }
  }
  </code></pre>
  
  <p>I get error:</p>
  
  <pre><code>java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;404&gt;
  </code></pre>
  
  <p>What his the proper way to to make GET request to the above code?
  Probably I need to add response OK when message is send back?</p>