powermock - AssertionError when mocking java.sql.TimeStamp -


please find below java code .

timestamp timestamp = powermock.createmock(timestamp.class); powermock.expectnew(timestamp.class, new class[] {long.class}, system.currenttimemillis()).andreturn(timestamp).times(2); powermock.replay(timestamp, timestamp.class); powermock.verify(timestamp, timestamp.class); 

then getting below error

java.lang.assertionerror: expectation failure on verify: java.sql.timestamp(1431344562673): expected: 1, actual: 0 @ org.powermock.api.easymock.internal.invocationcontrol.newinvocationcontrolassertionerror.throwassertionerrorfornewsubstitutionfailure(newinvocationcontrolassertionerror.java:21) @ org.powermock.api.easymock.powermock.verifyclass(powermock.java:2279) @ org.powermock.api.easymock.powermock.verify(powermock.java:1646)

why?

if have close @ code implmentation of newinvocationcontrolassertionerror (which thrown exception) notice kind of exception thrown when have defined powermock.expectnew(..)andreturn(..).times(n) in actual code tested new object created less n times

have @ implementation details here (newinvocationcontrolassertionerror )

so suggest implement in way powermock.expectnew(...).andreturn(...).anytimes()

hope helps!

good luck!


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -