Skip to content

Commit

Permalink
Merge pull request #486 from zalando/feature/improve-test
Browse files Browse the repository at this point in the history
Improved tests
  • Loading branch information
whiskeysierra committed Apr 15, 2019
2 parents 4b11975 + 60d7407 commit 0f829e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
Expand All @@ -30,7 +31,10 @@
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
import static org.zalando.logbook.Conditions.exclude;
import static org.zalando.logbook.Conditions.requestTo;
import static org.zalando.logbook.servlet.RequestBuilders.async;

/**
Expand All @@ -43,6 +47,7 @@ final class MultiFilterSecurityTest {
private final SecurityFilter securityFilter = spy(new SecurityFilter());

private final Logbook logbook = Logbook.builder()
.condition(exclude(requestTo("/api/empty")))
.sink(new DefaultSink(formatter, writer))
.build();

Expand Down Expand Up @@ -165,9 +170,16 @@ void shouldHandleUnauthorizedAsyncDispatchRequest() throws Exception {

@Test
void shouldEcho() throws Exception {
mvc.perform(get("/api/echo").content("Hello, world!"));
mvc.perform(post("/api/echo").content("Hello, world!"));

verify(writer).write(any(Precorrelation.class), argThat(containsString("Hello, world!")));
}

@Test
void shouldNotLogEmpty() throws Exception {
mvc.perform(get("/api/empty")).andExpect(content().string(""));

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

}
12 changes: 11 additions & 1 deletion logbook-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>logbook-spring-boot-starter</artifactId>
<packaging>pom</packaging>
<name>Logbook: Spring Boot Starter</name>
<description>Spring Boot Auto Configuration for Logbook and most of its libraries/adapters</description>
<scm>
Expand All @@ -21,4 +20,15 @@
<artifactId>logbook-spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<failIfNoTests>false</failIfNoTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 0f829e9

Please sign in to comment.