Skip to content

Commit

Permalink
Added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakky54 committed Jun 17, 2024
1 parent ae16910 commit 605c9ab
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/test/java/nl/altindag/log/util/LogbackUtilsShould.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;

class LogbackUtilsShould {

@Test
void getLoggerEvenWhenItHasInitiallyLogger() {
void getLoggerEvenWhenItHasInitializedLogger() {
SubstituteLogger substituteLogger = mock(SubstituteLogger.class);
Logger logbackLogger = mock(Logger.class);

Expand Down Expand Up @@ -61,4 +62,26 @@ void failToGetLoggerWhenTheUnderlyingLoggerIsNotInitializedYet() {
}
}

@Test
void failToGetLoggerWhenTheUnderlyingLoggerIsNotInitializedAndExceedsRetryMechanism() {
System.setProperty("logcaptor.poll-counter-limit", "5");
System.setProperty("logcaptor.poll-delay-milliseconds", "10");

SubstituteLogger substituteLogger = mock(SubstituteLogger.class);

try (MockedStatic<LoggerFactory> mockedStatic = mockStatic(LoggerFactory.class)) {
mockedStatic.when(() -> LoggerFactory.getLogger("magic-logger"))
.thenReturn(substituteLogger);

assertThatThrownBy(() -> LogbackUtils.getLogger("magic-logger"))
.isInstanceOf(LogCaptorException.class)
.hasMessage("SLF4J Logger implementation should be of the type [ch.qos.logback.classic.Logger] but found [org.slf4j.helpers.SubstituteLogger].");

mockedStatic.verify(() -> LoggerFactory.getLogger("magic-logger"), times(6));
} finally {
System.clearProperty("logcaptor.poll-counter-limit");
System.clearProperty("logcaptor.poll-delay-milliseconds");
}
}

}

0 comments on commit 605c9ab

Please sign in to comment.