假设我有一个Map<String, Action>
,我就这样:
assertThat( spyActionMap.get( "a" ) ).isInstanceOf( Action.class );
......通过。现在我想检查获得的Action
是否正确:
assertThat( spyActionMap.get( "a" ) ).isInstanceOf( Action.class ).getValue( Action.NAME ).isEqualTo( "Go crazy" );
...不编译,不足为奇。有没有办法做这种事情?
答案 0 :(得分:1)
您可以尝试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);