jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
461 stars 239 forks source link

Mocking of Base class methods #652

Closed numeralEasy closed 4 years ago

numeralEasy commented 4 years ago

Please provide the following information:

Base class methods aren't mocked as of version 1.48

public class Example {

    static class Foo {

        public String doSomething() {
            return "Foo";
    }
    }
    static class SubFoo extends Foo {

        public String doSomething() {
            return "SubFoo" + super.doSomething();
        }
    }

    @Test
    public void testThatFooMethodIsMocked(@Mocked Foo foo) {
        Assert.assertThat(new SubFoo().doSomething(), CoreMatchers.equalTo("SubFoonull"));
    }
}

The same Problem occured years ago and you reverted it. https://github.com/jmockit/jmockit1/issues/236

Was this feature dropped or is it a bug?

Best regards

numeralEasy commented 4 years ago

When i revert you change (6a97ea1be2cc6c04fa8454585159f452d54f0ef6) to:

public boolean isInstanceOfMockedClass(@Nonnull Object mockedInstance) {
       Class<?> mockedClass = mockedInstance.getClass();
          return findClassAssignableFrom(mockedClasses, mockedClass) != null;
}

... including findClassAssignableFrom ...

the test above is green.

rliesenfeld commented 4 years ago

It was dropped.