如何调试“类型X中的方法或匹配器不适用于参数”的错误?

问题描述 投票:0回答:1
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>)

如何修复此代码?

java spring junit annotations junit4
1个回答
-1
投票

您可以将类型指定为nullValue的参数,以使其返回适当的类型。

assertThat(contextObject, either(is(nullValue(ApplicationContext.class))).or(is(this.context)));
© www.soinside.com 2019 - 2024. All rights reserved.