'New code is not showing in Sonarqube Coverage on new code
I am trying to cover few lines of the code with junit test case. Though the test case is covering the lines which I found after debugging the test case, but in Sonarqube Coverage on new code those lines are not showing as covered ..
Below is the code :
@Override
public StandardMapper createMapper(Services services) {
val objectMapper = ObjectMapperFactory.createObjectMapper();
TransformerPool transformerPool = new TransformerPool(getTransformerPoolSize());
try (RetryingTransporter retryingTransporter = new RetryingTransporter(
new SoapTransporter(objectMapper,Configuration.class));
ResponseGeneratorService responseGeneratorService = new ResponseGeneratorService(
JAXBContext.newInstance(Response.class));
ConfigurationReader configurationReader = new ConfigurationReader();
ParsingTransformer parsingTransformer = new ParsingTransformer(
new RequestTransformerService(transformerPool));) {
return new StandardMapper(configurationReader, parsingTransformer, retryingTransporter,
responseGeneratorService);
} catch (Exception e) {
log.error(TransformerConstants.TRANSFORM + TransformerConstants.ERROR_101, e);
}
return null;
}
private int getTransformerPoolSize() {
try {
String poolSize = ((Function<String, String>) System::getenv).apply(TransformerConstants.TRANSFORMER_POOL_SIZE);
return Integer.parseInt(poolSize);
} catch (NumberFormatException nfe) {
log.error(TransformerConstants.TRANSFORMER_POOL_INITIALIZATION_ERROR, nfe);
}
return TransformerConstants.DEFAULT_TRANSFORMER_POOL_SIZE;
}
and test case for the above scenario is
@Test
public void testCreateMapper_validTransformerPoolSize() throws Exception {
restoreSystemProperties(() -> {
withEnvironmentVariable(TransformerConstants.TRANSFORMER_POOL_SIZE, "7").execute(() -> {
Assert.assertTrue(factory.createMapper(null) instanceof StandardMapper);
});
});
}
The above test case is passing and covers lines from getTransformerPoolSize() method but when I run above test case and put debugger point at return Integer.parseInt(poolSize); debugger points comes there but in sonarqube code coverage for new code it doesn't shows as covered ..
Below line from getTransformerPoolSize method is not getting covered even though Junit test case is covering that ..
return Integer.parseInt(poolSize);
Can someone suggest how to fix this issue ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|