Skip to content

Commit bfc1251

Browse files
committed
Merge branch '5.3.x'
2 parents fe03654 + 8e64701 commit bfc1251

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

framework-docs/src/docs/asciidoc/testing.adoc

+28-13
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,20 @@ categories:
142142
The `org.springframework.test.util` package contains several general purpose utilities
143143
for use in unit and integration testing.
144144

145-
`ReflectionTestUtils` is a collection of reflection-based utility methods. You can use
146-
these methods in testing scenarios where you need to change the value of a constant, set
147-
a non-`public` field, invoke a non-`public` setter method, or invoke a non-`public`
148-
configuration or lifecycle callback method when testing application code for use cases
149-
such as the following:
145+
{api-spring-framework}/test/util/AopTestUtils.html[`AopTestUtils`] is a collection of
146+
AOP-related utility methods. You can use these methods to obtain a reference to the
147+
underlying target object hidden behind one or more Spring proxies. For example, if you
148+
have configured a bean as a dynamic mock by using a library such as EasyMock or Mockito,
149+
and the mock is wrapped in a Spring proxy, you may need direct access to the underlying
150+
mock to configure expectations on it and perform verifications. For Spring's core AOP
151+
utilities, see {api-spring-framework}/aop/support/AopUtils.html[`AopUtils`] and
152+
{api-spring-framework}/aop/framework/AopProxyUtils.html[`AopProxyUtils`].
153+
154+
{api-spring-framework}/test/util/ReflectionTestUtils.html[`ReflectionTestUtils`] is a
155+
collection of reflection-based utility methods. You can use these methods in testing
156+
scenarios where you need to change the value of a constant, set a non-`public` field,
157+
invoke a non-`public` setter method, or invoke a non-`public` configuration or lifecycle
158+
callback method when testing application code for use cases such as the following:
150159

151160
* ORM frameworks (such as JPA and Hibernate) that condone `private` or `protected` field
152161
access as opposed to `public` setter methods for properties in a domain entity.
@@ -156,14 +165,20 @@ such as the following:
156165
* Use of annotations such as `@PostConstruct` and `@PreDestroy` for lifecycle callback
157166
methods.
158167

159-
{api-spring-framework}/test/util/AopTestUtils.html[`AopTestUtils`] is a collection of
160-
AOP-related utility methods. You can use these methods to obtain a reference to the
161-
underlying target object hidden behind one or more Spring proxies. For example, if you
162-
have configured a bean as a dynamic mock by using a library such as EasyMock or Mockito,
163-
and the mock is wrapped in a Spring proxy, you may need direct access to the underlying
164-
mock to configure expectations on it and perform verifications. For Spring's core AOP
165-
utilities, see {api-spring-framework}/aop/support/AopUtils.html[`AopUtils`] and
166-
{api-spring-framework}/aop/framework/AopProxyUtils.html[`AopProxyUtils`].
168+
{api-spring-framework}/test/util/TestSocketUtils.html[`TestSocketUtils`] is a simple
169+
utility for finding available TCP ports on `localhost` for use in integration testing
170+
scenarios.
171+
172+
[NOTE]
173+
====
174+
`TestSocketUtils` can be used in integration tests which start an external server on an
175+
available random port. However, these utilities make no guarantee about the subsequent
176+
availability of a given port and are therefore unreliable. Instead of using
177+
`TestSocketUtils` to find an available local port for a server, it is recommended that
178+
you rely on a server's ability to start on a random ephemeral port that it selects or is
179+
assigned by the operating system. To interact with that server, you should query the
180+
server for the port it is currently using.
181+
====
167182

168183

169184
[[unit-testing-spring-mvc]]

spring-test/src/main/java/org/springframework/test/util/TestSocketUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class TestSocketUtils {
7373
/**
7474
* Although {@code TestSocketUtils} consists solely of static utility methods,
7575
* this constructor is intentionally {@code public}.
76-
* <h4>Rationale</h4>
76+
* <h5>Rationale</h5>
7777
* <p>Static methods from this class may be invoked from within XML
7878
* configuration files using the Spring Expression Language (SpEL) and the
7979
* following syntax.

0 commit comments

Comments
 (0)