单元测试
没有入口文件的单元测试
@RunWith(SpringRunner.class)
@SpringBootTest(
classes = {SmsAutoConfigure.class, RedisAutoConfig.class, ComRedisAutoConfig.class},
webEnvironment = SpringBootTest.WebEnvironment.MOCK,
properties = {"spring.cloud.config.enabled=false"}
)
class WeiGeChannelImplTest {
@Autowired
private SmsService smsService;
@Test
void testWeiGeSms() {
smsService.send(ChannelEnum.WEIGE, "15955149139", "");
}
}
stream 排序,允许null值
List<PointsMallGoods> skus = pointsList.stream()
.sorted(Comparator.comparing(PointsMallGoods::getPoints,Comparator.nullsLast(Long::compareTo)))
.toList();
webflux 框架
public Flux<SeckillGoods> bindOrChangeGoods(BindGoodsForm form) {
saveSeckillTime(form.getActId(), form.getTime()).subscribe();
return Flux.fromIterable(form.getGoodsList())
.flatMap(goodsBean -> saveSeckillGoods(form.getActId(), goodsBean));
}
public Mono<SeckillGoodsTimeModel> findAllByAct(String actId) {
SeckillGoodsTimeModel model = new SeckillGoodsTimeModel();
return getSortTime(actId).switchIfEmpty(Mono.fromCallable(SeckillTime::new))
.flatMap(seckillTime -> seckillGoodsRepository.findByActId(actId)
.collectList()
.switchIfEmpty(Mono.fromCallable(ArrayList::new))
.flatMap(seckillGoods -> {
model.setTime(seckillTime);
model.setGoods(seckillGoods);
return Mono.just(model);
}));
}
public Flux<SeckillGoods> bindOrChangeGoods(BindGoodsForm form) {
return saveSeckillTime(form.getActId(), form.getTime())
.flatMapMany(time -> Flux.fromIterable(form.getGoodsList())
.flatMap(goodsBean -> saveSeckillGoods(form.getActId(), goodsBean)));
}
开启 MyBatis-Plus SQL
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl