Skip to content

Wrong mocked instance returned (StrictExpectations) #450

@Milbor-zz

Description

@Milbor-zz

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();
                }
            };
        }
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions