Skip to content

Commit

Permalink
add CapturingAppenderUnitTest
Browse files Browse the repository at this point in the history
  • Loading branch information
cleaning-agent committed Nov 24, 2023
1 parent 22017ab commit b1957f6
Showing 1 changed file with 49 additions and 0 deletions.
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();
}

}

0 comments on commit b1957f6

Please sign in to comment.