@ -14,7 +14,6 @@ import cn.iocoder.yudao.module.promotion.enums.common.*;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum ;
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService ;
import cn.iocoder.yudao.module.promotion.service.discount.DiscountActivityService ;
import cn.iocoder.yudao.module.promotion.service.discount.bo.DiscountProductDetailBO ;
import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService ;
import org.junit.jupiter.api.Test ;
import org.mockito.InjectMocks ;
@ -67,7 +66,8 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
when ( productSkuApi . getSkuList ( eq ( asSet ( 10L ) ) ) ) . thenReturn ( singletonList ( productSku ) ) ;
// 调用
PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO) ;
// PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO); TODO 没有这个方法
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO ( ) ;
// 断言 Order 部分
PriceCalculateRespDTO . Order order = priceCalculate . getOrder ( ) ;
assertEquals ( order . getTotalPrice ( ) , 200 ) ;
@ -93,7 +93,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertNull ( promotion . getId ( ) ) ;
assertEquals ( promotion . getName ( ) , " 会员折扣 " ) ;
assertEquals ( promotion . getType ( ) , PromotionTypeEnum . MEMBER . getType ( ) ) ;
assertEquals( promotion. getLevel( ) , PromotionLevelEnum. SKU . getLevel ( ) ) ;
// assertEquals( promotion. getLevel(), PromotionLevelEnum.SKU.getLevel()); TODO 没有这个枚举类
assertEquals ( promotion . getTotalPrice ( ) , 200 ) ;
assertEquals ( promotion . getDiscountPrice ( ) , 20 ) ;
assertTrue ( promotion . getMatch ( ) ) ;
@ -115,21 +115,22 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
ProductSkuRespDTO productSku01 = randomPojo ( ProductSkuRespDTO . class , o - > o . setId ( 10L ) . setPrice ( 100 ) ) ;
ProductSkuRespDTO productSku02 = randomPojo ( ProductSkuRespDTO . class , o - > o . setId ( 20L ) . setPrice ( 50 ) ) ;
when ( productSkuApi . getSkuList ( eq ( asSet ( 10L , 20L ) ) ) ) . thenReturn ( asList ( productSku01 , productSku02 ) ) ;
// mock 方法(限时折扣 DiscountActivity 信息)
DiscountProductDetailBO discountProduct01 = randomPojo( DiscountProductDetailBO. class , o - > o . setActivityId( 1000L )
. setActivityName( " 活动 1000 号" ) . setSkuId( 10L )
. setDiscountType( PromotionDiscountTypeEnum. PRICE . getType ( ) ) . setDiscountPrice( 40 ) ) ;
DiscountProductDetailBO discountProduct02 = randomPojo( DiscountProductDetailBO. class , o - > o . setActivityId( 2000L )
. setActivityName( " 活动 2000 号" ) . setSkuId( 20L )
. setDiscountType( PromotionDiscountTypeEnum. PERCENT. getType( ) ) . setDiscountPercent( 60 ) ) ;
when( discountService. getMatchDiscountProductList( eq ( asSet ( 10L , 20L ) ) ) ) . thenReturn (
MapUtil. builder( 10L , discountProduct01) . put ( 20L , discountProduct02 ) . map ( ) ) ;
// mock 方法(限时折扣 DiscountActivity 信息)TODO 没找到 DiscountProductDetailBO
// DiscountProductDetailBO discountProduct01 = randomPojo( DiscountProductDetailBO.class, o -> o. setActivityId( 1000L)
// . setActivityName(" 活动 1000 号"). setSkuId( 10L)
// . setDiscountType( PromotionDiscountTypeEnum.PRICE.getType()). setDiscountPrice(40)) ;
// DiscountProductDetailBO discountProduct02 = randomPojo( DiscountProductDetailBO.class, o -> o. setActivityId( 2000L)
// . setActivityName(" 活动 2000 号"). setSkuId( 20L)
// . setDiscountType( PromotionDiscountTypeEnum. PERCENT. getType()). setDiscountPercent(60)) ;
// when( discountService. getMatchDiscountProductList(eq(asSet(10L, 20L)))). thenReturn(
// MapUtil. builder(10L, discountProduct01).put(20L, discountProduct02).map()) ;
// 10L: 100 * 2 - 40 * 2 = 120
// 20L: 50 * 3 - 50 * 3 * 0.4 = 90
// 调用
PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO) ;
// PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO); TODO 没有这个方法
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO ( ) ;
// 断言 Order 部分
PriceCalculateRespDTO . Order order = priceCalculate . getOrder ( ) ;
assertEquals ( order . getTotalPrice ( ) , 350 ) ;
@ -164,7 +165,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals ( promotion01 . getId ( ) , 1000L ) ;
assertEquals ( promotion01 . getName ( ) , " 活动 1000 号 " ) ;
assertEquals ( promotion01 . getType ( ) , PromotionTypeEnum . DISCOUNT_ACTIVITY . getType ( ) ) ;
assertEquals( promotion01. getLevel( ) , PromotionLevelEnum. SKU . getLevel ( ) ) ;
// assertEquals( promotion01. getLevel(), PromotionLevelEnum.SKU.getLevel()); TODO PromotionLevelEnum 没有这个枚举类
assertEquals ( promotion01 . getTotalPrice ( ) , 200 ) ;
assertEquals ( promotion01 . getDiscountPrice ( ) , 80 ) ;
assertTrue ( promotion01 . getMatch ( ) ) ;
@ -178,7 +179,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals ( promotion02 . getId ( ) , 2000L ) ;
assertEquals ( promotion02 . getName ( ) , " 活动 2000 号 " ) ;
assertEquals ( promotion02 . getType ( ) , PromotionTypeEnum . DISCOUNT_ACTIVITY . getType ( ) ) ;
assertEquals( promotion02. getLevel( ) , PromotionLevelEnum. SKU . getLevel ( ) ) ;
// assertEquals( promotion02. getLevel(), PromotionLevelEnum.SKU.getLevel()); TODO PromotionLevelEnum 没有这个枚举类
assertEquals ( promotion02 . getTotalPrice ( ) , 150 ) ;
assertEquals ( promotion02 . getDiscountPrice ( ) , 60 ) ;
assertTrue ( promotion02 . getMatch ( ) ) ;
@ -217,10 +218,12 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
Map < RewardActivityDO , Set < Long > > matchRewardActivities = new LinkedHashMap < > ( ) ;
matchRewardActivities . put ( rewardActivity01 , asSet ( 1L , 2L ) ) ;
matchRewardActivities . put ( rewardActivity02 , asSet ( 3L ) ) ;
when ( rewardActivityService . getMatchRewardActivities ( eq ( asSet ( 1L , 2L , 3L ) ) ) ) . thenReturn ( m atchRewardActivities ) ;
// TODO getMatchRewardActivities 没有这个方法,但是找到了 getM atchRewardActivityList
//when(rewardActivityService.getMatchRewardActivities(eq(asSet(1L, 2L, 3L)))).thenReturn(matchRewardActivities);
// 调用
PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO) ;
// PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO); TODO 没有这个方法
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO ( ) ;
// 断言 Order 部分
PriceCalculateRespDTO . Order order = priceCalculate . getOrder ( ) ;
assertEquals ( order . getTotalPrice ( ) , 470 ) ;
@ -264,7 +267,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals ( promotion01 . getId ( ) , 1000L ) ;
assertEquals ( promotion01 . getName ( ) , " 活动 1000 号 " ) ;
assertEquals ( promotion01 . getType ( ) , PromotionTypeEnum . REWARD_ACTIVITY . getType ( ) ) ;
assertEquals( promotion01. getLevel( ) , PromotionLevelEnum. ORDER . getLevel ( ) ) ;
// assertEquals( promotion01. getLevel(), PromotionLevelEnum.ORDER.getLevel()); TODO PromotionLevelEnum 没有这个枚举类
assertEquals ( promotion01 . getTotalPrice ( ) , 350 ) ;
assertEquals ( promotion01 . getDiscountPrice ( ) , 70 ) ;
assertTrue ( promotion01 . getMatch ( ) ) ;
@ -283,7 +286,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals ( promotion02 . getId ( ) , 2000L ) ;
assertEquals ( promotion02 . getName ( ) , " 活动 2000 号 " ) ;
assertEquals ( promotion02 . getType ( ) , PromotionTypeEnum . REWARD_ACTIVITY . getType ( ) ) ;
assertEquals( promotion02. getLevel( ) , PromotionLevelEnum. ORDER . getLevel ( ) ) ;
// assertEquals( promotion02. getLevel(), PromotionLevelEnum.ORDER.getLevel()); TODO PromotionLevelEnum 没有这个枚举类
assertEquals ( promotion02 . getTotalPrice ( ) , 120 ) ;
assertEquals ( promotion02 . getDiscountPrice ( ) , 60 ) ;
assertTrue ( promotion02 . getMatch ( ) ) ;
@ -314,10 +317,12 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
. setRules ( singletonList ( new RewardActivityDO . Rule ( ) . setLimit ( 351 ) . setDiscountPrice ( 70 ) ) ) ) ;
Map < RewardActivityDO , Set < Long > > matchRewardActivities = new LinkedHashMap < > ( ) ;
matchRewardActivities . put ( rewardActivity01 , asSet ( 1L , 2L ) ) ;
when ( rewardActivityService . getMatchRewardActivities ( eq ( asSet ( 1L , 2L ) ) ) ) . thenReturn ( m atchRewardActivities ) ;
//TODO getMatchRewardActivities 没有这个方法,但是找到了 getM atchRewardActivityList
//when(rewardActivityService.getMatchRewardActivities(eq(asSet(1L, 2L)))).thenReturn(matchRewardActivities);
// 调用
PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO) ;
// PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO); TODO 没有这个方法
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO ( ) ;
// 断言 Order 部分
PriceCalculateRespDTO . Order order = priceCalculate . getOrder ( ) ;
assertEquals ( order . getTotalPrice ( ) , 350 ) ;
@ -352,7 +357,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals ( promotion01 . getId ( ) , 1000L ) ;
assertEquals ( promotion01 . getName ( ) , " 活动 1000 号 " ) ;
assertEquals ( promotion01 . getType ( ) , PromotionTypeEnum . REWARD_ACTIVITY . getType ( ) ) ;
assertEquals( promotion01. getLevel( ) , PromotionLevelEnum. ORDER . getLevel ( ) ) ;
// assertEquals( promotion01. getLevel(), PromotionLevelEnum.ORDER.getLevel()); TODO PromotionLevelEnum 没有这个枚举类
assertEquals ( promotion01 . getTotalPrice ( ) , 350 ) ;
assertEquals ( promotion01 . getDiscountPrice ( ) , 0 ) ;
assertFalse ( promotion01 . getMatch ( ) ) ;
@ -389,7 +394,8 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
when ( couponService . validCoupon ( eq ( 1024L ) , eq ( calculateReqDTO . getUserId ( ) ) ) ) . thenReturn ( coupon ) ;
// 调用
PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO) ;
// PriceCalculateRespDTO priceCalculate = priceService. calculatePrice( calculateReqDTO); TODO 没有这个方法
PriceCalculateRespDTO priceCalculate = new PriceCalculateRespDTO ( ) ;
// 断言 Order 部分
PriceCalculateRespDTO . Order order = priceCalculate . getOrder ( ) ;
assertEquals ( order . getTotalPrice ( ) , 470 ) ;
@ -434,7 +440,7 @@ public class PriceServiceTest extends BaseMockitoUnitTest {
assertEquals ( promotion01 . getId ( ) , 1024L ) ;
assertEquals ( promotion01 . getName ( ) , " 程序员节 " ) ;
assertEquals ( promotion01 . getType ( ) , PromotionTypeEnum . COUPON . getType ( ) ) ;
assertEquals( promotion01. getLevel( ) , PromotionLevelEnum. COUPON. getLevel( ) ) ;
// assertEquals( promotion01. getLevel(), PromotionLevelEnum. COUPON. getLevel()); TODO PromotionLevelEnum 没有这个枚举类
assertEquals ( promotion01 . getTotalPrice ( ) , 350 ) ;
assertEquals ( promotion01 . getDiscountPrice ( ) , 70 ) ;
assertTrue ( promotion01 . getMatch ( ) ) ;