package org.xmx0632.deliciousfruit.service; import java.math.BigDecimal; import java.util.Arrays; import java.util.List; import org.junit.After; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.OrderItem; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.OrderRequestReceiver; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.CashCouponPay; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.DeliveryPeriod; import org.xmx0632.deliciousfruit.api.v1.bo.OrderRequest.Payment.GiftCardPay; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.DeductionPay; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.PayByCashCoupon; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.PayByEcoupon; import org.xmx0632.deliciousfruit.api.v1.bo.OrderResponse.PayByGiftCard; import org.xmx0632.deliciousfruit.api.v1.bo.SettlementRequest; import org.xmx0632.deliciousfruit.api.v1.bo.SettlementResponse; import org.xmx0632.deliciousfruit.api.v1.bo.SettlementResponse.ProductFreeInfo; import org.xmx0632.deliciousfruit.entity.ReceiverInfo; public class BaseIosPayoffServiceTestCase { protected static final String TRANSACTION_ID = IosPayoffServiceTestHelper.TRANSACTION_ID; @InjectMocks protected IosPayoffService iosPayoffService; @Mock protected IosOrderService iosOrderService; @Mock protected DeductionPayService deductionPayService; @Mock protected ReceiverInfoService receiverInfoService; @Mock protected OrderService orderService; protected List<CashCouponPay> cashCoupons; protected List<GiftCardPay> giftCards; protected BigDecimal payAmountFromAccount; protected BigDecimal payAmountFromPonit; protected int payPonit; protected List<OrderItem> orderList = Arrays.asList(new OrderItem()); protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); } protected void mockSettlementResponse(BigDecimal actualAmount, BigDecimal productPriceOff, List<ProductFreeInfo> productProductsFree, BigDecimal totalPriceOff, List<ProductFreeInfo> totalProductsFree, BigDecimal totalPrice, BigDecimal freightPay) { SettlementResponse settlementResponse = IosPayoffServiceTestHelper .setupSettlementResponse(actualAmount, productPriceOff, productProductsFree, totalPriceOff, totalProductsFree, totalPrice, freightPay); Mockito.when( iosOrderService.caculatePromotionInfo(Mockito .any(SettlementRequest.class))).thenReturn( settlementResponse); } protected void mockDeductionPayService( List<PayByCashCoupon> payByCashCouponInfo, List<PayByEcoupon> payByEcouponInfo, List<PayByGiftCard> payByGiftCardInfo, BigDecimal deductionPointAmount, BigDecimal deductionAccountAmount) { DeductionPay deductionPay = new DeductionPay(); deductionPay.setPayByCashCouponInfo(payByCashCouponInfo); deductionPay.setPayByEcouponInfo(payByEcouponInfo); deductionPay.setPayByGiftCardInfo(payByGiftCardInfo); deductionPay.setPayByPoint(deductionPointAmount); deductionPay.setPayFromAccount(deductionAccountAmount); Mockito.when( deductionPayService.getDeductionPay( Mockito.any(OrderRequest.class), Mockito.any(String.class))).thenReturn(deductionPay); } protected void mockReceiverInfoService( List<PayByCashCoupon> payByCashCouponInfo, List<PayByEcoupon> payByEcouponInfo, List<PayByGiftCard> payByGiftCardInfo, BigDecimal deductionPointAmount, BigDecimal deductionAccountAmount) { DeductionPay deductionPay = new DeductionPay(); deductionPay.setPayByCashCouponInfo(payByCashCouponInfo); deductionPay.setPayByEcouponInfo(payByEcouponInfo); deductionPay.setPayByGiftCardInfo(payByGiftCardInfo); deductionPay.setPayByPoint(deductionPointAmount); deductionPay.setPayFromAccount(deductionAccountAmount); ReceiverInfo mockWorld = Mockito.mock(ReceiverInfo.class); Mockito.doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); return "called with arguments: " + args; } }).when(mockWorld); } @After public void tearDown() throws Exception { } protected OrderRequest createRequest(List<CashCouponPay> cashCoupons, List<GiftCardPay> giftCards, BigDecimal payAmountFromAccount, BigDecimal payAmountFromPonit, int payPonit, List<OrderItem> orderList, String paymentMethod) { // 送货时间为空,不填,周一至周五上/下午,周末上/下午,周一至周日上/下午这6种供用户选 DeliveryPeriod deliveryPeriod = new DeliveryPeriod("周一至周五上午", ""); // 支付方式 Payment payment = IosPayoffServiceTestHelper.setupPayment(cashCoupons, giftCards, payAmountFromAccount, payAmountFromPonit, payPonit, paymentMethod); // 收货地址 OrderRequestReceiver receiverInfo = IosPayoffServiceTestHelper .setupReceiverInfo(); // 订单请求 OrderRequest request = IosPayoffServiceTestHelper.setupOrderRequest( orderList, deliveryPeriod, payment, receiverInfo); return request; } }