Skip to content

Commit 2f50e5c

Browse files
committed
Address review comments
Signed-off-by: Toshiaki Maki <makingx@gmail.com>
1 parent 52405c5 commit 2f50e5c

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServletAutoConfigurationTests.java

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616

1717
package org.springframework.grpc.autoconfigure.server;
1818

19-
import java.util.concurrent.atomic.AtomicBoolean;
20-
2119
import io.grpc.BindableService;
2220
import io.grpc.ServerServiceDefinition;
2321
import io.grpc.internal.GrpcUtil;
24-
import io.grpc.servlet.jakarta.GrpcServlet;
25-
import io.grpc.servlet.jakarta.ServletAdapter;
2622
import io.grpc.servlet.jakarta.ServletServerBuilder;
2723
import org.junit.jupiter.api.Test;
2824

@@ -35,7 +31,9 @@
3531
import org.springframework.util.unit.DataSize;
3632

3733
import static org.assertj.core.api.Assertions.assertThat;
34+
import static org.mockito.ArgumentMatchers.any;
3835
import static org.mockito.Mockito.mock;
36+
import static org.mockito.Mockito.verify;
3937
import static org.mockito.Mockito.when;
4038

4139
/**
@@ -74,40 +72,32 @@ void whenNoBindableServicesRegisteredAutoConfigurationIsSkipped() {
7472

7573
@Test
7674
void whenWebApplicationServletIsAutoConfigured() {
77-
this.contextRunner().run((context) -> {
78-
assertThat(context).getBean(ServletRegistrationBean.class)
79-
.isNotNull()
80-
.extracting("servlet")
81-
.isInstanceOf(GrpcServlet.class)
82-
.extracting("servletAdapter")
83-
.isInstanceOf(ServletAdapter.class)
84-
.extracting("maxInboundMessageSize")
85-
.isEqualTo(GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE);
86-
});
75+
this.contextRunner().run((context) -> assertThat(context).getBean(ServletRegistrationBean.class).isNotNull());
8776
}
8877

8978
@Test
9079
void whenCustomizerIsRegistered() {
91-
AtomicBoolean invoked = new AtomicBoolean(false);
92-
ServerBuilderCustomizer<ServletServerBuilder> customizer = serverBuilder -> invoked.set(true);
93-
this.contextRunner().withBean(ServerBuilderCustomizer.class, () -> customizer).run(context -> {
94-
assertThat(context).getBean(ServletRegistrationBean.class).isNotNull();
95-
assertThat(invoked.get()).isTrue();
96-
});
80+
ServerBuilderCustomizer<ServletServerBuilder> customizer = mock();
81+
this.contextRunner()
82+
.withBean(ServerBuilderCustomizer.class, () -> customizer)
83+
.run(context -> verify(customizer).customize(any(ServletServerBuilder.class)));
9784
}
9885

9986
@Test
100-
void whenMaxInboundMessageSizeIsConfigured() {
101-
this.contextRunner().withPropertyValues("spring.grpc.server.max-inbound-message-size=10KB").run(context -> {
102-
assertThat(context).getBean(ServletRegistrationBean.class)
103-
.isNotNull()
104-
.extracting("servlet")
105-
.isInstanceOf(GrpcServlet.class)
106-
.extracting("servletAdapter")
107-
.isInstanceOf(ServletAdapter.class)
108-
.extracting("maxInboundMessageSize")
109-
.isEqualTo((int) DataSize.ofKilobytes(10).toBytes());
110-
});
87+
void whenMaxInboundMessageSizeIsSetThenItIsUsed() {
88+
this.contextRunner()
89+
.withPropertyValues("spring.grpc.server.max-inbound-message-size=10KB")
90+
.run(context -> assertThat(context).getBean(ServletRegistrationBean.class)
91+
.hasFieldOrPropertyWithValue("servlet.servletAdapter.maxInboundMessageSize",
92+
Math.toIntExact(DataSize.ofKilobytes(10).toBytes())));
93+
}
94+
95+
@Test
96+
void whenMaxInboundMessageSizeIsNotSetThenDefaultIsUsed() {
97+
this.contextRunner()
98+
.run((context) -> assertThat(context).getBean(ServletRegistrationBean.class)
99+
.hasFieldOrPropertyWithValue("servlet.servletAdapter.maxInboundMessageSize",
100+
GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE));
111101
}
112102

113103
}

0 commit comments

Comments
 (0)