Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 3.2
    • Fix Version/s: 4.0
    • Component/s: mock
    • Labels:
      None
    • Environment:
      *

      Description

      The following Test failes on the wrong Assertion:

      <code>
      public class UnitilsAssertInvokedTest extends UnitilsTestNG {
          
          public static class A {
              public void method(Object o) {
              }
          }

          Mock<A> b1;
          Mock<A> b2;
          Mock<A> b3;
          Mock<A> b4;
          
          @Dummy
          Object o;
          
          @Test(groups="Unit")
          public void testUnitilsAssertInvoked() {
              
              b1.getMock().method(o);
              //b2.getMock().method(o);
              b3.getMock().method(o);
              b4.getMock().method(o);
              
              b1.assertInvoked().method(null);
              b2.assertInvoked().method(null); // asserts invocation of b3.method(o), should fail here
              b3.assertInvoked().method(null); // asserts invocation of b4.method(o)
              b4.assertInvoked().method(null); // fails here
              
              MockUnitils.assertNoMoreInvocations();
          }
      }
      </code>

      The next Test failes with the wrong Exception Message:

      <code>
      public class UnitilsAssertInvokedTest01 extends UnitilsTestNG {
          
          public static class A {
              public void method(Object o) {
              }
          }

          Mock<A> b1;
          Mock<A> b2;
          Mock<A> b3;
          Mock<A> b4;
          
          @Dummy
          Object o;
          
          @Test(groups="Unit")
          public void testUnitilsAssertInvoked() {
              
              b1.getMock().method(o);
              b2.getMock().method(o);
              b3.getMock().method(o);
              b4.getMock().method(o);
              
              b1.assertInvoked().method(null);
              //b2.assertInvoked().method(null);
              b3.assertInvoked().method(null); // asserts invocation of b2.method(o)
              b4.assertInvoked().method(null); // asserts invocation of b3.method(o)
              
              MockUnitils.assertNoMoreInvocations();
          }
      }
      </code>

      Exception Message:
      java.lang.AssertionError: No more invocations expected, yet observed following calls:
      1. b4.method(o) .....

      Proposed Solution:
      Method org.unitils.mock.core.BehaviorDefiningInvocation.matches(ProxyInvocation) only matches the method and the arguments, but not the proxy instance itself. Adding something like:
      <code>
      if (!getProxy().equals(proxyInvocation.getProxy())) {
                  return -1;
      }
      </code>
      would resolve the Problem.


      PS: probably connected with UNI-231

        Attachments

          Activity

            People

            • Assignee:
              tim.ducheyne Tim Ducheyne
              Reporter:
              klaschkaf Florian Klaschka
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: