jmockit/jmockit1

Overridden methods from base class call methods from fake subclass

jmf-tls opened this issue · 1 comments

  • Version of JMockit that was used:
    1.49 (also in master branch at 5c6a2df)

  • Description of the problem or enhancement request:

Consider this test scenario

   public static class BaseClass {
      protected int doSomething() { return 1; }
   }

   public static class Subclass extends BaseClass {
      @Override protected int doSomething() { return super.doSomething() + 1; }
   }

   public static final class FakeForSubclass extends MockUp<Subclass> {
      @Mock public int doSomething(Invocation inv) { return inv.proceed(); }
   }

When a test uses FakeForSubclass and creates an instance of Subclass, calling subclass.doSomething() results in a StackOverflowError.
Initially the invocation proceeds to run the code on Subclass, which calls the method on the base class that it overrides.
This call is intercepted by FakeForSubclass, which calls the code in Subclass again, resulting in a loop that ends in the StackOverflowError. The code in BaseClassshould be called instead.

I created a pull request that adds a validation for this issue on the FakedClassWithSuperClassTest: #704

Probably related with #671