title: How to write JUnit test cases for GET API?
body: <p>I have a GET API which accepts different parameters in controller class. According to the boolean parameter, the API should return a different result. How can I write JUnit test cases for the same? </p>
  
  <pre><code>@CrossOrigin
  
  @RequestMapping(value = "/api/brand/multi-get", method = RequestMethod.GET, consumes =
          MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces =
          MediaType.APPLICATION_JSON_VALUE)
  
  public ResponseDTO listBrands(@RequestParam(required = false) Integer start,
                                @RequestParam(required = false) Integer limit,
                                @RequestParam(required = false) Boolean show_rejected) {
  
      ResponseDTO responseDTO = new ResponseDTO();
      System.out.println("------------------");
      try {
          if (start == null) {
              start = 0;
          }
          if (limit == null) {
              limit = 50;
          } else if (1 &lt;= limit &amp;&amp; limit &lt;= 250) {
              if (show_rejected) {
                  List&lt;Brand&gt; brands = brandService.findAllBrands(start, limit);
                  if (brands != null &amp;&amp; !brands.isEmpty()) {
                      responseDTO.setData(brands);
                      responseDTO.setCode(ErrorCode.error_0);
                      responseDTO.setMessage("Brand list");
                      return responseDTO;
                  } else {
                      responseDTO.setData(new ArrayList&lt;&gt;());
                      responseDTO.setCode(ErrorCode.error_0);
                      responseDTO.setMessage("Brand list");
                      return responseDTO;
                  }
              } else {
                  Page&lt;Brand&gt; brands = brandService.findAllActiveBrands(start, limit);
  
                  if (brands != null &amp;&amp; !brands.isEmpty()) {
                      responseDTO.setData(brands);
                      responseDTO.setCode(ErrorCode.error_0);
                      responseDTO.setMessage("Brand list");
                      return responseDTO;
                  } else {
                      responseDTO.setData(new ArrayList&lt;&gt;());
                      responseDTO.setCode(ErrorCode.error_0);
                      responseDTO.setMessage("Brand list");
                      return responseDTO;
                  }
              }
          } else {
              responseDTO.setCode(ErrorCode.error_1104);
              responseDTO.setMessage(ErrorCode.error_msg1104);
              return responseDTO;
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      return responseDTO;
  }
  </code></pre>