Search code examples
javagenericsjmock

JMock unexpected invocation with weird invocation parameter


Given:

A<T>
B extends A<String>

IMyInterface {
  List<T> myMethod(A<T>)
  List<String> myMethod(B)
}

When running a test that calls

foo = myMethod(new B());

I get this JMock error

unexpected invocation: IMyInterface.myMethod(<{}>)

Does anybody know what (<{}>) mean?


Solution

  • JMock uses the toString() implementation of each object that it received when it's formatting the error message so what you're seeing is probably a result of the implementation of toString() in your B class. JMock adds the angle brackets so I'd say B.toString() is returning "{}".