Skip to content

Commit

Permalink
Polish argument capturing in two Tomcat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dreis2211 authored and snicoll committed Feb 26, 2018
1 parent c3ae02a commit cbabf54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.AprLifecycleListener;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests;
import org.springframework.http.server.reactive.HttpHandler;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -69,22 +67,14 @@ public void tomcatCustomizers() {
}

@Test
public void contextIsAddedToHostBeforeCustomizersAreCalled() throws Exception {
public void contextIsAddedToHostBeforeCustomizersAreCalled() {
TomcatReactiveWebServerFactory factory = getFactory();
TomcatContextCustomizer customizer = mock(TomcatContextCustomizer.class);
willAnswer(new Answer<Void>() {

@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
assertThat(((Context) invocation.getArguments()[0]).getParent())
.isNotNull();
return null;
}

}).given(customizer).customize(any(Context.class));
factory.addContextCustomizers(customizer);
this.webServer = factory.getWebServer(mock(HttpHandler.class));
verify(customizer).customize(any(Context.class));
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(customizer).customize(contextCaptor.capture());
assertThat(contextCaptor.getValue().getParent()).isNotNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import org.springframework.boot.testsupport.rule.OutputCapture;
import org.springframework.boot.web.server.WebServerException;
Expand All @@ -63,7 +62,6 @@
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -147,22 +145,14 @@ public void tomcatCustomizers() {
}

@Test
public void contextIsAddedToHostBeforeCustomizersAreCalled() throws Exception {
public void contextIsAddedToHostBeforeCustomizersAreCalled() {
TomcatServletWebServerFactory factory = getFactory();
TomcatContextCustomizer customizer = mock(TomcatContextCustomizer.class);
willAnswer(new Answer<Void>() {

@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
assertThat(((Context) invocation.getArguments()[0]).getParent())
.isNotNull();
return null;
}

}).given(customizer).customize(any(Context.class));
factory.addContextCustomizers(customizer);
this.webServer = factory.getWebServer();
verify(customizer).customize(any(Context.class));
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(customizer).customize(contextCaptor.capture());
assertThat(contextCaptor.getValue().getParent()).isNotNull();
}

@Test
Expand Down

0 comments on commit cbabf54

Please sign in to comment.