Loading ...
Sorry, an error occurred while loading the content.

1664Misleading error message when matches are type promoted

Expand Messages
  • joshuaball65495
    Jun 6, 2013

      The following unit test:

      package sandbox;

      import org.easymock.EasyMockSupport;
      import org.junit.Test;

      import static org.easymock.EasyMock.*;

      public class EasyMocksSandbox extends EasyMockSupport {

      private static interface Interface {
      Object method(long l);

      public void test() throws Throwable {
      Interface mock = createMock(Interface.class);






      produces the following confusing error message:

      Unexpected method call Interface.method(1):
      Interface.method(1): expected: 1, actual: 0
      at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:44)
      at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:85)
      at sandbox.$Proxy5.method(Unknown Source)
      at sandbox.EasyMocksSandbox.test(EasyMocksSandbox.java:22)

      In case the formatting is screwed up, you can see it here: http://pastebin.com/5g3ZVX9Q

      Why is Interface.method(1) unexpected when the very next line says that it is expected?

      The reason is that eq() received an int, and the interface uses a long. Equals.equals returns false because Int and Long are of different classes.

      Can we change Equals.equals to be more forgiving around numeric type promotion, or else change ArgumentToString.appendArgument to print more precise literals, such as 1l instead of 1?