Java 如何调试错误";类型X中的方法或匹配器不适用于参数“1”;? 公共类JUnitTest{ @自动连线应用程序上下文上下文; static Set testObjects=new HashSet(); 静态ApplicationContext contextObject=null; @测试公共void test3(){ 资产(testObjects,而不是(hasItem(this)); 添加(这个); assertThat(contextObject,要么是(nullValue())。要么是(this.context));//错误 contextObject=this.context; } }
错误消息:Java 如何调试错误";类型X中的方法或匹配器不适用于参数“1”;? 公共类JUnitTest{ @自动连线应用程序上下文上下文; static Set testObjects=new HashSet(); 静态ApplicationContext contextObject=null; @测试公共void test3(){ 资产(testObjects,而不是(hasItem(this)); 添加(这个); assertThat(contextObject,要么是(nullValue())。要么是(this.context));//错误 contextObject=this.context; } },java,spring,junit,annotations,junit4,Java,Spring,Junit,Annotations,Junit4,错误消息: public class JUnitTest { @Autowired ApplicationContext context; static Set<JUnitTest> testObjects = new HashSet<JUnitTest>(); static ApplicationContext contextObject = null; @Test public void test3() { asse
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;
}
}
类型中的方法或(Matcher<?super Object>)
CombinableMatcher.CombinableItherMatcher
如何修复此代码?您可以指定一个类型作为
nullValue
的参数,使其返回适当的类型
The method or(Matcher< ? super Object >) in the type
CombinableMatcher.CombinableEitherMatcher< Object> is not applicable for the
arguments (Matcher< ApplicationContext>)
不客气。如果你觉得这个答案有用的话,请不要忘记投票并接受它。
assertThat(contextObject, either(is(nullValue(ApplicationContext.class))).or(is(this.context)));