@@ -50,14 +50,14 @@ void canBeInstantiated() {
50
50
51
51
@ Test
52
52
void findAvailableTcpPortWithZeroMinPort () {
53
- assertThatIllegalArgumentException ().isThrownBy (() ->
54
- org .springframework .util .SocketUtils .findAvailableTcpPort (0 ));
53
+ assertThatIllegalArgumentException ().isThrownBy (
54
+ () -> org .springframework .util .SocketUtils .findAvailableTcpPort (0 ));
55
55
}
56
56
57
57
@ Test
58
58
void findAvailableTcpPortWithNegativeMinPort () {
59
- assertThatIllegalArgumentException ().isThrownBy (() ->
60
- org .springframework .util .SocketUtils .findAvailableTcpPort (-500 ));
59
+ assertThatIllegalArgumentException ().isThrownBy (
60
+ () -> org .springframework .util .SocketUtils .findAvailableTcpPort (-500 ));
61
61
}
62
62
63
63
@ Test
@@ -80,8 +80,8 @@ void findAvailableTcpPortWhenPortOnLoopbackInterfaceIsNotAvailable() throws Exce
80
80
try (ServerSocket socket = ServerSocketFactory .getDefault ().createServerSocket (port , 1 , InetAddress .getByName ("localhost" ))) {
81
81
assertThat (socket ).isNotNull ();
82
82
// will only look for the exact port
83
- assertThatIllegalStateException ().isThrownBy (() ->
84
- org .springframework .util .SocketUtils .findAvailableTcpPort (port , port ))
83
+ assertThatIllegalStateException ().isThrownBy (
84
+ () -> org .springframework .util .SocketUtils .findAvailableTcpPort (port , port ))
85
85
.withMessageStartingWith ("Could not find an available TCP port" )
86
86
.withMessageEndingWith ("after 1 attempts" );
87
87
}
@@ -123,23 +123,22 @@ void find50AvailableTcpPortsInRange() {
123
123
124
124
@ Test
125
125
void findAvailableTcpPortsWithRequestedNumberGreaterThanSizeOfRange () {
126
- assertThatIllegalArgumentException ().isThrownBy (() ->
127
- findAvailableTcpPorts (50 , 45000 , 45010 ));
126
+ assertThatIllegalArgumentException ().isThrownBy (() -> findAvailableTcpPorts (50 , 45000 , 45010 ));
128
127
}
129
128
130
129
131
130
// UDP
132
131
133
132
@ Test
134
133
void findAvailableUdpPortWithZeroMinPort () {
135
- assertThatIllegalArgumentException ().isThrownBy (() ->
136
- org .springframework .util .SocketUtils .findAvailableUdpPort (0 ));
134
+ assertThatIllegalArgumentException ().isThrownBy (
135
+ () -> org .springframework .util .SocketUtils .findAvailableUdpPort (0 ));
137
136
}
138
137
139
138
@ Test
140
139
void findAvailableUdpPortWithNegativeMinPort () {
141
- assertThatIllegalArgumentException ().isThrownBy (() ->
142
- org .springframework .util .SocketUtils .findAvailableUdpPort (-500 ));
140
+ assertThatIllegalArgumentException ().isThrownBy (
141
+ () -> org .springframework .util .SocketUtils .findAvailableUdpPort (-500 ));
143
142
}
144
143
145
144
@ Test
@@ -155,8 +154,8 @@ void findAvailableUdpPortWhenPortOnLoopbackInterfaceIsNotAvailable() throws Exce
155
154
try (DatagramSocket socket = new DatagramSocket (port , InetAddress .getByName ("localhost" ))) {
156
155
assertThat (socket ).isNotNull ();
157
156
// will only look for the exact port
158
- assertThatIllegalStateException ().isThrownBy (() ->
159
- org .springframework .util .SocketUtils .findAvailableUdpPort (port , port ))
157
+ assertThatIllegalStateException ().isThrownBy (
158
+ () -> org .springframework .util .SocketUtils .findAvailableUdpPort (port , port ))
160
159
.withMessageStartingWith ("Could not find an available UDP port" )
161
160
.withMessageEndingWith ("after 1 attempts" );
162
161
}
@@ -198,8 +197,7 @@ void find50AvailableUdpPortsInRange() {
198
197
199
198
@ Test
200
199
void findAvailableUdpPortsWithRequestedNumberGreaterThanSizeOfRange () {
201
- assertThatIllegalArgumentException ().isThrownBy (() ->
202
- findAvailableUdpPorts (50 , 45000 , 45010 ));
200
+ assertThatIllegalArgumentException ().isThrownBy (() -> findAvailableUdpPorts (50 , 45000 , 45010 ));
203
201
}
204
202
205
203
@@ -226,13 +224,13 @@ private void findAvailableUdpPorts(int numRequested, int minPort, int maxPort) {
226
224
SortedSet <Integer > ports = org .springframework .util .SocketUtils .findAvailableUdpPorts (numRequested , minPort , maxPort );
227
225
assertAvailablePorts (ports , numRequested , minPort , maxPort );
228
226
}
227
+
229
228
private void assertPortInRange (int port , int minPort , int maxPort ) {
230
- assertThat (port >= minPort ).as ("port [" + port + "] >= " + minPort ).isTrue ();
231
- assertThat (port <= maxPort ).as ("port [" + port + "] <= " + maxPort ).isTrue ();
229
+ assertThat (port ).as ("port" ).isBetween (minPort , maxPort );
232
230
}
233
231
234
232
private void assertAvailablePorts (SortedSet <Integer > ports , int numRequested , int minPort , int maxPort ) {
235
- assertThat (ports . size ()) .as ("number of ports requested" ).isEqualTo (numRequested );
233
+ assertThat (ports ) .as ("number of ports requested" ).hasSize (numRequested );
236
234
for (int port : ports ) {
237
235
assertPortInRange (port , minPort , maxPort );
238
236
}
0 commit comments