Hi
I got a problem with jmock2.5.0.
Below is my tests that past under jmock2.2.0. After upgrading
jmock to 2.5.0, these tests got failed with the stack trace below.
@Test
public void
testCollectMissDataRight() throws Exception
{
final Collector collector0
= context.mock(Collector.class);
final SocketSession fSession =
context.mock(SocketSession.class);
MaintenanceSession session
=
new
MaintenanceSession(null,collector0);
context.checking(new
Expectations()
{
{
one(collector0).isConnectedSector(with(equal("TACC00")));
will(returnValue(fSession));
one(fSession).startCollectLeftData((byte[])with(anything()));
}
});
byte[] data =
"0000004820000001234567890123456789012345678999 TACC00
".getBytes();
session.processData(data);
context.assertIsSatisfied();
}
@Test
public void
testCollectMissDataWrong() throws Exception
{
final Collector collector1
= context.mock(Collector.class);
final SocketSession fSession1 =
context.mock(SocketSession.class);
MaintenanceSession session
=
new
MaintenanceSession(null,collector1);
context.checking(new
Expectations()
{
{
one(collector1).isConnectedSector(with(equal("TACC00")));
will(returnValue(null));
never(fSession1).startCollectLeftData((byte[])with(anything()));
one(collector1).processAPError((String)with(anything()));
}
});
byte[] data =
"0000004820000001234567890123456789012345678999 TACC00
".getBytes();
session.processData(data);
context.assertIsSatisfied();
}
java.lang.IllegalArgumentException: a mock with name collector
already exists
at org.jmock.Mockery.mock(Mockery.java:128)
at
org.jmock.Mockery.mock(Mockery.java:120)
at
rae07a.collect.MaintenanceSessionTest.testCollectMissDataWrong(MaintenanceSessionTest.java:45)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
java.lang.reflect.Method.invoke(Method.java:585)
at
org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at
org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at
org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at
org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I got into jmock2.50 source and found out this problem has
something to do with defaultNameFor method which always gives the same name for
the same class.
public <T> T mock(Class<T>
typeToMock) {
return mock(typeToMock,
namingScheme.defaultNameFor(typeToMock));
}
Maybe this is supposed to do. Can anybody help me with some
answer?
James
Confidentiality Notice: The information
contained in this e-mail and any accompanying attachment(s)
is intended only for the use of the intended recipient and may be confidential
and/or privileged of Neusoft Corporation, its subsidiaries and/or its
affiliates. If any reader of this communication is not the intended
recipient, unauthorized use, forwarding, printing, storing, disclosure
or copying is strictly prohibited, and may be unlawful. If you have
received this communication in error, please immediately notify the
sender by return e-mail, and delete the original message and all copies
from your system. Thank you.