public class JUnitTest {
@Autowired ApplicationContext context;
static Set<JUnitTest> testObjects = new HashSet<JUnitTest>();
static ApplicationContext contextObject = null;
@Test public void test3() {
assertThat(testObjects, not(hasItem(this)));
testObjects.add(this);
assertThat(contextObject, either(is(nullValue())).or(is(this.context))); //error
contextObject = this.context;
}
}
错误信息:
The method or(Matcher< ? super Object >) in the type
CombinableMatcher.CombinableEitherMatcher< Object> is not applicable for the
arguments (Matcher< ApplicationContext>)
如何修复此代码?
您可以将类型指定为nullValue
的参数,以使其返回适当的类型。
assertThat(contextObject, either(is(nullValue(ApplicationContext.class))).or(is(this.context)));