-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22017ab
commit b1957f6
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/test/java/de/dm/infrastructure/logcapture/CapturingAppenderUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.dm.infrastructure.logcapture; | ||
|
||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.filter.Filter; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
|
||
import java.util.Set; | ||
|
||
import static ch.qos.logback.core.spi.FilterReply.ACCEPT; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class CapturingAppenderUnitTest { | ||
|
||
@Mock | ||
LoggerContext loggerContext; | ||
|
||
CapturingAppender sut = new CapturingAppender(loggerContext, Set.of( | ||
"a.package", | ||
"another.package") | ||
); | ||
|
||
@SuppressWarnings("unchecked") // filter types are irrelevant | ||
@Test | ||
void neverFiltersAndNeverHasAnyFilters() { | ||
assertThat(sut.getFilterChainDecision(mock(ILoggingEvent.class))).isEqualTo(ACCEPT); | ||
|
||
sut.addFilter(mock(Filter.class)); | ||
|
||
assertThat(sut.getFilterChainDecision(mock(ILoggingEvent.class))).isEqualTo(ACCEPT); | ||
assertThat(sut.getCopyOfAttachedFiltersList()).isEmpty(); | ||
|
||
sut.clearAllFilters(); | ||
|
||
assertThat(sut.getFilterChainDecision(mock(ILoggingEvent.class))).isEqualTo(ACCEPT); | ||
} | ||
|
||
@Test | ||
void startStop() { | ||
assertThat(sut.isStarted()).isFalse(); | ||
sut.start(); | ||
assertThat(sut.isStarted()).isTrue(); | ||
sut.stop(); | ||
assertThat(sut.isStarted()).isFalse(); | ||
} | ||
|
||
} |