2014-02-17 59 views
0

這似乎確定PowerMock MockStatic想到還沒工作EasyMock的anyObject

EasyMock.expect(URLDecoder.decode("test", "UTF-8")).andThrow(new UnsupportedEncodingException("This is a test")); 

這不

EasyMock.expect(URLDecoder.decode((String) EasyMock.anyObject(), "UTF-8")).andThrow(new UnsupportedEncodingException("This is a test")); 

這將引發以下

java.lang.IllegalStateException: 2 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:47) 
at org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:40) 
at org.easymock.internal.RecordState.invoke(RecordState.java:78) 
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:40) 
at 

回答

0

如果你打算使用1匹配器在你的期望,那麼你需要使用所有匹配器。

不幸的是,在EasyMock出來的錯誤消息中沒有很好地解釋這一點,但是在其他字符串周圍添加一個EasyMock.eq()應該可以做到。

EasyMock.expect(URLDecoder.decode((String) EasyMock.anyObject(), EasyMock.eq("UTF-8"))).andThrow(new UnsupportedEncodingException("This is a test")); 
相關問題