我正在寻找一个Hamcrest Matcher来对返回java.util.Optional类型的方法进行单元测试。类似于以下内容:
@Test
public void get__Null(){
Optional<Element> element = Element.get(null);
assertThat( sasi , isEmptyOptional());
}
@Test
public void get__GetCode(){
Optional<Element> element = Element.get(MI_CODE);
assertThat( sasi , isOptionalThatMatches(allOf(hasproperty("code", MI_CODE),
hasProperty("id", notNullValue())));
}
是否有可在Maven仓库中使用的实现?
equalTo(...)
呢? - Jaroslaw Pawlak