gpt4 book ai didi

java - AssertJ - 检查类后继续流畅的断言

转载 作者:行者123 更新时间:2023-11-30 06:51:24 25 4
gpt4 key购买 nike

假设我有一个Map<String, Action>我是这样的:

    assertThat( spyActionMap.get( "a" ) ).isInstanceOf( Action.class );

...通过。现在我想检查Action得到的是正确的:

    assertThat( spyActionMap.get( "a" ) ).isInstanceOf( Action.class ).getValue( Action.NAME ).isEqualTo( "Go crazy" );

...无法编译,这并不奇怪。有什么办法可以做到这种事情吗?

最佳答案

您可以尝试isInstanceOfSatisfying并在 Consumer 中指定您的断言:

Object yoda = new Jedi("Yoda", "Green");
Object luke = new Jedi("Luke Skywalker", "Green");

Consumer<Jedi> jediRequirements = jedi -> {
assertThat(jedi.getLightSaberColor()).isEqualTo("Green");
assertThat(jedi.getName()).doesNotContain("Dark");
};

assertThat(yoda).isInstanceOfSatisfying(Jedi.class, jediRequirements);
assertThat(luke).isInstanceOfSatisfying(Jedi.class, jediRequirements);

关于java - AssertJ - 检查类后继续流畅的断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42704987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com