source: class StockAPI {
  
      @GetMapping
      public ResponseEntity<List<Stock>> findAll() {
          return ResponseEntity.ok(stockService.findAll());
      }
  
      @GetMapping("/{stockId}") public ResponseEntity<Stock> findById(@PathVariable Long stockId);
      @PostMapping public ResponseEntity create(@RequestBody Stock stock);
      @PatchMapping("/{stockId}") public ResponseEntity<Stock> update(@PathVariable Long stockId, @RequestBody Stock updatingStock);
      @DeleteMapping("/{id}") public ResponseEntity delete(@PathVariable Long id);
  
      @Autowired
      private MockMvc mockMvc;
      @MockBean
      private StockService stockService;
  
  }
  
  class StockAPITest {
  
      @Autowired
      private MockMvc mockMvc;
      @MockBean
      private StockService stockService;
  
      @Test
      public void findAll() throws Exception {
  
target:         // given
          Stock stock = new Stock();
          stock.setId(1L);
          stock.setName("Stock 1");
          stock.setPrice(new BigDecimal(1));
  
          List<Stock> stocks = Arrays.asList(stock);
          given(stockService.findAll()).willReturn(stocks);
  
          // when + then
          this.mockMvc.perform(get("/api/v1/stocks"))
                  .andExpect(status().isOk())
                  .andExpect(content().json("[{'id': 1,'name': 'Stock 1';'price': 1}]"));
      }
  
  }