@Test
  public void testDeleteCouponServletWithEmptyCoupon() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn("");
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.DELETE_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(stringWriter.toString().contains("Coupon code is empty or not valid"));
  }
  @Test
  public void testDeleteCouponServletWithNullCoupon() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn(Constants.COUPON_TEST_CODE);
    when(couponPluginApi.getCouponByCode(anyString())).thenReturn(null);
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.DELETE_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(stringWriter.toString().contains("Coupon not found in the DB"));
  }
  @Test
  public void testGetCouponServletWithSQLException()
      throws IOException, SQLException, ServletException {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);

    when(response.getWriter()).thenReturn(writer);
    when(request.getParameter(Constants.COUPON_CODE)).thenReturn(Constants.COUPON_TEST_CODE);
    when(couponPluginApi.getCouponByCode(anyString())).thenThrow(SQLException.class);
    when(request.getPathInfo()).thenReturn(Constants.GET_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(stringWriter.toString().contains("SQL Exception"));
  }
  @Test
  public void testGetCouponServletOK() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    CouponsRecord couponRecord = buildSuccessfulCouponRecord();

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn(Constants.COUPON_TEST_CODE);
    when(couponPluginApi.getCouponByCode(anyString())).thenReturn(couponRecord);
    when(couponPluginApi.getProductsOfCoupon(anyString())).thenReturn(new ArrayList());
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.GET_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(stringWriter.toString().contains(Constants.COUPON_TEST_CODE));
  }
  @Test
  public void testDeleteCouponServletWithCouponApplicationActive() throws Exception {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    List<CouponsAppliedRecord> mockListOfActiveCouponsApplied = buildListOfActiveCouponsApplied();
    CouponsRecord couponRecord = buildSuccessfulCouponRecord();

    when(request.getParameter(Constants.COUPON_CODE)).thenReturn(Constants.COUPON_TEST_CODE);
    when(couponPluginApi.getCouponByCode(anyString())).thenReturn(couponRecord);
    when(couponPluginApi.getActiveCouponsAppliedByCouponCode(anyString()))
        .thenReturn(mockListOfActiveCouponsApplied);
    when(response.getWriter()).thenReturn(writer);
    when(request.getPathInfo()).thenReturn(Constants.DELETE_COUPON_PATH.toString());
    when(request.getMethod()).thenReturn("GET");

    servletRouter.doGet(request, response);

    assertTrue(
        stringWriter
            .toString()
            .contains("has currently active applications and cannot be deleted"));
  }