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

Wrong mocked instance returned (StrictExpectations) #450

Closed
Milbor opened this Issue Aug 28, 2017 · 0 comments

Comments

2 participants
@Milbor

Milbor commented Aug 28, 2017

Passes in 1.28.
Issue #404 was fixed for Expectations only.
StrictExpectations still return wrong instance.

@ContextConfiguration(classes = TestConfig.class)
public class JmockitTest extends AbstractTestNGSpringContextTests {
    @Capturing
    private SubManager manager;
    @Autowired
    private System system;
    private Entity stub = new Entity();

    @Test
    public void test() {
        new StrictExpectations() {{
            manager.find();
            result = stub;
        }};
        final Entity actual = system.call();
        assertSame(actual, stub);
    }

    public static class System {
        @Autowired
        private SubManager manager;

        public Entity call() {
            return manager.find();
        }
    }

    public interface SubManager extends Manager {
    }

    public interface Manager {
        Entity find();
    }

    public static class Entity {
    }

    @Configuration
    public static class TestConfig {
        @Bean
        protected System system() {
            return new System();
        }

        @Bean
        protected SubManager manager() {
            return new SubManager() {
                @Override
                public Entity find() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    }
}

@rliesenfeld rliesenfeld self-assigned this Aug 29, 2017

@rliesenfeld rliesenfeld added the bug label Aug 29, 2017

@jmockit jmockit locked and limited conversation to collaborators Oct 29, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.