Skip to content

Commit

Permalink
Refactored ExcludeTest to correctly use new setup
Browse files Browse the repository at this point in the history
Fixes #754
  • Loading branch information
whiskeysierra committed Aug 2, 2020
1 parent 20c1689 commit 5b5213f
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.zalando.logbook.HttpLogWriter;
import org.zalando.logbook.HttpRequest;
import org.zalando.logbook.Logbook;
import org.zalando.logbook.MockHttpRequest;
import org.zalando.logbook.Precorrelation;

import java.io.IOException;
import java.util.function.Predicate;
Expand All @@ -35,33 +36,33 @@ public Predicate<HttpRequest> requestCondition() {
@Autowired
private Logbook logbook;

@MockBean(name = "httpLogger")
private Logger logger;
@MockBean
private HttpLogWriter writer;

@BeforeEach
void setUp() {
doReturn(true).when(logger).isTraceEnabled();
doReturn(true).when(writer).isActive();
}

@Test
void shouldExcludeHealth() throws IOException {
logbook.process(request("/health")).write();

verify(logger, never()).trace(any());
verify(writer, never()).write(any(Precorrelation.class), any());
}

@Test
void shouldExcludeAdmin() throws IOException {
logbook.process(request("/admin")).write();

verify(logger, never()).trace(any());
verify(writer, never()).write(any(Precorrelation.class), any());
}

@Test
void shouldExcludeAdminWithPath() throws IOException {
logbook.process(request("/admin/users")).write();

verify(logger, never()).trace(any());
verify(writer, never()).write(any(Precorrelation.class), any());
}

@Test
Expand All @@ -70,7 +71,7 @@ void shouldExcludeAdminWithQueryParameters() throws IOException {
.withPath("/admin")
.withQuery("debug=true")).write();

verify(logger, never()).trace(any());
verify(writer, never()).write(any(Precorrelation.class), any());
}

private MockHttpRequest request(final String path) {
Expand Down

0 comments on commit 5b5213f

Please sign in to comment.