如何在@Configuration文件中模拟void方法

时间:2019-04-02 21:18:28

标签: spring spring-boot mocking

我尝试使用@Configuration文件模拟bean无效方法。这是我的配置文件:

    @Profile("test")
        @Configuration
        public class BeanTestConfiguration {
            @Bean
            @Primary
            public Binance binanceTest() {
                SomeClass mock = mock(SomeClass.class, "SomeClass");

                when(mock.getOneMethod()).thenAnswer(invocation -> {
                    List<Double> glass = new ArrayList<>();
                    buyGlass.add(400.0);

                    try {
                        Thread.sleep(1000);
                    } catch (Exception e) {
                        //Do nothing.
                    }

                    return glass;
                };

                doAnswer((Answer) invocation -> {
                    Object arg0 = invocation.getArgument(0);
                    Object arg1 = invocation.getArgument(1);

                    return null;
                }).when(mock).testVoid(isA(String.class), isA(Double.class), isA(Double.class));

                return mock;
            }

getOneMethod-可以,

但是使用testVoid方法,返回实际方法的实现。

0 个答案:

没有答案