@Test(expectedExceptions = BaseException.class) public void testCreateChargeServiceFailure() throws BaseException { Charge expectedCharge = new Charge.Builder() .amount(new BigDecimal(1234)) .currency("SomeCurrency") .card(new Card.Builder().name("SomeCardName").build()) .build(); final String serializedResponseString = JsonUtil.serialize(expectedCharge); final Response mockedResponse = new Response(200, serializedResponseString, "some_intuit_tid"); mockedResponse.setResponseObject(expectedCharge); new Expectations() {{ serviceBase.sendRequest((Request) any); result = new BaseException("Unexpected Error , service response object was null "); }}; RequestContext requestContext = new RequestContext(); requestContext.setBaseUrl("SomeBaseUrl"); ChargeService chargeService = new ChargeService(requestContext); Charge chargeRequest = new Charge(); Charge actualCharge = chargeService.create(chargeRequest); }
public Charge create(Charge charge) throws BaseException { logger.debug("Enter ChargeService::create"); String apiUrl = requestContext.getBaseUrl() + "charges".replaceAll("\\{format\\}", "json"); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(charge) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; }
ChargeService extends ServiceBase { public Charge create(Charge charge) throws BaseException { logger.debug("Enter ChargeService::create"); String apiUrl = requestContext.getBaseUrl() + "charges".replaceAll("\\{format\\}", "json"); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(charge) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } }
ChargeService extends ServiceBase { public Charge create(Charge charge) throws BaseException { logger.debug("Enter ChargeService::create"); String apiUrl = requestContext.getBaseUrl() + "charges".replaceAll("\\{format\\}", "json"); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(charge) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); }
ChargeService extends ServiceBase { public Charge create(Charge charge) throws BaseException { logger.debug("Enter ChargeService::create"); String apiUrl = requestContext.getBaseUrl() + "charges".replaceAll("\\{format\\}", "json"); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(charge) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Charge create(Charge charge); Charge retrieve(String chargeId); Charge capture(String chargeId, Capture capture); Refund refund(String chargeId, Refund refund); Refund getRefund(String chargeId, String refundId); Refund voidTransaction(String chargeRequestId); }
ChargeService extends ServiceBase { public Charge create(Charge charge) throws BaseException { logger.debug("Enter ChargeService::create"); String apiUrl = requestContext.getBaseUrl() + "charges".replaceAll("\\{format\\}", "json"); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).requestObject(charge) .typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Charge create(Charge charge); Charge retrieve(String chargeId); Charge capture(String chargeId, Capture capture); Refund refund(String chargeId, Refund refund); Refund getRefund(String chargeId, String refundId); Refund voidTransaction(String chargeRequestId);  }