Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Mocked not wrorking with abstract Base class #276

Closed
numeralEasy opened this issue May 2, 2016 · 1 comment
Closed

@Mocked not wrorking with abstract Base class #276

numeralEasy opened this issue May 2, 2016 · 1 comment
Assignees
Labels

Comments

@numeralEasy
Copy link

Jmockit Version 1.20+

You restored original mocking semantics when an expectation is recorded on a mocked base class:
#236
It was not restored for mocked abstract base class.

Abstract base class works with @capturing and partial mocking. @mocked doesn't work.

public final class TestSubClass {

    public static abstract class BaseClass {

        String name;

        public String getName() {
            return name;
        }

        public void setName(String n) {
            name = n;
        }

    }

    final static class SubClass extends BaseClass {

    }

    /**
     * with jomckit version 1.20+ :
     *   -fails if @Mocked used on abstract base class
     *   -works if @Mocked used on non-abstract base class
     * 
     * with jmockit version 1.19 : 
     *   -this test works
     * 
     * @param baseClass
     */
    @Test
    public void testGetName_fails(final @Mocked BaseClass baseClass) {

        new Expectations() {

            {
                baseClass.getName();
                result = "mocked name";
            }
        };

        assertEquals("mocked name", new SubClass().getName());
    }

    /**
     * works with abstract and non-abstract base class
     * @param baseClass
     */
    @Test
    public void testGetName_works(final @Capturing BaseClass baseClass) {

        new Expectations() {

            {
                baseClass.getName();
                result = "mocked name";
            }
        };

        assertEquals("mocked name", new SubClass().getName());
    }

    /**
     * partial mocking works with abstract and non-abstract base class
     * @param baseClass
     */
    @Test
    public void testGetName_works2() {

        final SubClass subClass = new SubClass();
        new Expectations(subClass) {

            {
                subClass.getName();
                result = "mocked name";
            }
        };

        assertEquals("mocked name", subClass.getName());
    }
}
@rliesenfeld rliesenfeld self-assigned this May 2, 2016
@rliesenfeld rliesenfeld added the bug label May 2, 2016
@rliesenfeld
Copy link
Member

Indeed, it's a bug.

Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants