问题描述
我有这个测试用例
public void testCacheSyncSingleColumn() throws Exception {
resetAll();
String schema = "barcelona_mm";
String mainTable = "notes";
String mainCol = "assignee_id";
String mainColValue = "1";
String mapQuery = "SELECT firstname AS value FROM #.security_user WHERE security_user_id = ";
String queryResult = "Support Operations";
String key = mainTable + "." + mainCol;
String[] lineA = new String[] { mainTable,mainCol,"security_user","security_user_id","firstname" };
String[] lineB = new String[] { "" };
FileReader fileMock = null;// EasyMock.createMock(FileReader.class);
CSVReader mockReader = EasyMock.createMock(CSVReader.class);
connectionFactoryMock = EasyMock.createMock(ConnectionFactory.class);
cacheSignatureService = new CachedSignatureServiceImpl();
SignatureDao signatureDaoMock = EasyMock.createMock(SignatureDao.class);
SignatureReader signatureReaderMock = EasyMock.createMock(SignatureReader.class);
setInternalState(cacheSignatureService,SignatureReader.class,signatureReaderMock);
setInternalState(cacheSignatureService,SignatureDao.class,signatureDaoMock);
powermockito.whenNew(CSVReader.class).withArguments(fileMock).thenReturn(mockReader);
// ERROR AT THIS LINE
expect(mockReader.readNext()).andReturn(lineA);
expect(mockReader.readNext()).andReturn(lineB);
mockReader.close();
replayAll();
JdbcTemplate template = createMock(JdbcTemplate.class);
expect(template.query(EasyMock.<String> anyObject(),EasyMock.<PreparedStatementSetter> anyObject(),EasyMock.<ResultSetExtractor<String>> anyObject())).andReturn(queryResult).anyTimes();
expect(signatureReaderMock.getQuery(EasyMock.anyString(),EasyMock.anyString())).andReturn(mapQuery);
expect(signatureReaderMock.getRefKey(EasyMock.anyString(),EasyMock.anyString())).andReturn(key);
expect(signatureReaderMock.getRefKey(EasyMock.anyString(),EasyMock.anyString())).andReturn(key);
expect(signatureDaoMock.getValue(EasyMock.anyString(),EasyMock.anyString(),EasyMock.anyString())).andReturn(queryResult);
replayAll(signatureReaderMock,signatureDaoMock);
String result = cacheSignatureService.getValue("source",schema,mainTable,mainColValue);
Assert.assertTrue(result.equals(queryResult));
}
如果我运行10次,那么在所有10次中都会经过一段时间,并抛出错误
java.lang.IllegalStateException: 0 matchers expected,1 recorded.
This exception usually occurs when matchers are mixed with raw values when recording a method:
foo(5,eq(6)); // wrong
You need to use no matcher at all or a matcher for every single param:
foo(eq(5),eq(6)); // right
foo(5,6); // also right
at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:52)
at org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:41)
at org.easymock.internal.RecordState.invoke(RecordState.java:51)
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:40)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:101)
at org.easymock.internal.ClassproxyFactory$MockMethodInterceptor.intercept(ClassproxyFactory.java:97)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)