alibaba / testable-mock

换种思路写Mock,让单元测试更简单
https://alibaba.github.io/testable-mock/
MIT License
1.83k stars 310 forks source link

stream表达式相关的问题,具体没找到问题点 #250

Closed suyujie closed 2 years ago

suyujie commented 2 years ago

List rlist = boList.stream().map(bo->bo.getId()).distinct().collect(toList()); List rlist = boList.stream().map(XBean::getId).distinct().collect(toList());

测试中,第二行代码报错了。第一行正常 第二行报错信息 区别就是 一个用 箭头方式,一个用::方式。 其中对象里面的 Id 是 lombok的@Data注解生成的get set

java.lang.IncompatibleClassChangeError: Expected static method com.jd.ipc.model.dto.VirtualCateDto.getDeptId3()Ljava/lang/Integer;

iceqing commented 2 years ago

遇到同样的问题 版本是:0.7.1

Caused by: java.lang.IncompatibleClassChangeError: Expected static method xxx.malldb.MallItemPropertyName.getName()Ljava/lang/String;
    at xxx.service.impl.MallItemPropertyServiceImpl.Lambda$_getName_6(MallItemPropertyServiceImpl.java)
    at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320)
    at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
zcbbpo commented 2 years ago

是像这种的吗?

public static class XBean {
        private Long id;

       public Long getId() {
           return id;
       }

       public void setId(Long id) {
           this.id = id;
       }
   }

    public void foo() {
        List<XBean> testList = Collections.emptyList();
        //noinspection RedundantOperationOnEmptyContainer
        List<Long> response = testList.stream().map(XBean::getId).distinct().collect(Collectors.toList());
    }
suyujie commented 2 years ago

是的; 箭头好使,双冒号不行

把 XBean::getId 换成 o->o.getId() 就好使。

---原始邮件--- 发件人: @.> 发送时间: 2021年12月16日(周四) 晚上6:12 收件人: @.>; 抄送: @.**@.>; 主题: Re: [alibaba/testable-mock] stream表达式先关的问题,具体没找到问题点 (Issue #250)

是像这种的吗? public static class XBean { private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; } } public void foo() { List<XBean> testList = Collections.emptyList(); //noinspection RedundantOperationOnEmptyContainer List<Long> response = testList.stream().map(XBean::getId).distinct().collect(Collectors.toList()); }
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

suyujie commented 2 years ago

已经修复了?时效杠杠的呀。。会发布小版本吗?