|
27 | 27 | import java.util.concurrent.atomic.AtomicBoolean;
|
28 | 28 | import java.util.concurrent.atomic.AtomicReference;
|
29 | 29 | import java.util.function.Consumer;
|
| 30 | +import java.util.function.Supplier; |
30 | 31 | import java.util.stream.Stream;
|
31 | 32 |
|
32 | 33 | import static org.assertj.core.api.Assertions.assertThat;
|
33 |
| -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
34 | 34 | import static org.mockito.Mockito.*;
|
35 | 35 |
|
36 | 36 | public class ConnectionFactoryTest {
|
@@ -164,33 +164,34 @@ protected synchronized FrameHandlerFactory createFrameHandlerFactory() {
|
164 | 164 | public void heartbeatAndChannelMaxMustBeUnsignedShorts() {
|
165 | 165 | class TestConfig {
|
166 | 166 | int value;
|
167 |
| - Consumer<Integer> call; |
168 |
| - boolean expectException; |
| 167 | + Supplier<Integer> getCall; |
| 168 | + Consumer<Integer> setCall; |
| 169 | + int expected; |
169 | 170 |
|
170 |
| - public TestConfig(int value, Consumer<Integer> call, boolean expectException) { |
| 171 | + public TestConfig(int value, Supplier<Integer> getCall, Consumer<Integer> setCall, int expected) { |
171 | 172 | this.value = value;
|
172 |
| - this.call = call; |
173 |
| - this.expectException = expectException; |
| 173 | + this.getCall = getCall; |
| 174 | + this.setCall = setCall; |
| 175 | + this.expected = expected; |
174 | 176 | }
|
175 | 177 | }
|
176 | 178 |
|
177 | 179 | ConnectionFactory cf = new ConnectionFactory();
|
| 180 | + Supplier<Integer> getHeartbeart = () -> cf.getRequestedHeartbeat(); |
178 | 181 | Consumer<Integer> setHeartbeat = cf::setRequestedHeartbeat;
|
| 182 | + Supplier<Integer> getChannelMax = () -> cf.getRequestedChannelMax(); |
179 | 183 | Consumer<Integer> setChannelMax = cf::setRequestedChannelMax;
|
180 | 184 |
|
181 | 185 | Stream.of(
|
182 |
| - new TestConfig(0, setHeartbeat, false), |
183 |
| - new TestConfig(10, setHeartbeat, false), |
184 |
| - new TestConfig(65535, setHeartbeat, false), |
185 |
| - new TestConfig(-1, setHeartbeat, true), |
186 |
| - new TestConfig(65536, setHeartbeat, true)) |
187 |
| - .flatMap(config -> Stream.of(config, new TestConfig(config.value, setChannelMax, config.expectException))) |
| 186 | + new TestConfig(0, getHeartbeart, setHeartbeat, 0), |
| 187 | + new TestConfig(10, getHeartbeart, setHeartbeat, 10), |
| 188 | + new TestConfig(65535, getHeartbeart, setHeartbeat, 65535), |
| 189 | + new TestConfig(-1, getHeartbeart, setHeartbeat, 0), |
| 190 | + new TestConfig(65536, getHeartbeart, setHeartbeat, 65535)) |
| 191 | + .flatMap(config -> Stream.of(config, new TestConfig(config.value, getChannelMax, setChannelMax, config.expected))) |
188 | 192 | .forEach(config -> {
|
189 |
| - if (config.expectException) { |
190 |
| - assertThatThrownBy(() -> config.call.accept(config.value)).isInstanceOf(IllegalArgumentException.class); |
191 |
| - } else { |
192 |
| - config.call.accept(config.value); |
193 |
| - } |
| 193 | + config.setCall.accept(config.value); |
| 194 | + assertThat(config.getCall.get()).isEqualTo(config.expected); |
194 | 195 | });
|
195 | 196 |
|
196 | 197 | }
|
|
0 commit comments