junit Java中Lambda expression的单元覆盖率[已关闭]

vsaztqbk  于 5个月前  发布在  Java
关注(0)|答案(1)|浏览(54)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
12天前关闭
Improve this question
我试图掩盖看起来像是

protected SessionBuilderConfigurer getSessionBuilderConfigurer() {
    return cqlSessionBuilder -> {
        ProgrammaticDriverConfigLoaderBuilder programmaticDriverConfigLoaderBuilder;
   
        programmaticDriverConfigLoaderBuilder = getCassandraWithoutSslConfiguration();//Local method

        DriverConfigLoader driverConfigLoader = programmaticDriverConfigLoaderBuilder.build();
        return cqlSessionBuilder
            .withConfigLoader(driverConfigLoader)
            .withAuthCredentials(properties.getUsername(), properties.getPassword());
    };
  }

字符串
这在JUnit中根本没有涉及。
JUnit:

//Class level
@ExtendWith(MockitoExtension.class)

@InjectMocks WaausCassandraConfiguration configuration;

//Inside method
Assertions.assertNotNull(configuration.getSessionBuilderConfigurer());

57hvy0tb

57hvy0tb1#

getSessionBuilderConfigurer()创建了一个SessionBuilderConfigurer对象,lambda是某个方法(可能是SessionBuilderConfigurer.configure())的实现。
如果你想在lambda中执行代码,你需要执行那个方法:

CqlSessionBuilder sessionBuilder = mock(CqlSessionBuilder.class);
// the following line create the SessionBuilderConfigurer
SessionBuilderConfigurer configurer = configuration.getSessionBuilderConfigurer();
// the following line calls the lambda
configurer.configure(sessionBuilder);

// now you need to assert that the correct methods on the sessionBuilder have been called

字符串

相关问题