I have a test case which uses @ExtendWith(OutputCaptureExtension.class) and test case is as below.
@Test
void testOneSimpleMethodWhichHaveDebugLogs(CapturedOutput output) {
....//// When then and everything is here.
Object param = Mockito.mock(Object.class);
Object.setExampleMap(map);
Mockito.when(param.getMap()).thenReturn(map);
ImplementationOfSomeAbstractClass obj = new ImplementationOfSomeAbstractClass();
Status result = obj.validation(param);
assertEquals(StatusEnum.NO_CHANGE, result);
assertTrue(output.getAll().contains("Some Text"));
}
The class which have the logger method is as below.
@Slf4j
@RequiredArgsConstructor
public abstract class SomeAbstractClass {
protected Status validation(Object param) {
Status result = Status.UNKNOWN;
try {
param1 = someOtherPrivateMethod();
result = anotherProtectedMethod(param, param1);
} catch (Exception e) {
log.error("Invalid.", e);
}
return result;
}
protected Result anotherProtectedMethod(Object param, Object param1) {
try {
if (somCondition) {
log.error("SomeText");
}
if (somCondition) {
log.warn("SomeText");
}
if (somCondition) {
log.info("SomeText");
}
if (somCondition) {
log.debug("SomeText");
} else {
log.info("SomeText");
log.info("SomeText");
}
} catch (Exception exp) {
log.error("SomeText");
}
log.error("SomeText");
return null;
}
}
All other log levels are getting printed on the console but somehow debug logs are not getting printed on console and only this single test case is failing.
Please help.