content: package dev.abarmin.spring;
  
  import com.fasterxml.jackson.databind.ObjectMapper;
  import dev.abarmin.balance.client.BalanceClient;
  import org.junit.jupiter.api.Test;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.boot.test.context.TestConfiguration;
  import org.springframework.boot.test.mock.mockito.MockBean;
  import org.springframework.http.HttpHeaders;
  import org.springframework.http.MediaType;
  import org.springframework.test.web.servlet.MockMvc;
  
  import static dev.abarmin.spring.ApplicationTestHelper.createRequest;
  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  
  @SpringBootTest
  @AutoConfigureMockMvc
  class ApplicationMockEnvironmentTest {
      @Autowired
      MockMvc mockMvc;
  
      @Autowired
      ObjectMapper objectMapper;
  
      @TestConfiguration
      static class MyConfig {
          @MockBean
          BalanceClient balanceClient;
      }
  
      @Test
      void createAndRetrieve() throws Exception {
          String bodyJson = objectMapper.writeValueAsString(createRequest());
  
          mockMvc.perform(post("/transactions")
                          .content(bodyJson)
                          .contentType(MediaType.APPLICATION_JSON_VALUE))
                  .andExpect(status().isCreated())
                  .andExpect(header().exists(HttpHeaders.LOCATION));
  
          mockMvc.perform(get("/transactions"))
                  .andExpect(status().isOk())
                  .andExpect(jsonPath("$.transactions").isArray())
                  .andExpect(jsonPath("$.transactions[0].id").isNumber());
      }
  }
  