【问题标题】:How to use Lombok with cucumber and guice如何将龙目岛与黄瓜和吉斯一起使用
【发布时间】:2017-08-18 04:21:21
【问题描述】:

这是代码。我用黄瓜和guice。我想使用龙目岛。我正在使用 java 8

@ScenarioScoped
public class VolumeCreateTestSteps {
private final VolumeSummaryPage volumeSummaryPage;
private final VolumeCreateTabs volumeCreateTabs;
private final VolumeCreatePropertyTab volumeCreatePropertyTab;

@Inject
public VolumeCreateTestSteps(VolumeSummaryPage volumeSummaryPage,
                             VolumeCreateTabs volumeCreateTabs,
                             VolumeCreatePropertyTab volumeCreatePropertyTab) {
    this.volumeSummaryPage = volumeSummaryPage;
    this.volumeCreateTabs = volumeCreateTabs;
    this.volumeCreatePropertyTab = volumeCreatePropertyTab;
}

【问题讨论】:

    标签: java-8 cucumber lombok


    【解决方案1】:

    不知道黄瓜,但是 Lombok+Guice 可以很好地协同工作。语法很老套:

    @ScenarioScoped
    @RequiredArgsConstructor(onConstructor=@__(@Inject))
    public class VolumeCreateTestSteps {
        private final VolumeSummaryPage volumeSummaryPage;
        private final VolumeCreateTabs volumeCreateTabs;
        private final VolumeCreatePropertyTab volumeCreatePropertyTab;
    }
    

    这个有趣的onConstructor=@__(@Inject) 使用未定义的注释名称“两个下划线”是一个主要的 hack,但它从 Java 5 开始对我有用。目前,我正在使用带有 Java 8 的 Lombok 1.16.12。我猜,对于 Java 9、有问题,所以newest Lombok version使用了不同的hack:

    onConstructor_=@Inject
    

    注意结尾的下划线。

    【讨论】:

      猜你喜欢
      • 2016-03-06
      • 2017-01-09
      • 1970-01-01
      • 2018-03-29
      • 2021-03-27
      • 2011-06-19
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      相关资源
      最近更新 更多