Compare commits

..

105 Commits

Author SHA1 Message Date
Spring Builds 3bea4682b7 Release v6.0.8 2023-04-13 08:23:33 +00:00
Sam Brannen be17c8d85f Disable variable assignment in SimpleEvaluationContext
This commit introduces infrastructure to differentiate between
programmatic setting of a variable in an EvaluationContext versus the
assignment of a variable within a SpEL expression using the assignment
operator (=). In addition, this commit disables variable assignment
within expressions when using the SimpleEvaluationContext.

Closes gh-30326
2023-04-13 09:40:23 +02:00
Sam Brannen b73f5fcac2 Limit SpEL expression length
This commit enforces a limit of the maximum size of a single SpEL
expression.

Closes gh-30325
2023-04-13 09:39:53 +02:00
Sam Brannen bc1511d667 Limit string concatenation in SpEL expressions
This commit introduces support for limiting the maximum length of a
string resulting from the concatenation operator (+) in SpEL
expressions.

Closes gh-30324
2023-04-13 09:39:32 +02:00
Sam Brannen db9b139cf0 Change max regex length in SpEL expressions to 1000
This commit changes the max regex length in SpEL expressions from 1024
to 1000 in order to consistently use "round" numbers for recently
introduced limits.

See gh-30265
2023-04-13 09:39:27 +02:00
rstoyanchev bd029b9218 Ensure RestClientResponseException is serializable
Closes gh-30224
2023-04-12 15:38:27 +01:00
rstoyanchev 5f2264816a Polishing contribution
Closes gh-30294
2023-04-12 15:22:57 +01:00
Yanming Zhou a8f31f5b9e Improve ProblemDetail equals and hashCode
Lazy computed title property should be taken into account

See gh-30294
2023-04-12 15:07:22 +01:00
Stephane Nicoll 90627b4345 Upgrade to Micrometer 1.10.6
Closes gh-30317
2023-04-12 14:45:54 +02:00
Juergen Hoeller 4acc71b282 Upgrade to Reactor 2022.0.6 and Netty 4.1.91
Includes Checkstyle 10.9.3 and Mockito 5.3.0

Closes gh-30316
2023-04-12 13:36:01 +02:00
kyuarl21 cd0379a67f Modified to slf4j2-impl in build.gradle
due to slf4j-api versions 1.7 x or earlier issue
2023-04-12 13:11:48 +02:00
Simon Baslé e262e98bab ConstructorResolver error hints about mixing indexed and named args
This commit adds a note to an exception in `ConstructorResolver`'s
`autowireConstructor` method hinting that attention should be paid to
cases that mix indexed arguments and named arguments. This is especially
when inheriting bean definitions in xml.

Closes gh-29976
Close gh-PR
2023-04-12 13:09:28 +02:00
SW 59c65fa940 Replace Collections.unmodifiableList(new ArrayList(..)) with List.copyOf() (#30166) 2023-04-12 13:07:20 +02:00
Stephane Nicoll 695601aa06 Merge pull request #30308 from izeye
* pr/30308:
  Add since tags to sameSite() and attribute() in CookieResultMatchersDsl

Closes gh-30308
2023-04-11 14:57:13 +02:00
Johnny Lim 8f5a1fe7e2 Add since tags to sameSite() and attribute() in CookieResultMatchersDsl
See gh-30308
2023-04-11 14:56:55 +02:00
rstoyanchev 073226d792 Polishing contribution
Closes gh-30120
2023-04-11 11:43:24 +01:00
Aleksandrs Jansons 1abe155663 Ensure WebSocket disconnect msg reaches the client
In some application setups, the WebSocket server does not transmit
the disconnect message to the client, so that the client has no idea
that the established connection has been terminated.

This issue arises when the application uses SimpleBrokerMessageHandler
and the error handler is set to the instance of
StompSubProtocolErrorHandler or an extended class that does not
override the handleErrorMessageToClient method.

The commit fixes disconnect message population so that
`java.lang.IllegalArgumentException: No StompHeaderAccessor` exception
is not thrown in the handleErrorMessageToClient method in
StompSubProtocolErrorHandler class.

See gh-30120
2023-04-11 11:43:23 +01:00
divcon 33ef9107e0 Minor refactoring in PayloadMethodArgumentResolver
Closes gh-30168
2023-04-11 11:36:41 +01:00
rstoyanchev 8463eade33 Polishing contribution
Closes gh-30192
2023-04-10 21:24:25 +01:00
James Yuzawa e77faf7484 Improve performance of canRead() in HttpMessageReader's
Use MimeType.WILDCARD_TYPE for faster String.equals().
Move cheaper checks to the front of the canRead implementations.

See gh-30192
2023-03-25 12:21:10 -04:00
Sam Brannen b23cc01cb7 Revise "Ignore nonexistent default-destroy-method in XML config"
This commit revises the fix in c811428512.

Closes gh-30301
2023-04-07 18:48:52 +02:00
Brian Clozel 01f97887ea Improve WebClient observations handling of CANCEL signal
Prior to this commit, `WebClient` observations would be recorded as
aborted (with tags "outcome":"UNKNOWN", "status":"CLIENT_ERROR")
for use cases like this:

```
Flux<String> result = client.get()
    .uri("/path")
    .retrieve()
    .bodyToFlux(String.class)
    .take(1);
```

This is due to operators like `take` or `next` that consume *some*
`onNext` signals and then cancels the subscription before completion.
This means the subscriber is only partially interested in the response
and we should not count this as a client error.

This commit ensures that observations are only recorded as aborted if
the response was not published at the time the CANCEL signal was
received.

The code snippet above will now publish observations with
"outcome":"SUCCESS" and "status":"200" tags, for example.

Closes gh-30070
2023-04-07 16:37:09 +02:00
Sam Brannen cef597bedd Update copyright headers 2023-04-07 14:24:22 +02:00
Sam Brannen 01fabfe66d Suppress warnings in tests 2023-04-07 14:23:55 +02:00
Sam Brannen c811428512 Ignore nonexistent default-destroy-method in XML config
Prior to this commit, DisposableBeanAdapter attempted to invoke a
configured default-destroy-method on every bean, including beans that
do not declare the named destroy method, resulting in a
NullPointerException being thrown and logged at WARN level.

This commit addresses this by effectively ignoring any nonexistent
destroy method.

Closes gh-30301
2023-04-07 13:58:49 +02:00
Sébastien Deleuze b5b115e52c Fix SSE with indenting serializer in WebMvc.fn
This commit ensures that HTTP headers like "text/event-stream"
are correctly forwarded to the converter used in
SseServerResponse for proper pretty print handling.

Close gh-30277
2023-04-07 11:25:47 +02:00
Sam Brannen 310344cf61 Increase max regex length in SpEL expressions
This commit increases the max regex length in SpEL expressions from 256
to 1024 in order to support use cases where a regex may be rather long
without necessarily increasing the complexity of the regex.

Closes gh-30265
2023-04-06 17:53:03 +02:00
Sam Brannen 2bac371c5b Improve Javadoc for ObjectUtils.nullSafeConciseToString() 2023-04-06 17:35:50 +02:00
Arjen Poutsma cef9166833 Encode IPV6 Zone IDs in ReactorServerHttpRequest
This commit ensures that the zone id in the ReactorServerHttpRequest is
properly encoded.

Closes gh-30188
2023-04-06 11:32:44 +02:00
Simon Baslé d6460e0d57 Add Cookie attributes + SameSite CookieResultMatchers in MockMvc
This commit adds assertions to MockMvc's CookieresultMatchers:
 - `attribute` for arbitrary attributes
 - `sameSite` for the SameSite well-known attribute

Note that the `sameSite` methods delegate to their `attribute`
counterparts. Note also that Jakarta's `Cookie#getAttribute` method is
case-insensitive, which is reflected in the documentation of the
`attribute` assertion method and the tests.

Closes gh-30285
2023-04-05 17:02:38 +02:00
Sam Brannen 842490beeb Add tests for corner cases
See gh-30290
See gh-30286
2023-04-05 15:05:25 +02:00
Sam Brannen e746230de6 Introduce ObjectUtils.nullSafeConciseToString()
ObjectUtils.nullSafeToString(Object) exists for generating a string
representation of various objects in a "null-safe" manner, including
support for object graphs, collections, etc.

However, there are times when we would like to generate a "concise",
null-safe string representation that does not include an entire object
graph (or potentially a collection of object graphs).

This commit introduces ObjectUtils.nullSafeConciseToString(Object) to
address this need and makes use of the new feature in FieldError and
ConversionFailedException.

Closes gh-30286
2023-04-05 14:13:28 +02:00
Sam Brannen 8161316b1d Introduce StringUtils.truncate()
StringUtils.truncate() serves as central, consistent way for truncating
strings used in log messages and exception failure messages, for
immediate use in LogFormatUtils and ObjectUtils.

See gh-30286
Closes gh-30290
2023-04-05 13:50:13 +02:00
Krzysztof Krasoń 1734deca1e Refactor AssertJ assertions into more idiomatic ones
This commit refactors some AssertJ assertions into more idiomatic and
readable ones. Using the dedicated assertion instead of a generic one
will produce more meaningful error messages. 

For instance, consider collection size:
```
// expected: 5 but was: 2
assertThat(collection.size()).equals(5);
// Expected size: 5 but was: 2 in: [1, 2]
assertThat(collection).hasSize(5);
```

Closes gh-30104
2023-04-04 17:34:07 +02:00
Justin Tay dd97ee4e99 Support SameSite cookie attribute in MockMvcHttpConnector
Closes gh-30264
2023-04-04 16:57:21 +02:00
Simon Baslé 90b0f451f0 Add a couple missing java.time types to StatementCreatorUtils
This commit adds mapping for two types from the `java.time` package,
complementing the types that are already translatable to Sql types
TIME, DATE and TIMESTAMP:
 - `OffsetTime` maps to a `TIME_WITH_TIMEZONE`
 - `OffsetDateTime` maps to a `TIMESTAMP_WITH_TIMEZONE`

This is in accordance with the B.4 table provided in the JDBC 4.2
specification.

When preparing statements, these `java.time` types use the `setObject`
method. Tests covering the 5 `java.time` classes have also been added.

See gh-28778
See gh-28527
Closes gh-30123
2023-04-04 16:51:24 +02:00
Sam Brannen 9fb61c57ae Sync MockCookie implementations
See gh-30263
2023-04-04 16:32:30 +02:00
Sam Brannen f9cb0eba87 Update Javadoc regarding Servlet 6 baseline for mocks 2023-04-04 16:29:51 +02:00
Sam Brannen d1d2d5943e Polish contribution
See gh-30263
2023-04-04 16:29:03 +02:00
Justin Tay 281736f14e Update MockCookie to use Servlet 6.0 APIs and semantics for "attributes"
Closes gh-30263
2023-04-04 16:13:37 +02:00
Sam Brannen 6bfc70b61e Polishing 2023-04-04 16:02:54 +02:00
Simon Baslé 95883b9eb7 Rename MockMVC matcher methods to prevent regression in user tests
This commit changes the name of two recently introduced methods in the
`MockRestRequestMatchers` class for header and queryParam. These have
been found to cause false negatives in user tests, due to the new
overload taking precedence in some cases.

Namely, using a `Matcher` factory method which can apply to both `List`
and `String` will cause the compiler to select the newest list overload,
by instantiating a `Matcher<Object>`.

This can cause false negatives in user tests, failing tests that used
to pass because the Matcher previously applied to the first String in
the header or queryParam value list. For instance, `equalsTo("a")`.

The new overloads are recent enough and this has enough potential to
cause an arbitrary number of user tests to fail that we break the API
to eliminate the ambiguity, by renaming the methods with a `*List`
suffix.

Closes gh-30220
Closes gh-30238
See gh-29953
See gh-28660
2023-04-04 15:06:14 +02:00
Arjen Poutsma f0eb43a6af Merge pull request #30157 from srivatsa-cfp:main
* gh-30157:
  Add non-null assertions in DefaultServerResponseBuilder
2023-04-04 12:42:39 +02:00
Vatsa 6c8ebc7f7e Add non-null assertions in DefaultServerResponseBuilder
This commit adds various non-null assertions to
DefaultServerResponseBuilder, in both Spring MVC and WebFlux.

Closes gh-30157
2023-04-04 12:36:46 +02:00
Sam Brannen 69c8f8e9c7 Update copyright headers 2023-04-03 16:45:49 +02:00
Sam Brannen 02f2d94f57 Polish contribution
See gh-30271
2023-04-03 16:45:49 +02:00
wizard 7fcbc869a6 Specify initial capacity when creating ArrayList in SpringFactoriesLoader
Closes gh-30271
2023-04-03 16:42:00 +02:00
Sam Brannen 4eed2ced74 Polishing 2023-04-03 14:42:38 +02:00
Sébastien Deleuze 98f1287f3a Fix HttpServiceMethod support for suspending functions
This commit fixes nested type handling for suspending
functions in HttpServiceMethod.

Closes gh-30266
2023-04-03 10:30:49 +02:00
Brian Clozel 8234fa2a13 Fix JDK20 env variable declaration in CI pipeline
See gh-30185
2023-04-03 09:43:37 +02:00
Filip Blondeel 8b9d2e3f95 Fix incorrect jakarta.inject artifact version
Closes gh-30270
2023-04-03 09:36:22 +02:00
hongxue.zou 534d1cd35b Polishing
This commit includes a null-safety fix in
HttpComponentsHeadersAdapter.

Closes gh-30267
2023-04-03 09:04:39 +02:00
Sam Brannen ca545ac3d4 Upgrade dependencies 2023-04-02 19:20:49 +02:00
Sam Brannen ca7c2779bf Suppress warnings displayed in Gradle build for test source code 2023-04-01 18:36:56 +02:00
Sam Brannen 4a90257a84 Upgrade to Gradle 8
This commit upgrades the build to use Gradle 8.0.2 and Dokka 1.8.10.

Closes gh-30000
2023-04-01 18:36:28 +02:00
Sam Brannen 49a4ed2ffa Improve Javadoc for @PropertySource 2023-04-01 18:15:19 +02:00
Sam Brannen 717d03a29d Fix grammar 2023-04-01 18:15:19 +02:00
1993heqiang 2b427efe7f Fix PathVariable reference documentation code snippets
Closes gh-30243
2023-03-31 15:51:56 +02:00
Sam Brannen 3632bea51e Polishing 2023-03-31 13:52:05 +02:00
Brian Clozel 1efa162cf0 WebClient defaultStatusHandler do not apply to exchangeTo*
This commit documents the fact that default status handlers configured
on the `WebClient` are not applied to `exchangeTo*` methods as those
variants give full access to the client response.

Applying them here would restrict the ability to adapt the behavior
depending on the HTTP response status.

Closes gh-30059
2023-03-31 11:19:40 +02:00
Harry Yang a8b7a5e037 Refine initRequestBuilder in DefaultWebClient
Closes gh-30254
2023-03-31 10:53:51 +02:00
Sébastien Deleuze 807325916f Add class hints for Jackson annotations on fields and methods
Before this commit, only class level annotations were
processed.

Closes gh-30208
2023-03-31 10:39:18 +02:00
Brian Clozel d451d6adcc Ensure that client responses are observed when filters fail
Prior to this commit, an error thrown by a `ExchangeFilterFunction`
configured on a `WebClient` instance would be recorded as such by the
client observation, but the response details would be missing from the
observation.
All filter functions and the exchange function (performing the HTTP
call) would be merged into a single `ExchangeFunction`; this instance
was instrumented and osberved. As a result, the instrumentation would
only get the error signal returned by the filter function and would not
see the HTTP response even if it was received. This means that the
recorded observation would not have the relevant information for the
HTTP status.

This commit ensures that between the configured `ExchangeFilterFunction`
and the `ExchangeFunction`, an instrumentation `ExchangeFilterFunction`
is inserted. This allows to set the client response to the observation
context, even if a later error signal is thrown by a filter function.

Note that with this change, an error signal sent by a filter function
will be still recorded in the observation.

See gh-30059
2023-03-30 20:04:48 +02:00
Juergen Hoeller 8fca258207 Propagate HttpStreamResetException itself if cause is null
Closes gh-30245
2023-03-30 19:22:30 +02:00
Sébastien Deleuze d126b99c91 Refine generic type management in AbstractMessageWriterResultHandler
This commit updates AbstractMessageWriterResultHandler#writeBody in
order to use the declared bodyParameter instead of
ResolvableType.forInstance(body) when the former has unresolvable
generics.

Closes gh-30214
2023-03-30 18:07:01 +02:00
Sébastien Deleuze c5f0f7bb11 Refine DisposableBeanAdapter method discovery for native
After this commit, DisposableBeanAdapter can find destruction related methods
even when hints are just specified at interface level, which is typically the
case when a bean is exposed via one of its interfaces.

Closes gh-29545
2023-03-30 15:28:50 +02:00
Brian Clozel 3a36d51473 Polish
See gh-29246
2023-03-30 14:49:11 +02:00
Brian Clozel fe6589d5af Add runtime hint test for inherited destroy methods
This commit ensures that init/destroy methods that are provided as
default methods from interfaces are properly covered by runtime hints at
runtime.

Closes gh-29246
2023-03-30 14:42:19 +02:00
Brian Clozel b374824319 Contribute introspection hints on registered beans
Prior to this commit, reflection hints registered for beans was
selectively applied to only consider the methods that we'll actually
need reflection on at runtime. This would rely on an undocumented
behavior of GraalVM Native where calling `getDeclaredMethods` on a type
would only return known metadata at runtime, ignoring the ones that were
not registered during native compilation.

As of oracle/graal#5171, this behavior is now fixed in GraalVM and
aligns with the JVM behavior: all methods will be returned. This means
that if during native compilation, introspection was not registered for
the type a new `MissingReflectionMetadataException` will be raised.

As a follow up of #29205, this commit contributes the "introspection on
declared method" reflection hint for all registered beans.

Closes gh-29246
2023-03-29 21:16:59 +02:00
Juergen Hoeller 7e905e3e00 Use JdkDynamicAopProxy class loader instead of JDK bootstrap/platform loader
Closes gh-30115
2023-03-29 13:46:29 +02:00
Juergen Hoeller 491ae1e3be Use MethodInvocationInfo class loader in case of JDK platform loader as well
Closes gh-30210
2023-03-29 13:46:18 +02:00
Brian Clozel 66cdf43b56 Polish
Closes gh-30223
2023-03-29 10:55:48 +02:00
James Yuzawa 2ba206f8ba Order metric labels in ObservationConventions
See gh-30223
2023-03-29 10:55:34 +02:00
James Yuzawa 5ba6944145 Remove String.formatter from DefaultServerRequestObservationConvention
Closes gh-30218
2023-03-28 20:24:55 +02:00
Arjen Poutsma 5609e67100 Improve Javadoc of MultipartBodyBuilder
This commit improves the Javadoc of MultipartBodyBuilder, to make it
clear that it is intended for multipart/form-data.

See gh-30179
2023-03-28 14:04:09 +02:00
Juergen Hoeller b2be07c73c Polishing 2023-03-28 13:26:29 +02:00
Juergen Hoeller ce2689eead Use MethodInvocationInfo class loader in case of core JDK interface type
Closes gh-30210
2023-03-28 13:20:49 +02:00
Johnny Lim 2184d4e80e Fix incomplete assertions
Closes gh-30209
2023-03-28 10:56:41 +02:00
Ed .d 50d01ce405 feat: Add support for Vavr's Try monad to trigger transaction rollbacks
Updated the Spring Framework documentation to include an example of using Vavr's Try monad to trigger transaction rollbacks when a @Transactional-annotated method returns a Failure. The modified documentation demonstrates how to use Try in a transactional method and how to check if an exception has been wrapped inside a Try.Failure instance. Additionally, a link to the official Vavr documentation was added to provide more information on the Try method.
2023-03-28 10:38:03 +02:00
Sam Brannen 0c0cda9815 Polish contribution
See gh-30189
2023-03-27 19:31:35 +02:00
Harry Yang 47aca90c58 Optimize array creation in SpEL ConstructorReference
- Create primitive arrays directly instead of using Array#newInstance.

- Replace if-else blocks with enhanced switch statement.

Closes gh-30189
2023-03-27 19:31:35 +02:00
Sam Brannen ddd6b123bb Polish TypeCode 2023-03-27 19:31:35 +02:00
heqiang ec270c7135 Use diamond operator in examples in reference manual
Closes gh-30204
2023-03-27 18:27:29 +02:00
Sébastien Deleuze 7cc72ddf7a Add HttpMethod reflection hint to ObjectToObjectConverterRuntimeHints
This commit adds a reflection hint for HttpMethod#valueOf in order
to be able to support conversion required for Spring Boot
configuration properties binding as described in
https://github.com/spring-projects/spring-boot/issues/34483.

Closes gh-30201
2023-03-27 15:13:15 +02:00
Sam Brannen 5f0ee2e4dd Polish ConstructorReference 2023-03-25 17:40:00 +01:00
Johnny Lim 43031509c8 Update versions in Javadoc
Closes gh-30170
2023-03-25 17:13:36 +01:00
ghostg00 e66c80667f Fix example in Javadoc for @EnableWebSocket
The `echoWebSocketHandler()` method is not defined in the
`WebSocketConfigurer` interface and should therefore be annotated with
`@Bean` instead of `@Override`.

Closes gh-30183
2023-03-24 17:54:33 +01:00
Sam Brannen 84714fbae9 Allow JDK 20 builds to pass by using legacy locale data
After setting up a JDK 20 CI build pipeline, numerous tests involving
date/time parsing and formatting began to fail [0]. (The failing JPA
tests are not specific to JDK 20.)

For example, we encounter visually confusing assertion failures such as
the following.

org.opentest4j.AssertionFailedError:
	expected: "12:00 PM"
	but was:  "12:00 PM"

The expected string contains a normal space (which has always been the
case prior to JDK 20); whereas, the actual string now contains a narrow
non-breaking space.

The cause of this is mentioned in the JDK 20 Release Notes [1] as "NBSP
prefixed to a, instead of a normal space". Note, however, that the
links for the first two bullet points in that section are mixed up.
"NBSP prefixed to a, instead of a normal space" should point to [2].
Furthermore, the new whitespace character is not a non-breaking space
(NBSP) but rather a narrow non-breaking space (NNBSP). In addition, the
second bullet point should technically read "NNBSP prefixed to `a`,
instead of a normal space" -- even though `a` provides limited value to
most readers.

The downside for the Java community is that this constitutes a breaking
change for parsing and formatting date/time values that include "AM"
and "PM" units (any may potentially apply to other date/time
parsing/formatting scenarios). In Spring Framework's test suite we have
witnessed this in conjunction with Spring's @DateTimeFormat and
DateTimeFormatterFactory infrastructure as well as with Google's
Gson-to-JSON support.

A colleague who works at Oracle graciously informed me that one can use
"legacy locale data" by supplying `-Djava.locale.providers=COMPAT` as a
JVM argument, noting however that this option limits some newer
functionalities (but without enumerating which new functionalities one
might be missing when using this option).

In any case, this commit adds that JVM argument to our Gradle toolchain
builds so that our test suite passes on JDK 20, and we will continue to
investigate further options for our builds and for our users.

Note, however, that one must manually configure the
`-Djava.locale.providers=COMPAT` JVM argument when running affected
tests within an IDE.

See gh-30185

[0] https://ge.spring.io/s/kmiq2bz2afafs/tests/overview?outcome=failed
[1] https://jdk.java.net/20/release-notes#JDK-8284840
[2] https://unicode-org.atlassian.net/browse/CLDR-14032
2023-03-24 16:08:38 +01:00
Sam Brannen 0ca02ce677 Disable affected tests on Java 18+/19+
See gh-30185
2023-03-24 16:05:40 +01:00
Sam Brannen db29b65399 Polishing 2023-03-24 16:05:40 +01:00
Sam Brannen 18adf905a8 Polishing 2023-03-23 17:04:41 +01:00
Sam Brannen ce9a72f95c Update copyright headers 2023-03-23 16:56:20 +01:00
Sam Brannen dfb4a951ae Suppress deprecation warnings instead of deprecating tests 2023-03-23 16:55:12 +01:00
Brian Clozel d9776941bf Update Java version for compatibility tests in CI
This commit configures Java 20 for compatibility tests in our CI,
replacing Java 19.
2023-03-23 15:47:06 +01:00
Giuseppe 24b359d519 Handle all exceptions for stored proc out param retrieval in SharedEntityManagerCreator
Prior to this commit, the EntityManager was not closed in
SharedEntityManagerCreator.DeferredQueryInvocationHandler's
invoke(Object, Method, Object[]) method if an invocation of
getOutputParameterValue(*) threw an exception other than
IllegalArgumentException, which could lead to a connection leak.

This commit addresses this by catching RuntimeException instead of
IllegalArgumentException.

Closes gh-30161
2023-03-22 15:39:53 +01:00
Arjen Poutsma ae70bf7c38 Merge pull request #30138 from yuzawa-san:LiteralPathElement-string-equals
* gh-30138:
  Polish external contribution
  Use String.equals() in LiteralPathElement
2023-03-22 12:13:45 +01:00
Arjen Poutsma c68e986b75 Polish external contribution
This commit removes the text char[] in favor of the text String
introduced through the PR.

Closes gh-30138
2023-03-22 12:10:18 +01:00
James Yuzawa 2bc1aa7827 Use String.equals() in LiteralPathElement 2023-03-22 12:10:18 +01:00
Kukri 570d21ebbd Fix anchor in link to "Web on Reactive Stack" chapter
Closes gh-30158
2023-03-22 11:30:35 +01:00
James Yuzawa 800b13492b Optimize some iterations in BodyExtractor and BodyInserter
This commit turns some stream-based iterations back into simpler
enhanced for loops.

For simple use cases like these, where the stream API is merely used to
map/filter + collect to a List, a for loop is more efficient.
This is especially true for small collections like the ones we deal
with in BodyInserters/BodyExtractors here (in the order of 50ns/op vs
5ns/op). These cases are also simple enough that they don't lose in
readability after the conversion.

Closes gh-30136
2023-03-22 11:04:54 +01:00
Сергей Цыпанов 4e896c8125 Use InputStream.readAllBytes() in FileCopyUtils.copyToByteArray()
InputStream.readAllBytes() allows us to avoid the creation of an
intermediate ByteArrayOutputStream and is likely to perform better.

Closes gh-30155
2023-03-21 15:37:26 +01:00
Arjen Poutsma 9421fe1d75 Merge pull request #30139 from yuzawa-san:cache-reactor-request-methods
* gh-30139:
  Cache ServerHttpRequest::getMethod in AbstractServerHttpRequest
  cache reactor request methods
2023-03-21 11:36:11 +01:00
Arjen Poutsma 37a4e84450 Cache ServerHttpRequest::getMethod in AbstractServerHttpRequest
This commit ensures that the HttpMethod, exposed through
ServerHttpRequest::getMethod, is cached in AbstractServerHttpRequest so
that potentially expensive HTTP method lookups are only done once.

Closes gh-30139
2023-03-21 11:29:32 +01:00
James Yuzawa c27a5687dc cache reactor request methods 2023-03-21 09:39:04 +01:00
Spring Builds 4e8162c6dd Next development version (v6.0.8-SNAPSHOT) 2023-03-20 09:53:24 +00:00
522 changed files with 5872 additions and 4226 deletions
+9 -9
View File
@@ -1,16 +1,16 @@
plugins {
id 'io.spring.nohttp' version '0.0.11'
id 'io.freefair.aspectj' version '6.5.0.3' apply false
id 'io.freefair.aspectj' version '8.0.1' apply false
// kotlinVersion is managed in gradle.properties
id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false
id 'org.jetbrains.dokka' version '1.7.20'
id 'org.jetbrains.dokka' version '1.8.10'
id 'org.asciidoctor.jvm.convert' version '3.3.2' apply false
id 'org.asciidoctor.jvm.pdf' version '3.3.2' apply false
id 'org.unbroken-dome.xjc' version '2.0.0' apply false
id 'com.github.ben-manes.versions' version '0.42.0'
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'de.undercouch.download' version '5.1.0'
id 'me.champeau.jmh' version '0.6.8' apply false
id 'com.github.ben-manes.versions' version '0.46.0'
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'de.undercouch.download' version '5.4.0'
id 'me.champeau.jmh' version '0.7.0' apply false
}
ext {
@@ -78,7 +78,7 @@ configure([rootProject] + javaProjects) { project ->
}
checkstyle {
toolVersion = "10.9.1"
toolVersion = "10.9.3"
configDirectory.set(rootProject.file("src/checkstyle"))
}
@@ -105,11 +105,11 @@ configure([rootProject] + javaProjects) { project ->
testRuntimeOnly("org.junit.platform:junit-platform-suite-engine")
testRuntimeOnly("org.apache.logging.log4j:log4j-core")
testRuntimeOnly("org.apache.logging.log4j:log4j-jul")
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl")
// JSR-305 only used for non-required meta-annotations
compileOnly("com.google.code.findbugs:jsr305")
testCompileOnly("com.google.code.findbugs:jsr305")
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.31")
checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.38")
}
ext.javadocLinks = [
@@ -26,8 +26,8 @@ import org.gradle.testretry.TestRetryTaskExtension;
* Conventions that are applied in the presence of the {@link JavaBasePlugin}. When the
* plugin is applied:
* <ul>
* <li>The {@link TestRetryPlugin Test Retry} plugins is applied so that flaky tests
* are retried 3 times when running on the CI.
* <li>The {@link TestRetryPlugin Test Retry} plugin is applied so that flaky tests
* are retried 3 times when running on the CI server.
* </ul>
*
* @author Brian Clozel
@@ -41,7 +41,7 @@ class TestConventions {
private void configureTestConventions(Project project) {
project.getTasks().withType(Test.class,
(test) -> project.getPlugins().withType(TestRetryPlugin.class, (testRetryPlugin) -> {
test -> project.getPlugins().withType(TestRetryPlugin.class, testRetryPlugin -> {
TestRetryTaskExtension testRetry = test.getExtensions().getByType(TestRetryTaskExtension.class);
testRetry.getFailOnPassedAfterRetry().set(true);
testRetry.getMaxRetries().set(isCi() ? 3 : 0);
+1 -1
View File
@@ -6,6 +6,6 @@ RUN ./setup.sh
ENV JAVA_HOME /opt/openjdk/java17
ENV JDK17 /opt/openjdk/java17
ENV JDK19 /opt/openjdk/java19
ENV JDK20 /opt/openjdk/java20
ENV PATH $JAVA_HOME/bin:$PATH
+2 -2
View File
@@ -5,8 +5,8 @@ case "$1" in
java17)
echo "https://github.com/bell-sw/Liberica/releases/download/17.0.6+10/bellsoft-jdk17.0.6+10-linux-amd64.tar.gz"
;;
java19)
echo "https://github.com/bell-sw/Liberica/releases/download/19.0.2+9/bellsoft-jdk19.0.2+9-linux-amd64.tar.gz"
java20)
echo "https://github.com/bell-sw/Liberica/releases/download/20%2B37/bellsoft-jdk20+37-linux-amd64.tar.gz"
;;
*)
echo $"Unknown java version"
+1 -1
View File
@@ -20,7 +20,7 @@ curl https://raw.githubusercontent.com/spring-io/concourse-java-scripts/v0.0.4/c
mkdir -p /opt/openjdk
pushd /opt/openjdk > /dev/null
for jdk in java17 java19
for jdk in java17 java20
do
JDK_URL=$( /get-jdk-url.sh $jdk )
mkdir $jdk
+8 -8
View File
@@ -127,14 +127,14 @@ resources:
access_token: ((github-ci-status-token))
branch: ((branch))
context: build
- name: repo-status-jdk19-build
- name: repo-status-jdk20-build
type: github-status-resource
icon: eye-check-outline
source:
repository: ((github-repo-name))
access_token: ((github-ci-status-token))
branch: ((branch))
context: jdk19-build
context: jdk20-build
- name: slack-alert
type: slack-notification
icon: slack
@@ -231,7 +231,7 @@ jobs:
"zip.type": "schema"
get_params:
threads: 8
- name: jdk19-build
- name: jdk20-build
serial: true
public: true
plan:
@@ -239,7 +239,7 @@ jobs:
- get: git-repo
- get: every-morning
trigger: true
- put: repo-status-jdk19-build
- put: repo-status-jdk20-build
params: { state: "pending", commit: "git-repo" }
- do:
- task: check-project
@@ -248,16 +248,16 @@ jobs:
privileged: true
timeout: ((task-timeout))
params:
TEST_TOOLCHAIN: 19
TEST_TOOLCHAIN: 20
<<: *build-project-task-params
on_failure:
do:
- put: repo-status-jdk19-build
- put: repo-status-jdk20-build
params: { state: "failure", commit: "git-repo" }
- put: slack-alert
params:
<<: *slack-fail-params
- put: repo-status-jdk19-build
- put: repo-status-jdk20-build
params: { state: "success", commit: "git-repo" }
- name: build-pull-requests
serial: true
@@ -441,7 +441,7 @@ jobs:
groups:
- name: "builds"
jobs: ["build", "jdk19-build"]
jobs: ["build", "jdk20-build"]
- name: "releases"
jobs: ["stage-milestone", "stage-rc", "stage-release", "promote-milestone", "promote-rc", "promote-release", "create-github-release"]
- name: "ci-images"
+1 -1
View File
@@ -4,6 +4,6 @@ set -e
source $(dirname $0)/common.sh
pushd git-repo > /dev/null
./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false -Porg.gradle.java.installations.fromEnv=JDK17,JDK19 \
./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false -Porg.gradle.java.installations.fromEnv=JDK17,JDK20 \
-PmainToolchain=${MAIN_TOOLCHAIN} -PtestToolchain=${TEST_TOOLCHAIN} --no-daemon --max-workers=4 check
popd > /dev/null
@@ -1300,7 +1300,7 @@ listing shows our custom `BeanDefinitionParser` implementation:
}
private static void parseChildComponents(List<Element> childElements, BeanDefinitionBuilder factory) {
ManagedList<BeanDefinition> children = new ManagedList<BeanDefinition>(childElements.size());
ManagedList<BeanDefinition> children = new ManagedList<>(childElements.size());
for (Element element : childElements) {
children.add(parseComponentElement(element));
}
@@ -7189,7 +7189,7 @@ You can add the following dependency to your file pom.xml:
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>1</version>
<version>2.0.0</version>
</dependency>
----
=====
@@ -293,7 +293,7 @@ being placed in it. The following example shows how to do so:
.Java
----
class Simple {
public List<Boolean> booleanList = new ArrayList<Boolean>();
public List<Boolean> booleanList = new ArrayList<>();
}
Simple simple = new Simple();
@@ -1478,7 +1478,7 @@ show how to use the `#this` and `#root` variables:
.Java
----
// create an array of integers
List<Integer> primes = new ArrayList<Integer>();
List<Integer> primes = new ArrayList<>();
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
// create parser and set variable 'primes' as the array of integers
@@ -2122,7 +2122,7 @@ This section lists the classes used in the examples throughout this chapter.
public static String Advisors = "advisors";
public static String President = "president";
private List<Inventor> members = new ArrayList<Inventor>();
private List<Inventor> members = new ArrayList<>();
private Map officers = new HashMap();
public List getMembers() {
@@ -1028,12 +1028,30 @@ the call stack and makes a determination whether to mark the transaction for rol
In its default configuration, the Spring Framework's transaction infrastructure code
marks a transaction for rollback only in the case of runtime, unchecked exceptions.
That is, when the thrown exception is an instance or subclass of `RuntimeException`.
(`Error` instances also, by default, result in a rollback). Checked exceptions that are
thrown from a transactional method do not result in rollback in the default
configuration.
(`Error` instances also, by default, result in a rollback).
You can configure exactly which `Exception` types mark a transaction for rollback,
including checked exceptions by specifying _rollback rules_.
As of Spring Framework 5.2, the default configuration also provides support for
Vavr's `Try` method to trigger transaction rollbacks when it returns a 'Failure'.
This allows you to handle functional-style errors using Try and have the transaction
automatically rolled back in case of a failure. For more information on Vavr's Try,
refer to the [official Vavr documentation](https://www.vavr.io/vavr-docs/#_try).
Here's an example of how to use Vavr's Try with a transactional method:
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@Transactional
public Try<String> myTransactionalMethod() {
// If myDataAccessOperation throws an exception, it will be caught by the
// Try instance created with Try.of() and wrapped inside the Failure class
// which can be checked using the isFailure() method on the Try instance.
return Try.of(delegate::myDataAccessOperation);
}
----
Checked exceptions that are thrown from a transactional method do not result in a rollback
in the default configuration. You can configure exactly which `Exception` types mark a
transaction for rollback, including checked exceptions by specifying _rollback rules_.
.Rollback rules
[[transaction-declarative-rollback-rules]]
@@ -4528,7 +4546,7 @@ JDBC `?` placeholders:
}
public int[] batchUpdate(final List<Actor> actors) {
List<Object[]> batch = new ArrayList<Object[]>();
List<Object[]> batch = new ArrayList<>();
for (Actor actor : actors) {
Object[] values = new Object[] {
actor.getFirstName(), actor.getLastName(), actor.getId()};
@@ -4692,7 +4710,7 @@ example uses only one configuration method (we show examples of multiple methods
}
public void add(Actor actor) {
Map<String, Object> parameters = new HashMap<String, Object>(3);
Map<String, Object> parameters = new HashMap<>(3);
parameters.put("id", actor.getId());
parameters.put("first_name", actor.getFirstName());
parameters.put("last_name", actor.getLastName());
@@ -4750,7 +4768,7 @@ listing shows how it works:
}
public void add(Actor actor) {
Map<String, Object> parameters = new HashMap<String, Object>(2);
Map<String, Object> parameters = new HashMap<>(2);
parameters.put("first_name", actor.getFirstName());
parameters.put("last_name", actor.getLastName());
Number newId = insertActor.executeAndReturnKey(parameters);
@@ -4810,7 +4828,7 @@ You can limit the columns for an insert by specifying a list of column names wit
}
public void add(Actor actor) {
Map<String, Object> parameters = new HashMap<String, Object>(2);
Map<String, Object> parameters = new HashMap<>(2);
parameters.put("first_name", actor.getFirstName());
parameters.put("last_name", actor.getLastName());
Number newId = insertActor.executeAndReturnKey(parameters);
+1 -1
View File
@@ -13,7 +13,7 @@ Spring MVC Test, WebTestClient.
JDBC, R2DBC, O/R Mapping, XML Marshalling.
<<web.adoc#spring-web, Web Servlet>> :: Spring MVC, WebSocket, SockJS,
STOMP Messaging.
<<web-reactive.adoc#spring-webflux, Web Reactive>> :: Spring WebFlux, WebClient,
<<web-reactive.adoc#spring-web-reactive, Web Reactive>> :: Spring WebFlux, WebClient,
WebSocket, RSocket.
<<integration.adoc#spring-integration, Integration>> :: REST Clients, JMS, JCA, JMX,
Email, Tasks, Scheduling, Caching, Observability.
@@ -1655,7 +1655,7 @@ content types that a controller method produces, as the following example shows:
----
@GetMapping("/pets/{petId}", produces = ["application/json"])
@ResponseBody
fun getPet(@PathVariable String petId): Pet {
fun getPet(@PathVariable petId: String): Pet {
// ...
}
----
@@ -1704,7 +1704,7 @@ You can also use the same with request header conditions, as the following examp
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@GetMapping(path = "/pets", headers = "myHeader=myValue") // <1>
@GetMapping(path = "/pets/{petId}", headers = "myHeader=myValue") // <1>
public void findPet(@PathVariable String petId) {
// ...
}
@@ -1714,7 +1714,7 @@ You can also use the same with request header conditions, as the following examp
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
@GetMapping("/pets", headers = ["myHeader=myValue"]) // <1>
@GetMapping("/pets/{petId}", headers = ["myHeader=myValue"]) // <1>
fun findPet(@PathVariable petId: String) {
// ...
}
@@ -743,7 +743,7 @@ or to render a JSON response, as the following example shows:
@RequestMapping(path = "/error")
public Map<String, Object> handle(HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("status", request.getAttribute("jakarta.servlet.error.status_code"));
map.put("reason", request.getAttribute("jakarta.servlet.error.message"));
return map;
@@ -1903,7 +1903,7 @@ You can also use the same with request header conditions, as the following examp
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
@GetMapping(path = "/pets", headers = "myHeader=myValue") // <1>
@GetMapping(path = "/pets/{petId}", headers = "myHeader=myValue") // <1>
public void findPet(@PathVariable String petId) {
// ...
}
@@ -1913,7 +1913,7 @@ You can also use the same with request header conditions, as the following examp
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin
----
@GetMapping("/pets", headers = ["myHeader=myValue"]) // <1>
@GetMapping("/pets/{petId}", headers = ["myHeader=myValue"]) // <1>
fun findPet(@PathVariable petId: String) {
// ...
}
@@ -4393,7 +4393,7 @@ return value with `DeferredResult`, as the following example shows:
@GetMapping("/quotes")
@ResponseBody
public DeferredResult<String> quotes() {
DeferredResult<String> deferredResult = new DeferredResult<String>();
DeferredResult<String> deferredResult = new DeferredResult<>();
// Save the deferredResult somewhere..
return deferredResult;
}
+43 -43
View File
@@ -8,32 +8,32 @@ javaPlatform {
dependencies {
api(platform("com.fasterxml.jackson:jackson-bom:2.14.2"))
api(platform("io.micrometer:micrometer-bom:1.10.4"))
api(platform("io.netty:netty-bom:4.1.90.Final"))
api(platform("io.micrometer:micrometer-bom:1.10.6"))
api(platform("io.netty:netty-bom:4.1.91.Final"))
api(platform("io.netty:netty5-bom:5.0.0.Alpha5"))
api(platform("io.projectreactor:reactor-bom:2022.0.5"))
api(platform("io.projectreactor:reactor-bom:2022.0.6"))
api(platform("io.rsocket:rsocket-bom:1.1.3"))
api(platform("org.apache.groovy:groovy-bom:4.0.8"))
api(platform("org.apache.groovy:groovy-bom:4.0.11"))
api(platform("org.apache.logging.log4j:log4j-bom:2.20.0"))
api(platform("org.eclipse.jetty:jetty-bom:11.0.14"))
api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4"))
api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.4.0"))
api(platform("org.junit:junit-bom:5.9.2"))
api(platform("org.mockito:mockito-bom:5.2.0"))
api(platform("org.mockito:mockito-bom:5.3.0"))
constraints {
api("com.fasterxml:aalto-xml:1.3.1")
api("com.fasterxml:aalto-xml:1.3.2")
api("com.fasterxml.woodstox:woodstox-core:6.5.0")
api("com.github.ben-manes.caffeine:caffeine:3.1.2")
api("com.github.ben-manes.caffeine:caffeine:3.1.5")
api("com.github.librepdf:openpdf:1.3.30")
api("com.google.code.findbugs:findbugs:3.0.1")
api("com.google.code.findbugs:jsr305:3.0.2")
api("com.google.code.gson:gson:2.10")
api("com.google.code.gson:gson:2.10.1")
api("com.google.protobuf:protobuf-java-util:3.21.12")
api("com.googlecode.protobuf-java-format:protobuf-java-format:1.4")
api("com.h2database:h2:2.1.214")
api("com.jayway.jsonpath:json-path:2.7.0")
api("com.rometools:rome:1.18.0")
api("com.jayway.jsonpath:json-path:2.8.0")
api("com.rometools:rome:1.19.0")
api("com.squareup.okhttp3:mockwebserver:3.14.9")
api("com.squareup.okhttp3:okhttp:3.14.9")
api("com.sun.activation:jakarta.activation:2.0.1")
@@ -41,31 +41,31 @@ dependencies {
api("com.sun.xml.bind:jaxb-core:3.0.2")
api("com.sun.xml.bind:jaxb-impl:3.0.2")
api("com.sun.xml.bind:jaxb-xjc:3.0.2")
api("com.thoughtworks.qdox:qdox:2.0.2")
api("com.thoughtworks.xstream:xstream:1.4.19")
api("com.thoughtworks.qdox:qdox:2.0.3")
api("com.thoughtworks.xstream:xstream:1.4.20")
api("commons-io:commons-io:2.11.0")
api("de.bechte.junit:junit-hierarchicalcontextrunner:4.12.1")
api("info.picocli:picocli:4.7.0")
api("de.bechte.junit:junit-hierarchicalcontextrunner:4.12.2")
api("info.picocli:picocli:4.7.1")
api("io.micrometer:context-propagation:1.0.0")
api("io.mockk:mockk:1.12.1")
api("io.mockk:mockk:1.13.4")
api("io.projectreactor.netty:reactor-netty5-http:2.0.0-M3")
api("io.projectreactor.tools:blockhound:1.0.6.RELEASE")
api("io.projectreactor.tools:blockhound:1.0.7.RELEASE")
api("io.r2dbc:r2dbc-h2:1.0.0.RELEASE")
api("io.r2dbc:r2dbc-spi-test:1.0.0.RELEASE")
api("io.r2dbc:r2dbc-spi:1.0.0.RELEASE")
api("io.reactivex.rxjava3:rxjava:3.1.5")
api("io.smallrye.reactive:mutiny:1.8.0")
api("io.undertow:undertow-core:2.3.4.Final")
api("io.undertow:undertow-servlet:2.3.4.Final")
api("io.undertow:undertow-websockets-jsr:2.3.4.Final")
api("io.reactivex.rxjava3:rxjava:3.1.6")
api("io.smallrye.reactive:mutiny:1.9.0")
api("io.undertow:undertow-core:2.3.5.Final")
api("io.undertow:undertow-servlet:2.3.5.Final")
api("io.undertow:undertow-websockets-jsr:2.3.5.Final")
api("io.vavr:vavr:0.10.4")
api("jakarta.activation:jakarta.activation-api:2.0.1")
api("jakarta.annotation:jakarta.annotation-api:2.0.0")
api("jakarta.ejb:jakarta.ejb-api:4.0.0")
api("jakarta.ejb:jakarta.ejb-api:4.0.1")
api("jakarta.el:jakarta.el-api:4.0.0")
api("jakarta.enterprise.concurrent:jakarta.enterprise.concurrent-api:2.0.0")
api("jakarta.faces:jakarta.faces-api:3.0.0")
api("jakarta.inject:jakarta.inject-api:2.0.0")
api("jakarta.inject:jakarta.inject-api:2.0.1")
api("jakarta.inject:jakarta.inject-tck:2.0.1")
api("jakarta.interceptor:jakarta.interceptor-api:2.0.0")
api("jakarta.jms:jakarta.jms-api:3.0.0")
@@ -75,7 +75,7 @@ dependencies {
api("jakarta.persistence:jakarta.persistence-api:3.0.0")
api("jakarta.resource:jakarta.resource-api:2.0.0")
api("jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0")
api("jakarta.servlet.jsp:jakarta.servlet.jsp-api:3.1.0")
api("jakarta.servlet.jsp:jakarta.servlet.jsp-api:3.1.1")
api("jakarta.servlet:jakarta.servlet-api:6.0.0")
api("jakarta.transaction:jakarta.transaction-api:2.0.1")
api("jakarta.validation:jakarta.validation-api:3.0.2")
@@ -89,9 +89,9 @@ dependencies {
api("net.sf.jopt-simple:jopt-simple:5.0.4")
api("net.sourceforge.htmlunit:htmlunit:2.70.0")
api("org.apache-extras.beanshell:bsh:2.0b6")
api("org.apache.activemq:activemq-broker:5.16.2")
api("org.apache.activemq:activemq-kahadb-store:5.16.2")
api("org.apache.activemq:activemq-stomp:5.16.2")
api("org.apache.activemq:activemq-broker:5.17.2")
api("org.apache.activemq:activemq-kahadb-store:5.17.2")
api("org.apache.activemq:activemq-stomp:5.17.2")
api("org.apache.commons:commons-pool2:2.9.0")
api("org.apache.derby:derby:10.16.1.1")
api("org.apache.derby:derbyclient:10.16.1.1")
@@ -103,41 +103,41 @@ dependencies {
api("org.apache.tomcat.embed:tomcat-embed-websocket:10.1.7")
api("org.apache.tomcat:tomcat-util:10.1.7")
api("org.apache.tomcat:tomcat-websocket:10.1.7")
api("org.aspectj:aspectjrt:1.9.9.1")
api("org.aspectj:aspectjtools:1.9.9.1")
api("org.aspectj:aspectjweaver:1.9.9.1")
api("org.aspectj:aspectjrt:1.9.19")
api("org.aspectj:aspectjtools:1.9.19")
api("org.aspectj:aspectjweaver:1.9.19")
api("org.assertj:assertj-core:3.24.2")
api("org.awaitility:awaitility:3.1.6")
api("org.bouncycastle:bcpkix-jdk18on:1.71")
api("org.codehaus.jettison:jettison:1.3.8")
api("org.dom4j:dom4j:2.1.3")
api("org.eclipse.jetty:jetty-reactive-httpclient:3.0.7")
api("org.awaitility:awaitility:4.2.0")
api("org.bouncycastle:bcpkix-jdk18on:1.72")
api("org.codehaus.jettison:jettison:1.5.4")
api("org.dom4j:dom4j:2.1.4")
api("org.eclipse.jetty:jetty-reactive-httpclient:3.0.8")
api("org.eclipse.persistence:org.eclipse.persistence.jpa:3.0.3")
api("org.eclipse:yasson:2.0.4")
api("org.ehcache:ehcache:3.4.0")
api("org.ehcache:ehcache:3.10.8")
api("org.ehcache:jcache:1.0.1")
api("org.freemarker:freemarker:2.3.32")
// Substitute for "javax.management:jmxremote_optional:1.0.1_04" which
// is not available on Maven Central
api("org.glassfish.external:opendmk_jmxremote_optional_jar:1.0-b01-ea")
api("org.glassfish.tyrus:tyrus-container-servlet:2.0.1")
api("org.glassfish.tyrus:tyrus-container-servlet:2.1.3")
api("org.glassfish:jakarta.el:4.0.2")
api("org.graalvm.sdk:graal-sdk:22.3.0")
api("org.graalvm.sdk:graal-sdk:22.3.1")
api("org.hamcrest:hamcrest:2.2")
api("org.hibernate:hibernate-core-jakarta:5.6.15.Final")
api("org.hibernate:hibernate-validator:7.0.5.Final")
api("org.hsqldb:hsqldb:2.7.1")
api("org.javamoney:moneta:1.4.2")
api("org.jruby:jruby:9.4.0.0")
api("org.jruby:jruby:9.4.2.0")
api("org.junit.support:testng-engine:1.0.4")
api("org.mozilla:rhino:1.7.11")
api("org.mozilla:rhino:1.7.14")
api("org.ogce:xpp3:1.1.6")
api("org.python:jython-standalone:2.7.1")
api("org.python:jython-standalone:2.7.3")
api("org.quartz-scheduler:quartz:2.3.2")
api("org.seleniumhq.selenium:htmlunit-driver:2.70.0")
api("org.seleniumhq.selenium:selenium-java:3.141.59")
api("org.skyscreamer:jsonassert:1.5.0")
api("org.slf4j:slf4j-api:2.0.6")
api("org.skyscreamer:jsonassert:1.5.1")
api("org.slf4j:slf4j-api:2.0.7")
api("org.testng:testng:7.7.1")
api("org.webjars:underscorejs:1.8.3")
api("org.webjars:webjars-locator-core:0.52")
+1 -1
View File
@@ -1,4 +1,4 @@
version=6.0.7
version=6.0.8
org.gradle.caching=true
org.gradle.jvmargs=-Xmx2048m
+6 -5
View File
@@ -5,10 +5,10 @@
* One can choose the toolchain to use for compiling the MAIN sources and/or compiling
* and running the TEST sources. These options apply to Java, Kotlin and Groovy sources
* when available.
* {@code "./gradlew check -PmainToolchain=17 -PtestToolchain=19"} will use:
* {@code "./gradlew check -PmainToolchain=17 -PtestToolchain=20"} will use:
* <ul>
* <li>a JDK17 toolchain for compiling the main SourceSet
* <li>a JDK19 toolchain for compiling and running the test SourceSet
* <li>a JDK20 toolchain for compiling and running the test SourceSet
* </ul>
*
* By default, the build will fall back to using the current JDK and 17 language level for all sourceSets.
@@ -23,9 +23,9 @@
* {@code
* $ echo JDK17
* /opt/openjdk/java17
* $ echo JDK19
* /opt/openjdk/java18
* $ ./gradlew -Porg.gradle.java.installations.fromEnv=JDK17,JDK19 check
* $ echo JDK20
* /opt/openjdk/java20
* $ ./gradlew -Porg.gradle.java.installations.fromEnv=JDK17,JDK20 check
* }
*
* @author Brian Clozel
@@ -81,6 +81,7 @@ plugins.withType(JavaPlugin) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = testLanguageVersion
}
jvmArgs += ['-Djava.locale.providers=COMPAT']
}
}
}
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+2 -2
View File
@@ -144,7 +144,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@@ -152,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ class AopNamespaceHandlerScopeIntegrationTests {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest));
assertThat(requestScoped.getName()).isEqualTo(bram);
assertThat(((Advised) requestScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
assertThat(((Advised) requestScoped).getAdvisors()).as("Should have advisors").isNotEmpty();
}
@Test
@@ -131,7 +131,7 @@ class AopNamespaceHandlerScopeIntegrationTests {
request.setSession(oldSession);
assertThat(sessionScoped.getName()).isEqualTo(bram);
assertThat(((Advised) sessionScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
assertThat(((Advised) sessionScoped).getAdvisors()).as("Should have advisors").isNotEmpty();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,25 +52,25 @@ class ComponentBeanDefinitionParserTests {
@Test
void testBionicBasic() {
Component cp = getBionicFamily();
assertThat("Bionic-1").isEqualTo(cp.getName());
assertThat(cp.getName()).isEqualTo("Bionic-1");
}
@Test
void testBionicFirstLevelChildren() {
Component cp = getBionicFamily();
List<Component> components = cp.getComponents();
assertThat(2).isEqualTo(components.size());
assertThat("Mother-1").isEqualTo(components.get(0).getName());
assertThat("Rock-1").isEqualTo(components.get(1).getName());
assertThat(components).hasSize(2);
assertThat(components.get(0).getName()).isEqualTo("Mother-1");
assertThat(components.get(1).getName()).isEqualTo("Rock-1");
}
@Test
void testBionicSecondLevelChildren() {
Component cp = getBionicFamily();
List<Component> components = cp.getComponents().get(0).getComponents();
assertThat(2).isEqualTo(components.size());
assertThat("Karate-1").isEqualTo(components.get(0).getName());
assertThat("Sport-1").isEqualTo(components.get(1).getName());
assertThat(components).hasSize(2);
assertThat(components.get(0).getName()).isEqualTo("Karate-1");
assertThat(components.get(1).getName()).isEqualTo("Sport-1");
}
private Component getBionicFamily() {
+1 -1
View File
@@ -7,7 +7,7 @@ pluginManagement {
}
plugins {
id "com.gradle.enterprise" version "3.12.3"
id "com.gradle.enterprise" version "3.12.6"
id "io.spring.ge.conventions" version "0.0.13"
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,6 +120,11 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
if (logger.isTraceEnabled()) {
logger.trace("Creating JDK dynamic proxy: " + this.advised.getTargetSource());
}
if (classLoader == null || classLoader.getParent() == null) {
// JDK bootstrap loader or platform loader suggested ->
// use higher-level loader which can see Spring infrastructure classes
classLoader = getClass().getClassLoader();
}
return Proxy.newProxyInstance(classLoader, this.proxiedInterfaces, this);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class MethodInvocationProceedingJoinPointTests {
AtomicInteger depth = new AtomicInteger();
pf.addAdvice((MethodBeforeAdvice) (method, args, target) -> {
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertThat(jp.toString().contains(method.getName())).as("Method named in toString").isTrue();
assertThat(jp.toString()).as("Method named in toString").contains(method.getName());
// Ensure that these don't cause problems
jp.toShortString();
jp.toLongString();
@@ -319,10 +319,10 @@ abstract class AbstractAspectJAdvisorFactoryTests {
@Test
void introductionOnTargetNotImplementingInterface() {
NotLockable notLockableTarget = new NotLockable();
assertThat(notLockableTarget instanceof Lockable).isFalse();
assertThat(notLockableTarget).isNotInstanceOf(Lockable.class);
NotLockable notLockable1 = createProxy(notLockableTarget, NotLockable.class,
getAdvisorFactory().getAdvisors(aspectInstanceFactory(new MakeLockable(), "someBean")));
assertThat(notLockable1 instanceof Lockable).isTrue();
assertThat(notLockable1).isInstanceOf(Lockable.class);
Lockable lockable = (Lockable) notLockable1;
assertThat(lockable.locked()).isFalse();
lockable.lock();
@@ -331,7 +331,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
NotLockable notLockable2Target = new NotLockable();
NotLockable notLockable2 = createProxy(notLockable2Target, NotLockable.class,
getAdvisorFactory().getAdvisors(aspectInstanceFactory(new MakeLockable(), "someBean")));
assertThat(notLockable2 instanceof Lockable).isTrue();
assertThat(notLockable2).isInstanceOf(Lockable.class);
Lockable lockable2 = (Lockable) notLockable2;
assertThat(lockable2.locked()).isFalse();
notLockable2.setIntValue(1);
@@ -345,7 +345,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
assertThat(AopUtils.findAdvisorsThatCanApply(
getAdvisorFactory().getAdvisors(
aspectInstanceFactory(new MakeLockable(), "someBean")),
CannotBeUnlocked.class).isEmpty()).isTrue();
CannotBeUnlocked.class)).isEmpty();
assertThat(AopUtils.findAdvisorsThatCanApply(getAdvisorFactory().getAdvisors(
aspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class)).hasSize(2);
}
@@ -373,7 +373,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
AopUtils.findAdvisorsThatCanApply(
getAdvisorFactory().getAdvisors(aspectInstanceFactory(new MakeLockable(), "someBean")),
List.class));
assertThat(proxy instanceof Lockable).as("Type pattern must have excluded mixin").isFalse();
assertThat(proxy).as("Type pattern must have excluded mixin").isNotInstanceOf(Lockable.class);
}
@Test
@@ -430,7 +430,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
UnsupportedOperationException expectedException = new UnsupportedOperationException();
List<Advisor> advisors = getAdvisorFactory().getAdvisors(
aspectInstanceFactory(new ExceptionThrowingAspect(expectedException), "someBean"));
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
assertThat(advisors).as("One advice method was found").hasSize(1);
ITestBean itb = createProxy(target, ITestBean.class, advisors);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(itb::getAge);
}
@@ -443,7 +443,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
RemoteException expectedException = new RemoteException();
List<Advisor> advisors = getAdvisorFactory().getAdvisors(
aspectInstanceFactory(new ExceptionThrowingAspect(expectedException), "someBean"));
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
assertThat(advisors).as("One advice method was found").hasSize(1);
ITestBean itb = createProxy(target, ITestBean.class, advisors);
assertThatExceptionOfType(UndeclaredThrowableException.class)
.isThrownBy(itb::getAge)
@@ -456,7 +456,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
List<Advisor> advisors = getAdvisorFactory().getAdvisors(
aspectInstanceFactory(twoAdviceAspect, "someBean"));
assertThat(advisors.size()).as("Two advice methods found").isEqualTo(2);
assertThat(advisors).as("Two advice methods found").hasSize(2);
ITestBean itb = createProxy(target, ITestBean.class, advisors);
itb.setName("");
assertThat(itb.getAge()).isEqualTo(0);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,10 @@
package org.springframework.aop.framework;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.accessibility.Accessible;
@@ -194,11 +197,11 @@ public class ProxyFactoryTests {
TestBeanSubclass raw = new TestBeanSubclass();
ProxyFactory factory = new ProxyFactory(raw);
//System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
assertThat(factory.getProxiedInterfaces().length).as("Found correct number of interfaces").isEqualTo(5);
assertThat(factory.getProxiedInterfaces()).as("Found correct number of interfaces").hasSize(5);
ITestBean tb = (ITestBean) factory.getProxy();
assertThat(tb).as("Picked up secondary interface").isInstanceOf(IOther.class);
raw.setAge(25);
assertThat(tb.getAge() == raw.getAge()).isTrue();
assertThat(tb.getAge()).isEqualTo(raw.getAge());
long t = 555555L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
@@ -208,10 +211,10 @@ public class ProxyFactoryTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
assertThat(newProxiedInterfaces.length).as("Advisor proxies one more interface after introduction").isEqualTo(oldProxiedInterfaces.length + 1);
assertThat(newProxiedInterfaces).as("Advisor proxies one more interface after introduction").hasSize(oldProxiedInterfaces.length + 1);
TimeStamped ts = (TimeStamped) factory.getProxy();
assertThat(ts.getTimeStamp() == t).isTrue();
assertThat(ts.getTimeStamp()).isEqualTo(t);
// Shouldn't fail;
((IOther) ts).absquatulate();
}
@@ -231,13 +234,13 @@ public class ProxyFactoryTests {
factory.addAdvice(0, di);
assertThat(factory.getProxy()).isInstanceOf(ITestBean.class);
assertThat(factory.adviceIncluded(di)).isTrue();
assertThat(!factory.adviceIncluded(diUnused)).isTrue();
assertThat(factory.countAdvicesOfType(NopInterceptor.class) == 1).isTrue();
assertThat(factory.countAdvicesOfType(MyInterceptor.class) == 0).isTrue();
assertThat(factory.adviceIncluded(diUnused)).isFalse();
assertThat(factory.countAdvicesOfType(NopInterceptor.class)).isEqualTo(1);
assertThat(factory.countAdvicesOfType(MyInterceptor.class)).isEqualTo(0);
factory.addAdvice(0, diUnused);
assertThat(factory.adviceIncluded(diUnused)).isTrue();
assertThat(factory.countAdvicesOfType(NopInterceptor.class) == 2).isTrue();
assertThat(factory.countAdvicesOfType(NopInterceptor.class)).isEqualTo(2);
}
@Test
@@ -257,7 +260,8 @@ public class ProxyFactoryTests {
public void testCanAddAndRemoveAspectInterfacesOnSingleton() {
ProxyFactory config = new ProxyFactory(new TestBean());
assertThat(config.getProxy() instanceof TimeStamped).as("Shouldn't implement TimeStamped before manipulation").isFalse();
assertThat(config.getProxy()).as("Shouldn't implement TimeStamped before manipulation")
.isNotInstanceOf(TimeStamped.class);
long time = 666L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
@@ -267,26 +271,26 @@ public class ProxyFactoryTests {
int oldCount = config.getAdvisors().length;
config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
assertThat(config.getAdvisors().length == oldCount + 1).isTrue();
assertThat(config.getAdvisors()).hasSize(oldCount + 1);
TimeStamped ts = (TimeStamped) config.getProxy();
assertThat(ts.getTimeStamp() == time).isTrue();
assertThat(ts.getTimeStamp()).isEqualTo(time);
// Can remove
config.removeAdvice(ti);
assertThat(config.getAdvisors().length == oldCount).isTrue();
assertThat(config.getAdvisors()).hasSize(oldCount);
assertThatRuntimeException()
.as("Existing object won't implement this interface any more")
.isThrownBy(ts::getTimeStamp); // Existing reference will fail
assertThat(config.getProxy() instanceof TimeStamped).as("Should no longer implement TimeStamped").isFalse();
assertThat(config.getProxy()).as("Should no longer implement TimeStamped").isNotInstanceOf(TimeStamped.class);
// Now check non-effect of removing interceptor that isn't there
config.removeAdvice(new DebugInterceptor());
assertThat(config.getAdvisors().length == oldCount).isTrue();
assertThat(config.getAdvisors()).hasSize(oldCount);
ITestBean it = (ITestBean) ts;
DebugInterceptor debugInterceptor = new DebugInterceptor();
@@ -296,7 +300,7 @@ public class ProxyFactoryTests {
config.removeAdvice(debugInterceptor);
it.getSpouse();
// not invoked again
assertThat(debugInterceptor.getCount() == 1).isTrue();
assertThat(debugInterceptor.getCount()).isEqualTo(1);
}
@Test
@@ -305,13 +309,13 @@ public class ProxyFactoryTests {
pf.setTargetClass(ITestBean.class);
Object proxy = pf.getProxy();
assertThat(AopUtils.isJdkDynamicProxy(proxy)).as("Proxy is a JDK proxy").isTrue();
assertThat(proxy instanceof ITestBean).isTrue();
assertThat(proxy).isInstanceOf(ITestBean.class);
assertThat(AopProxyUtils.ultimateTargetClass(proxy)).isEqualTo(ITestBean.class);
ProxyFactory pf2 = new ProxyFactory(proxy);
Object proxy2 = pf2.getProxy();
assertThat(AopUtils.isJdkDynamicProxy(proxy2)).as("Proxy is a JDK proxy").isTrue();
assertThat(proxy2 instanceof ITestBean).isTrue();
assertThat(proxy2).isInstanceOf(ITestBean.class);
assertThat(AopProxyUtils.ultimateTargetClass(proxy2)).isEqualTo(ITestBean.class);
}
@@ -321,14 +325,14 @@ public class ProxyFactoryTests {
pf.setTargetClass(TestBean.class);
Object proxy = pf.getProxy();
assertThat(AopUtils.isCglibProxy(proxy)).as("Proxy is a CGLIB proxy").isTrue();
assertThat(proxy instanceof TestBean).isTrue();
assertThat(proxy).isInstanceOf(TestBean.class);
assertThat(AopProxyUtils.ultimateTargetClass(proxy)).isEqualTo(TestBean.class);
ProxyFactory pf2 = new ProxyFactory(proxy);
pf2.setProxyTargetClass(true);
Object proxy2 = pf2.getProxy();
assertThat(AopUtils.isCglibProxy(proxy2)).as("Proxy is a CGLIB proxy").isTrue();
assertThat(proxy2 instanceof TestBean).isTrue();
assertThat(proxy2).isInstanceOf(TestBean.class);
assertThat(AopProxyUtils.ultimateTargetClass(proxy2)).isEqualTo(TestBean.class);
}
@@ -338,8 +342,8 @@ public class ProxyFactoryTests {
JFrame frame = new JFrame();
ProxyFactory proxyFactory = new ProxyFactory(frame);
Object proxy = proxyFactory.getProxy();
assertThat(proxy instanceof RootPaneContainer).isTrue();
assertThat(proxy instanceof Accessible).isTrue();
assertThat(proxy).isInstanceOf(RootPaneContainer.class);
assertThat(proxy).isInstanceOf(Accessible.class);
}
@Test
@@ -380,6 +384,40 @@ public class ProxyFactoryTests {
assertThat(proxy.getName()).isEqualTo("tb");
}
@Test
public void testCharSequenceProxy() {
CharSequence target = "test";
ProxyFactory pf = new ProxyFactory(target);
ClassLoader cl = target.getClass().getClassLoader();
assertThat(((CharSequence) pf.getProxy(cl)).toString()).isEqualTo(target);
}
@Test
public void testDateProxy() {
Date target = new Date();
ProxyFactory pf = new ProxyFactory(target);
pf.setProxyTargetClass(true);
ClassLoader cl = target.getClass().getClassLoader();
assertThat(((Date) pf.getProxy(cl)).getTime()).isEqualTo(target.getTime());
}
@Test
public void testJdbcSavepointProxy() throws SQLException {
Savepoint target = new Savepoint() {
@Override
public int getSavepointId() throws SQLException {
return 1;
}
@Override
public String getSavepointName() throws SQLException {
return "sp";
}
};
ProxyFactory pf = new ProxyFactory(target);
ClassLoader cl = Savepoint.class.getClassLoader();
assertThat(((Savepoint) pf.getProxy(cl)).getSavepointName()).isEqualTo("sp");
}
@Order(2)
public static class A implements Runnable {
@@ -391,7 +429,7 @@ public class ProxyFactoryTests {
@Order(1)
public static class B implements Runnable{
public static class B implements Runnable {
@Override
public void run() {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean
@Override
protected void assertions(MethodInvocation invocation) {
assertThat(invocation.getThis() == this).isTrue();
assertThat(invocation.getThis()).isSameAs(this);
assertThat(ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())).as("Invocation should be on ITestBean: " + invocation.getMethod()).isTrue();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -128,7 +128,7 @@ class ScopedProxyBeanRegistrationAotProcessorTests {
this.beanFactory.registerBeanDefinition("test", scopedBean);
compile((freshBeanFactory, compiled) -> {
Object bean = freshBeanFactory.getBean("test");
assertThat(bean).isNotNull().isInstanceOf(NumberHolder.class).isInstanceOf(AopInfrastructureBean.class);
assertThat(bean).isInstanceOf(NumberHolder.class).isInstanceOf(AopInfrastructureBean.class);
});
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -142,7 +142,7 @@ public class ComposablePointcutTests {
pc1.intersection(GETTER_METHOD_MATCHER);
assertThat(pc1.equals(pc2)).isFalse();
assertThat(pc1.hashCode() == pc2.hashCode()).isFalse();
assertThat(pc1.hashCode()).isNotEqualTo(pc2.hashCode());
pc2.intersection(GETTER_METHOD_MATCHER);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ public class ControlFlowPointcutTests {
assertThat(new ControlFlowPointcut(One.class, "getAge").equals(new ControlFlowPointcut(One.class))).isFalse();
assertThat(new ControlFlowPointcut(One.class).hashCode()).isEqualTo(new ControlFlowPointcut(One.class).hashCode());
assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode()).isEqualTo(new ControlFlowPointcut(One.class, "getAge").hashCode());
assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode() == new ControlFlowPointcut(One.class).hashCode()).isFalse();
assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode()).isNotEqualTo(new ControlFlowPointcut(One.class).hashCode());
}
@Test
@@ -56,7 +56,7 @@ class DelegatingIntroductionInterceptorTests {
@Test
void testIntroductionInterceptorWithDelegation() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof TimeStamped)).isTrue();
assertThat(raw).isNotInstanceOf(TimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock();
@@ -66,13 +66,13 @@ class DelegatingIntroductionInterceptorTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
TimeStamped tsp = (TimeStamped) factory.getProxy();
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
assertThat(tsp.getTimeStamp()).isEqualTo(timestamp);
}
@Test
void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof SubTimeStamped)).isTrue();
assertThat(raw).isNotInstanceOf(SubTimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw);
SubTimeStamped ts = mock();
@@ -82,13 +82,13 @@ class DelegatingIntroductionInterceptorTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));
SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
assertThat(tsp.getTimeStamp()).isEqualTo(timestamp);
}
@Test
void testIntroductionInterceptorWithSuperInterface() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof TimeStamped)).isTrue();
assertThat(raw).isNotInstanceOf(TimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw);
SubTimeStamped ts = mock();
@@ -98,8 +98,8 @@ class DelegatingIntroductionInterceptorTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));
TimeStamped tsp = (TimeStamped) factory.getProxy();
assertThat(!(tsp instanceof SubTimeStamped)).isTrue();
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
assertThat(tsp).isNotInstanceOf(SubTimeStamped.class);
assertThat(tsp.getTimeStamp()).isEqualTo(timestamp);
}
@Test
@@ -125,7 +125,7 @@ class DelegatingIntroductionInterceptorTests {
//assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
TimeStamped ts = (TimeStamped) pf.getProxy();
assertThat(ts.getTimeStamp() == t).isTrue();
assertThat(ts.getTimeStamp()).isEqualTo(t);
((ITester) ts).foo();
((ITestBean) ts).getAge();
@@ -160,10 +160,10 @@ class DelegatingIntroductionInterceptorTests {
assertThat(ts).isInstanceOf(TimeStamped.class);
// Shouldn't proxy framework interfaces
assertThat(!(ts instanceof MethodInterceptor)).isTrue();
assertThat(!(ts instanceof IntroductionInterceptor)).isTrue();
assertThat(ts).isNotInstanceOf(MethodInterceptor.class);
assertThat(ts).isNotInstanceOf(IntroductionInterceptor.class);
assertThat(ts.getTimeStamp() == t).isTrue();
assertThat(ts.getTimeStamp()).isEqualTo(t);
((ITester) ts).foo();
((ITestBean) ts).getAge();
@@ -174,14 +174,14 @@ class DelegatingIntroductionInterceptorTests {
pf = new ProxyFactory(target);
pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));
Object o = pf.getProxy();
assertThat(!(o instanceof TimeStamped)).isTrue();
assertThat(o).isNotInstanceOf(TimeStamped.class);
}
@SuppressWarnings("serial")
@Test
void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
TestBean raw = new TestBean();
assertThat(! (raw instanceof TimeStamped)).isTrue();
assertThat(raw).isNotInstanceOf(TimeStamped.class);
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = new SerializableTimeStamped(0);
@@ -266,7 +266,7 @@ class DelegatingIntroductionInterceptorTests {
TimeStamped ts = (TimeStamped) pf.getProxy();
// From introduction interceptor, not target
assertThat(ts.getTimeStamp() == t).isTrue();
assertThat(ts.getTimeStamp()).isEqualTo(t);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -129,7 +129,7 @@ public class NameMatchMethodPointcutTests {
pc1.setMappedName(foo);
assertThat(pc1.equals(pc2)).isFalse();
assertThat(pc1.hashCode() != pc2.hashCode()).isTrue();
assertThat(pc1.hashCode()).isNotEqualTo(pc2.hashCode());
pc2.setMappedName(foo);
assertThat(pc2).isEqualTo(pc1);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -543,7 +543,7 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
assertThat(!r1.equals(r3)).isTrue();
assertThat(r1.equals(r3)).isFalse();
assertThat(primary.get(key)).isNull();
Object key2 = 3;
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,7 +92,7 @@ public class AspectJEnableCachingIsolatedTests {
load(MultiCacheManagerConfig.class);
}
catch (IllegalStateException ex) {
assertThat(ex.getMessage().contains("bean of type CacheManager")).isTrue();
assertThat(ex.getMessage()).contains("bean of type CacheManager");
}
}
@@ -107,7 +107,7 @@ public class AspectJEnableCachingIsolatedTests {
load(MultiCacheManagerConfigurer.class, EnableCachingConfig.class);
}
catch (IllegalStateException ex) {
assertThat(ex.getMessage().contains("implementations of CachingConfigurer")).isTrue();
assertThat(ex.getMessage()).contains("implementations of CachingConfigurer");
}
}
@@ -117,7 +117,7 @@ public class AspectJEnableCachingIsolatedTests {
load(EmptyConfig.class);
}
catch (IllegalStateException ex) {
assertThat(ex.getMessage().contains("no bean of type CacheManager")).isTrue();
assertThat(ex.getMessage()).contains("no bean of type CacheManager");
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.factory.aot;
/**
* Record class holding key information for beans registered in a bean factory.
*
* @param beanName the name of the registered bean
* @param beanClass the type of the registered bean
* @author Brian Clozel
* @since 6.0.8
*/
record BeanRegistrationKey(String beanName, Class<?> beanClass) {
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@ import org.springframework.aot.generate.GeneratedMethods;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.generate.MethodReference;
import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.CodeBlock;
@@ -38,6 +40,7 @@ import org.springframework.javapoet.MethodSpec;
* @author Phillip Webb
* @author Sebastien Deleuze
* @author Stephane Nicoll
* @author Brian Clozel
* @since 6.0
* @see BeanRegistrationsAotProcessor
*/
@@ -46,9 +49,10 @@ class BeanRegistrationsAotContribution
private static final String BEAN_FACTORY_PARAMETER_NAME = "beanFactory";
private final Map<String, Registration> registrations;
private final Map<BeanRegistrationKey, Registration> registrations;
BeanRegistrationsAotContribution(Map<String, Registration> registrations) {
BeanRegistrationsAotContribution(Map<BeanRegistrationKey, Registration> registrations) {
this.registrations = registrations;
}
@@ -69,26 +73,23 @@ class BeanRegistrationsAotContribution
GeneratedMethod generatedAliasesMethod = codeGenerator.getMethods().add("registerAliases",
this::generateRegisterAliasesMethod);
beanFactoryInitializationCode.addInitializer(generatedAliasesMethod.toMethodReference());
generateRegisterHints(generationContext.getRuntimeHints(), this.registrations);
}
private void generateRegisterBeanDefinitionsMethod(MethodSpec.Builder method,
GenerationContext generationContext,
BeanRegistrationsCode beanRegistrationsCode) {
GenerationContext generationContext, BeanRegistrationsCode beanRegistrationsCode) {
method.addJavadoc("Register the bean definitions.");
method.addModifiers(Modifier.PUBLIC);
method.addParameter(DefaultListableBeanFactory.class,
BEAN_FACTORY_PARAMETER_NAME);
method.addParameter(DefaultListableBeanFactory.class, BEAN_FACTORY_PARAMETER_NAME);
CodeBlock.Builder code = CodeBlock.builder();
this.registrations.forEach((beanName, registration) -> {
this.registrations.forEach((registeredBean, registration) -> {
MethodReference beanDefinitionMethod = registration.methodGenerator
.generateBeanDefinitionMethod(generationContext,
beanRegistrationsCode);
.generateBeanDefinitionMethod(generationContext, beanRegistrationsCode);
CodeBlock methodInvocation = beanDefinitionMethod.toInvokeCodeBlock(
ArgumentCodeGenerator.none(), beanRegistrationsCode.getClassName());
code.addStatement("$L.registerBeanDefinition($S, $L)",
BEAN_FACTORY_PARAMETER_NAME, beanName,
methodInvocation);
BEAN_FACTORY_PARAMETER_NAME, registeredBean.beanName(), methodInvocation);
});
method.addCode(code.build());
}
@@ -96,18 +97,22 @@ class BeanRegistrationsAotContribution
private void generateRegisterAliasesMethod(MethodSpec.Builder method) {
method.addJavadoc("Register the aliases.");
method.addModifiers(Modifier.PUBLIC);
method.addParameter(DefaultListableBeanFactory.class,
BEAN_FACTORY_PARAMETER_NAME);
method.addParameter(DefaultListableBeanFactory.class, BEAN_FACTORY_PARAMETER_NAME);
CodeBlock.Builder code = CodeBlock.builder();
this.registrations.forEach((beanName, registration) -> {
this.registrations.forEach((registeredBean, registration) -> {
for (String alias : registration.aliases) {
code.addStatement("$L.registerAlias($S, $S)",
BEAN_FACTORY_PARAMETER_NAME, beanName, alias);
code.addStatement("$L.registerAlias($S, $S)", BEAN_FACTORY_PARAMETER_NAME,
registeredBean.beanName(), alias);
}
});
method.addCode(code.build());
}
private void generateRegisterHints(RuntimeHints runtimeHints, Map<BeanRegistrationKey, Registration> registrations) {
registrations.keySet().forEach(beanRegistrationKey -> runtimeHints.reflection()
.registerType(beanRegistrationKey.beanClass(), MemberCategory.INTROSPECT_DECLARED_METHODS));
}
/**
* Gather the necessary information to register a particular bean.
* @param methodGenerator the {@link BeanDefinitionMethodGenerator} to use
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import org.springframework.lang.Nullable;
* @author Phillip Webb
* @author Sebastien Deleuze
* @author Stephane Nicoll
* @author Brian Clozel
* @since 6.0
*/
class BeanRegistrationsAotProcessor implements BeanFactoryInitializationAotProcessor {
@@ -40,15 +41,15 @@ class BeanRegistrationsAotProcessor implements BeanFactoryInitializationAotProce
public BeanRegistrationsAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory =
new BeanDefinitionMethodGeneratorFactory(beanFactory);
Map<String, Registration> registrations = new LinkedHashMap<>();
Map<BeanRegistrationKey, Registration> registrations = new LinkedHashMap<>();
for (String beanName : beanFactory.getBeanDefinitionNames()) {
RegisteredBean registeredBean = RegisteredBean.of(beanFactory, beanName);
BeanDefinitionMethodGenerator beanDefinitionMethodGenerator =
beanDefinitionMethodGeneratorFactory.getBeanDefinitionMethodGenerator(registeredBean);
if (beanDefinitionMethodGenerator != null) {
registrations.put(beanName, new Registration(beanDefinitionMethodGenerator,
beanFactory.getAliases(beanName)));
registrations.put(new BeanRegistrationKey(beanName, registeredBean.getBeanClass()),
new Registration(beanDefinitionMethodGenerator, beanFactory.getAliases(beanName)));
}
}
@@ -294,7 +294,9 @@ class ConstructorResolver {
}
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"Could not resolve matching constructor on bean class [" + mbd.getBeanClassName() + "] " +
"(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)");
"(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities. " +
"You should also check the consistency of arguments when mixing indexed and named arguments, " +
"especially in case of bean definition inheritance)");
}
else if (ambiguousConstructors != null && !mbd.isLenientConstructorResolution()) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
@@ -49,6 +49,7 @@ import org.springframework.util.StringUtils;
* @author Costin Leau
* @author Stephane Nicoll
* @author Sam Brannen
* @author Sebastien Deleuze
* @since 2.0
* @see AbstractBeanFactory
* @see org.springframework.beans.factory.DisposableBean
@@ -114,7 +115,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
(bean instanceof AutoCloseable && CLOSE_METHOD_NAME.equals(destroyMethodNames[0]));
if (!this.invokeAutoCloseable) {
this.destroyMethodNames = destroyMethodNames;
Method[] destroyMethods = new Method[destroyMethodNames.length];
List<Method> destroyMethods = new ArrayList<>(destroyMethodNames.length);
for (int i = 0; i < destroyMethodNames.length; i++) {
String destroyMethodName = destroyMethodNames[i];
Method destroyMethod = determineDestroyMethod(destroyMethodName);
@@ -137,10 +138,10 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
}
destroyMethod = ClassUtils.getInterfaceMethodIfPossible(destroyMethod, bean.getClass());
destroyMethods.add(destroyMethod);
}
destroyMethods[i] = destroyMethod;
}
this.destroyMethods = destroyMethods;
this.destroyMethods = destroyMethods.toArray(Method[]::new);
}
}
@@ -253,7 +254,18 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
@Nullable
private Method determineDestroyMethod(String name) {
try {
return findDestroyMethod(name);
Class<?> beanClass = this.bean.getClass();
Method destroyMethod = findDestroyMethod(beanClass, name);
if (destroyMethod != null) {
return destroyMethod;
}
for (Class<?> beanInterface : beanClass.getInterfaces()) {
destroyMethod = findDestroyMethod(beanInterface, name);
if (destroyMethod != null) {
return destroyMethod;
}
}
return null;
}
catch (IllegalArgumentException ex) {
throw new BeanDefinitionValidationException("Could not find unique destroy method on bean with name '" +
@@ -262,10 +274,10 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
@Nullable
private Method findDestroyMethod(String name) {
private Method findDestroyMethod(Class<?> clazz, String name) {
return (this.nonPublicAccessAllowed ?
BeanUtils.findMethodWithMinimalParameters(this.bean.getClass(), name) :
BeanUtils.findMethodWithMinimalParameters(this.bean.getClass().getMethods(), name));
BeanUtils.findMethodWithMinimalParameters(clazz, name) :
BeanUtils.findMethodWithMinimalParameters(clazz.getMethods(), name));
}
/**
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -205,11 +205,11 @@ abstract class AbstractPropertyAccessorTests {
kerry.setSpouse(target);
AbstractPropertyAccessor accessor = createAccessor(target);
Integer KA = (Integer) accessor.getPropertyValue("spouse.age");
assertThat(KA == 35).as("kerry is 35").isTrue();
assertThat(KA).as("kerry is 35").isEqualTo(35);
Integer RA = (Integer) accessor.getPropertyValue("spouse.spouse.age");
assertThat(RA == 31).as("rod is 31, not" + RA).isTrue();
assertThat(RA).as("rod is 31, not" + RA).isEqualTo(31);
ITestBean spousesSpouse = (ITestBean) accessor.getPropertyValue("spouse.spouse");
assertThat(target == spousesSpouse).as("spousesSpouse = initial point").isTrue();
assertThat(target).as("spousesSpouse = initial point").isSameAs(spousesSpouse);
}
@Test
@@ -236,13 +236,14 @@ abstract class AbstractPropertyAccessorTests {
}
@Test
@SuppressWarnings("unchecked")
void getPropertyIntermediateMapEntryIsNullWithAutoGrow() {
Foo target = new Foo();
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setConversionService(new DefaultConversionService());
accessor.setAutoGrowNestedPaths(true);
accessor.setPropertyValue("listOfMaps[0]['luckyNumber']", "9");
assertThat(target.listOfMaps.get(0).get("luckyNumber")).isEqualTo("9");
assertThat(target.listOfMaps.get(0)).containsEntry("luckyNumber", "9");
}
@Test
@@ -298,13 +299,14 @@ abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("spouse.company", "Lewisham");
assertThat(kerry.getName()).as("kerry name is Kerry").isEqualTo("Kerry");
assertThat(target.getSpouse() == kerry).as("nested set worked").isTrue();
assertThat(target.getSpouse()).as("nested set worked").isSameAs(kerry);
assertThat(kerry.getSpouse()).as("no back relation").isNull();
accessor.setPropertyValue(new PropertyValue("spouse.spouse", target));
assertThat(kerry.getSpouse() == target).as("nested set worked").isTrue();
assertThat(kerry.getSpouse()).as("nested set worked").isSameAs(target);
AbstractPropertyAccessor kerryAccessor = createAccessor(kerry);
assertThat("Lewisham".equals(kerryAccessor.getPropertyValue("spouse.spouse.spouse.spouse.company"))).as("spouse.spouse.spouse.spouse.company=Lewisham").isTrue();
assertThat(kerryAccessor.getPropertyValue("spouse.spouse.spouse.spouse.company")).as("spouse.spouse.spouse.spouse.company=Lewisham")
.isEqualTo("Lewisham");
}
@Test
@@ -315,13 +317,13 @@ abstract class AbstractPropertyAccessorTests {
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValue("spouse", kerry);
assertThat(target.getSpouse() == kerry).as("nested set worked").isTrue();
assertThat(target.getSpouse()).as("nested set worked").isSameAs(kerry);
assertThat(kerry.getSpouse()).as("no back relation").isNull();
accessor.setPropertyValue(new PropertyValue("spouse.spouse", target));
assertThat(kerry.getSpouse() == target).as("nested set worked").isTrue();
assertThat(kerry.getAge() == 0).as("kerry age not set").isTrue();
assertThat(kerry.getSpouse()).as("nested set worked").isSameAs(target);
assertThat(kerry.getAge()).as("kerry age not set").isEqualTo(0);
accessor.setPropertyValue(new PropertyValue("spouse.age", 35));
assertThat(kerry.getAge() == 35).as("Set primitive on spouse").isTrue();
assertThat(kerry.getAge()).as("Set primitive on spouse").isEqualTo(35);
assertThat(accessor.getPropertyValue("spouse")).isEqualTo(kerry);
assertThat(accessor.getPropertyValue("spouse.spouse")).isEqualTo(target);
@@ -359,7 +361,7 @@ abstract class AbstractPropertyAccessorTests {
accessor.getPropertyValue("spouse.bla");
}
catch (NotReadablePropertyException ex) {
assertThat(ex.getMessage().contains(TestBean.class.getName())).isTrue();
assertThat(ex.getMessage()).contains(TestBean.class.getName());
}
}
@@ -442,12 +444,12 @@ abstract class AbstractPropertyAccessorTests {
target.setAge(age);
target.setName(name);
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(target.getAge() == age).as("age is OK").isTrue();
assertThat(name.equals(target.getName())).as("name is OK").isTrue();
assertThat(target.getAge()).as("age is OK").isEqualTo(age);
assertThat(name).as("name is OK").isEqualTo(target.getName());
accessor.setPropertyValues(new MutablePropertyValues());
// Check its unchanged
assertThat(target.getAge() == age).as("age is OK").isTrue();
assertThat(name.equals(target.getName())).as("name is OK").isTrue();
assertThat(target.getAge()).as("age is OK").isEqualTo(age);
assertThat(name).as("name is OK").isEqualTo(target.getName());
}
@@ -463,9 +465,9 @@ abstract class AbstractPropertyAccessorTests {
pvs.addPropertyValue(new PropertyValue("name", newName));
pvs.addPropertyValue(new PropertyValue("touchy", newTouchy));
accessor.setPropertyValues(pvs);
assertThat(target.getName().equals(newName)).as("Name property should have changed").isTrue();
assertThat(target.getTouchy().equals(newTouchy)).as("Touchy property should have changed").isTrue();
assertThat(target.getAge() == newAge).as("Age property should have changed").isTrue();
assertThat(target.getName()).as("Name property should have changed").isEqualTo(newName);
assertThat(target.getTouchy()).as("Touchy property should have changed").isEqualTo(newTouchy);
assertThat(target.getAge()).as("Age property should have changed").isEqualTo(newAge);
}
@Test
@@ -480,7 +482,7 @@ abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue(new PropertyValue("touchy", newTouchy));
assertThat(target.getName()).as("Name property should have changed").isEqualTo(newName);
assertThat(target.getTouchy()).as("Touchy property should have changed").isEqualTo(newTouchy);
assertThat(target.getAge() == newAge).as("Age property should have changed").isTrue();
assertThat(target.getAge()).as("Age property should have changed").isEqualTo(newAge);
}
@Test
@@ -559,11 +561,11 @@ abstract class AbstractPropertyAccessorTests {
}
});
accessor.setPropertyValue("name", new String[] {});
assertThat(target.getName()).isEqualTo("");
assertThat(target.getName()).isEmpty();
accessor.setPropertyValue("name", new String[] {"a1", "b2"});
assertThat(target.getName()).isEqualTo("a1-b2");
accessor.setPropertyValue("name", null);
assertThat(target.getName()).isEqualTo("");
assertThat(target.getName()).isEmpty();
}
@Test
@@ -577,7 +579,7 @@ abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("bool2", "false");
assertThat(Boolean.FALSE.equals(accessor.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
assertThat(!target.getBool2()).as("Correct bool2 value").isTrue();
assertThat(target.getBool2()).as("Correct bool2 value").isFalse();
}
@Test
@@ -729,7 +731,7 @@ abstract class AbstractPropertyAccessorTests {
String freedomVal = target.properties.getProperty("freedom");
String peaceVal = target.properties.getProperty("peace");
assertThat(peaceVal).as("peace==war").isEqualTo("war");
assertThat(freedomVal.equals("slavery")).as("Freedom==slavery").isTrue();
assertThat(freedomVal).as("Freedom==slavery").isEqualTo("slavery");
}
@Test
@@ -1344,7 +1346,7 @@ abstract class AbstractPropertyAccessorTests {
pvs.addPropertyValue(new PropertyValue("more.garbage", new Object()));
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValues(pvs, true);
assertThat(target.getName().equals("rod")).as("Set valid and ignored invalid").isTrue();
assertThat(target.getName()).as("Set valid and ignored invalid").isEqualTo("rod");
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
accessor.setPropertyValues(pvs, false)); // Don't ignore: should fail
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ public abstract class AbstractPropertyValuesTests {
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) {
assertThat(pvs.getPropertyValues().length == 3).as("Contains 3").isTrue();
assertThat(pvs.getPropertyValues()).as("Contains 3").hasSize(3);
assertThat(pvs.contains("forname")).as("Contains forname").isTrue();
assertThat(pvs.contains("surname")).as("Contains surname").isTrue();
assertThat(pvs.contains("age")).as("Contains age").isTrue();
@@ -45,13 +45,13 @@ public abstract class AbstractPropertyValuesTests {
m.put("age", "50");
for (PropertyValue element : ps) {
Object val = m.get(element.getName());
assertThat(val != null).as("Can't have unexpected value").isTrue();
assertThat(val).as("Can't have unexpected value").isNotNull();
boolean condition = val instanceof String;
assertThat(condition).as("Val i string").isTrue();
assertThat(val.equals(element.getValue())).as("val matches expected").isTrue();
m.remove(element.getName());
}
assertThat(m.size() == 0).as("Map size is 0").isTrue();
assertThat(m).as("Map size is 0").isEmpty();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -135,7 +135,7 @@ class BeanUtilsTests {
PropertyDescriptor[] actual = Introspector.getBeanInfo(TestBean.class).getPropertyDescriptors();
PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(TestBean.class);
assertThat(descriptors).as("Descriptors should not be null").isNotNull();
assertThat(descriptors.length).as("Invalid number of descriptors returned").isEqualTo(actual.length);
assertThat(descriptors).as("Invalid number of descriptors returned").hasSameSizeAs(actual);
}
@Test
@@ -161,13 +161,13 @@ class BeanUtilsTests {
tb.setAge(32);
tb.setTouchy("touchy");
TestBean tb2 = new TestBean();
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
assertThat(tb2.getName()).as("Name empty").isNull();
assertThat(tb2.getAge()).as("Age empty").isEqualTo(0);
assertThat(tb2.getTouchy()).as("Touchy empty").isNull();
BeanUtils.copyProperties(tb, tb2);
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
assertThat(tb2.getName()).as("Name copied").isEqualTo(tb.getName());
assertThat(tb2.getAge()).as("Age copied").isEqualTo(tb.getAge());
assertThat(tb2.getTouchy()).as("Touchy copied").isEqualTo(tb.getTouchy());
}
@Test
@@ -177,13 +177,13 @@ class BeanUtilsTests {
tb.setAge(32);
tb.setTouchy("touchy");
TestBean tb2 = new TestBean();
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
assertThat(tb2.getName()).as("Name empty").isNull();
assertThat(tb2.getAge()).as("Age empty").isEqualTo(0);
assertThat(tb2.getTouchy()).as("Touchy empty").isNull();
BeanUtils.copyProperties(tb, tb2);
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
assertThat(tb2.getName()).as("Name copied").isEqualTo(tb.getName());
assertThat(tb2.getAge()).as("Age copied").isEqualTo(tb.getAge());
assertThat(tb2.getTouchy()).as("Touchy copied").isEqualTo(tb.getTouchy());
}
@Test
@@ -193,13 +193,13 @@ class BeanUtilsTests {
tb.setAge(32);
tb.setTouchy("touchy");
DerivedTestBean tb2 = new DerivedTestBean();
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
assertThat(tb2.getName()).as("Name empty").isNull();
assertThat(tb2.getAge()).as("Age empty").isEqualTo(0);
assertThat(tb2.getTouchy()).as("Touchy empty").isNull();
BeanUtils.copyProperties(tb, tb2);
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
assertThat(tb2.getName()).as("Name copied").isEqualTo(tb.getName());
assertThat(tb2.getAge()).as("Age copied").isEqualTo(tb.getAge());
assertThat(tb2.getTouchy()).as("Touchy copied").isEqualTo(tb.getTouchy());
}
/**
@@ -342,37 +342,37 @@ class BeanUtilsTests {
@Test
void copyPropertiesWithEditable() throws Exception {
TestBean tb = new TestBean();
assertThat(tb.getName() == null).as("Name empty").isTrue();
assertThat(tb.getName()).as("Name empty").isNull();
tb.setAge(32);
tb.setTouchy("bla");
TestBean tb2 = new TestBean();
tb2.setName("rod");
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
assertThat(tb2.getAge()).as("Age empty").isEqualTo(0);
assertThat(tb2.getTouchy()).as("Touchy empty").isNull();
// "touchy" should not be copied: it's not defined in ITestBean
BeanUtils.copyProperties(tb, tb2, ITestBean.class);
assertThat(tb2.getName() == null).as("Name copied").isTrue();
assertThat(tb2.getAge() == 32).as("Age copied").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy still empty").isTrue();
assertThat(tb2.getName()).as("Name copied").isNull();
assertThat(tb2.getAge()).as("Age copied").isEqualTo(32);
assertThat(tb2.getTouchy()).as("Touchy still empty").isNull();
}
@Test
void copyPropertiesWithIgnore() throws Exception {
TestBean tb = new TestBean();
assertThat(tb.getName() == null).as("Name empty").isTrue();
assertThat(tb.getName()).as("Name empty").isNull();
tb.setAge(32);
tb.setTouchy("bla");
TestBean tb2 = new TestBean();
tb2.setName("rod");
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
assertThat(tb2.getAge()).as("Age empty").isEqualTo(0);
assertThat(tb2.getTouchy()).as("Touchy empty").isNull();
// "spouse", "touchy", "age" should not be copied
BeanUtils.copyProperties(tb, tb2, "spouse", "touchy", "age");
assertThat(tb2.getName() == null).as("Name copied").isTrue();
assertThat(tb2.getAge() == 0).as("Age still empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy still empty").isTrue();
assertThat(tb2.getName()).as("Name copied").isNull();
assertThat(tb2.getAge()).as("Age still empty").isEqualTo(0);
assertThat(tb2.getTouchy()).as("Touchy still empty").isNull();
}
@Test
@@ -381,7 +381,7 @@ class BeanUtilsTests {
source.setName("name");
TestBean target = new TestBean();
BeanUtils.copyProperties(source, target, "specialProperty");
assertThat("name").isEqualTo(target.getName());
assertThat(target.getName()).isEqualTo("name");
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,15 +90,15 @@ public class BeanWrapperAutoGrowingTests {
@Test
public void getPropertyValueAutoGrow2dArray() {
assertNotNull(wrapper.getPropertyValue("multiArray[0][0]"));
assertThat(wrapper.getPropertyValue("multiArray[0][0]")).isNotNull();
assertThat(bean.getMultiArray()[0]).hasSize(1);
assertThat(bean.getMultiArray()[0][0]).isInstanceOf(Bean.class);
}
@Test
public void getPropertyValueAutoGrow3dArray() {
assertNotNull(wrapper.getPropertyValue("threeDimensionalArray[1][2][3]"));
assertThat(bean.getThreeDimensionalArray()[1].length).isEqualTo(3);
assertThat(wrapper.getPropertyValue("threeDimensionalArray[1][2][3]")).isNotNull();
assertThat(bean.getThreeDimensionalArray()[1]).hasNumberOfRows(3);
assertThat(bean.getThreeDimensionalArray()[1][2][3]).isInstanceOf(Bean.class);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -161,8 +161,8 @@ class BeanWrapperGenericsTests {
value2.add(Boolean.TRUE);
input.put("2", value2);
bw.setPropertyValue("collectionMap", input);
assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
assertThat(gb.getCollectionMap().get(2) instanceof ArrayList).isTrue();
assertThat(gb.getCollectionMap().get(1)).isInstanceOf(HashSet.class);
assertThat(gb.getCollectionMap().get(2)).isInstanceOf(ArrayList.class);
}
@Test
@@ -174,7 +174,7 @@ class BeanWrapperGenericsTests {
HashSet<Integer> value1 = new HashSet<>();
value1.add(1);
bw.setPropertyValue("collectionMap[1]", value1);
assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
assertThat(gb.getCollectionMap().get(1)).isInstanceOf(HashSet.class);
}
@Test
@@ -320,7 +320,7 @@ class BeanWrapperGenericsTests {
bw.setPropertyValue("mapOfInteger", map);
Object obj = gb.getMapOfInteger().get("testKey");
assertThat(obj instanceof Integer).isTrue();
assertThat(obj).isInstanceOf(Integer.class);
}
@Test
@@ -334,7 +334,7 @@ class BeanWrapperGenericsTests {
bw.setPropertyValue("mapOfListOfInteger", map);
Object obj = gb.getMapOfListOfInteger().get("testKey").get(0);
assertThat(obj instanceof Integer).isTrue();
assertThat(obj).isInstanceOf(Integer.class);
assertThat(((Integer) obj).intValue()).isEqualTo(1);
}
@@ -350,7 +350,7 @@ class BeanWrapperGenericsTests {
bw.setPropertyValue("listOfMapOfInteger", list);
Object obj = gb.getListOfMapOfInteger().get(0).get("testKey");
assertThat(obj instanceof Integer).isTrue();
assertThat(obj).isInstanceOf(Integer.class);
assertThat(((Integer) obj).intValue()).isEqualTo(5);
}
@@ -365,7 +365,7 @@ class BeanWrapperGenericsTests {
bw.setPropertyValue("mapOfListOfListOfInteger", map);
Object obj = gb.getMapOfListOfListOfInteger().get("testKey").get(0).get(0);
assertThat(obj instanceof Integer).isTrue();
assertThat(obj).isInstanceOf(Integer.class);
assertThat(((Integer) obj).intValue()).isEqualTo(1);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -246,16 +246,16 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
accessor.setPropertyValue("object", tb);
assertThat(target.value).isSameAs(tb);
assertThat(target.getObject().get()).isSameAs(tb);
assertThat(((Optional<TestBean>) accessor.getPropertyValue("object")).get()).isSameAs(tb);
assertThat(target.getObject()).containsSame(tb);
assertThat(((Optional<TestBean>) accessor.getPropertyValue("object"))).containsSame(tb);
assertThat(target.value.getName()).isEqualTo("x");
assertThat(target.getObject().get().getName()).isEqualTo("x");
assertThat(accessor.getPropertyValue("object.name")).isEqualTo("x");
accessor.setPropertyValue("object.name", "y");
assertThat(target.value).isSameAs(tb);
assertThat(target.getObject().get()).isSameAs(tb);
assertThat(((Optional<TestBean>) accessor.getPropertyValue("object")).get()).isSameAs(tb);
assertThat(target.getObject()).containsSame(tb);
assertThat(((Optional<TestBean>) accessor.getPropertyValue("object"))).containsSame(tb);
assertThat(target.value.getName()).isEqualTo("y");
assertThat(target.getObject().get().getName()).isEqualTo("y");
assertThat(accessor.getPropertyValue("object.name")).isEqualTo("y");
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -585,7 +585,7 @@ class ExtendedBeanInfoTests {
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
assertThat(ebi.getPropertyDescriptors()).hasSize(bi.getPropertyDescriptors().length);
assertThat(ebi.getPropertyDescriptors()).hasSameSizeAs(bi.getPropertyDescriptors());
}
@Test
@@ -711,7 +711,7 @@ class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(TestBean.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(ebi.getPropertyDescriptors()).hasSize(bi.getPropertyDescriptors().length);
assertThat(ebi.getPropertyDescriptors()).hasSameSizeAs(bi.getPropertyDescriptors());
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
pvs.addPropertyValue(new PropertyValue("age", "50"));
MutablePropertyValues pvs2 = pvs;
PropertyValues changes = pvs2.changesSince(pvs);
assertThat(changes.getPropertyValues().length == 0).as("changes are empty").isTrue();
assertThat(changes.getPropertyValues().length).as("changes are empty").isEqualTo(0);
}
@Test
@@ -82,26 +82,28 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
MutablePropertyValues pvs2 = new MutablePropertyValues(pvs);
PropertyValues changes = pvs2.changesSince(pvs);
assertThat(changes.getPropertyValues().length == 0).as("changes are empty, not of length " + changes.getPropertyValues().length).isTrue();
assertThat(changes.getPropertyValues().length).as("changes are empty, not of length " + changes.getPropertyValues().length)
.isEqualTo(0);
pvs2.addPropertyValue(new PropertyValue("forname", "Gordon"));
changes = pvs2.changesSince(pvs);
assertThat(changes.getPropertyValues().length).as("1 change").isEqualTo(1);
PropertyValue fn = changes.getPropertyValue("forname");
assertThat(fn != null).as("change is forname").isTrue();
assertThat(fn).as("change is forname").isNotNull();
assertThat(fn.getValue().equals("Gordon")).as("new value is gordon").isTrue();
MutablePropertyValues pvs3 = new MutablePropertyValues(pvs);
changes = pvs3.changesSince(pvs);
assertThat(changes.getPropertyValues().length == 0).as("changes are empty, not of length " + changes.getPropertyValues().length).isTrue();
assertThat(changes.getPropertyValues().length).as("changes are empty, not of length " + changes.getPropertyValues().length)
.isEqualTo(0);
// add new
pvs3.addPropertyValue(new PropertyValue("foo", "bar"));
pvs3.addPropertyValue(new PropertyValue("fi", "fum"));
changes = pvs3.changesSince(pvs);
assertThat(changes.getPropertyValues().length == 2).as("2 change").isTrue();
assertThat(changes.getPropertyValues().length).as("2 change").isEqualTo(2);
fn = changes.getPropertyValue("foo");
assertThat(fn != null).as("change in foo").isTrue();
assertThat(fn).as("change in foo").isNotNull();
assertThat(fn.getValue().equals("bar")).as("new value is bar").isTrue();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,8 +30,8 @@ public class PropertyAccessorUtilsTests {
@Test
public void getPropertyName() {
assertThat(PropertyAccessorUtils.getPropertyName("")).isEqualTo("");
assertThat(PropertyAccessorUtils.getPropertyName("[user]")).isEqualTo("");
assertThat(PropertyAccessorUtils.getPropertyName("")).isEmpty();
assertThat(PropertyAccessorUtils.getPropertyName("[user]")).isEmpty();
assertThat(PropertyAccessorUtils.getPropertyName("user")).isEqualTo("user");
}
@@ -69,7 +69,7 @@ public class PropertyAccessorUtilsTests {
@Test
public void canonicalPropertyName() {
assertThat(PropertyAccessorUtils.canonicalPropertyName(null)).isEqualTo("");
assertThat(PropertyAccessorUtils.canonicalPropertyName(null)).isEmpty();
assertThat(PropertyAccessorUtils.canonicalPropertyName("map")).isEqualTo("map");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map[key1]")).isEqualTo("map[key1]");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map['key1']")).isEqualTo("map[key1]");
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,7 +85,7 @@ public class BeanFactoryUtilsTests {
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
lbf.addBean("t1", new TestBean());
lbf.addBean("t2", new TestBean());
assertThat(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2).isTrue();
assertThat(BeanFactoryUtils.countBeansIncludingAncestors(lbf)).isEqualTo(2);
}
/**
@@ -94,9 +94,10 @@ public class BeanFactoryUtilsTests {
@Test
public void testHierarchicalCountBeansWithOverride() {
// Leaf count
assertThat(this.listableBeanFactory.getBeanDefinitionCount() == 1).isTrue();
assertThat(this.listableBeanFactory.getBeanDefinitionCount()).isEqualTo(1);
// Count minus duplicate
assertThat(BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory) == 8).as("Should count 8 beans, not " + BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory)).isTrue();
assertThat(BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory)).as("Should count 8 beans, not " + BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory))
.isEqualTo(8);
}
@Test
@@ -113,7 +114,7 @@ public class BeanFactoryUtilsTests {
assertThat(names).hasSize(1);
assertThat(names.contains("indexedBean")).isTrue();
// Distinguish from default ListableBeanFactory behavior
assertThat(listableBeanFactory.getBeanNamesForType(IndexedTestBean.class).length == 0).isTrue();
assertThat(listableBeanFactory.getBeanNamesForType(IndexedTestBean.class)).isEmpty();
}
@Test
@@ -288,7 +289,7 @@ public class BeanFactoryUtilsTests {
assertThat(names).hasSize(1);
assertThat(names.contains("annotatedBean")).isTrue();
// Distinguish from default ListableBeanFactory behavior
assertThat(listableBeanFactory.getBeanNamesForAnnotation(TestAnnotation.class).length == 0).isTrue();
assertThat(listableBeanFactory.getBeanNamesForAnnotation(TestAnnotation.class)).isEmpty();
}
@Test
@@ -137,7 +137,7 @@ class DefaultListableBeanFactoryTests {
KnowsIfInstantiated.clearInstantiationRecord();
Properties p = new Properties();
p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName());
assertThat(!KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isTrue();
assertThat(KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isFalse();
registerBeanDefinitions(p);
lbf.preInstantiateSingletons();
assertThat(KnowsIfInstantiated.wasInstantiated()).as("singleton was instantiated").isTrue();
@@ -149,12 +149,12 @@ class DefaultListableBeanFactoryTests {
Properties p = new Properties();
p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName());
p.setProperty("x1.(lazy-init)", "true");
assertThat(!KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isTrue();
assertThat(KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isFalse();
registerBeanDefinitions(p);
assertThat(!KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isTrue();
assertThat(KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isFalse();
lbf.preInstantiateSingletons();
assertThat(!KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isTrue();
assertThat(KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isFalse();
lbf.getBean("x1");
assertThat(KnowsIfInstantiated.wasInstantiated()).as("singleton was instantiated").isTrue();
}
@@ -166,13 +166,13 @@ class DefaultListableBeanFactoryTests {
// Reset static state
DummyFactory.reset();
p.setProperty("x1.singleton", "false");
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
registerBeanDefinitions(p);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
lbf.preInstantiateSingletons();
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
lbf.getBean("x1");
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.containsBean("x1")).isTrue();
@@ -190,7 +190,7 @@ class DefaultListableBeanFactoryTests {
p.setProperty("x1.singleton", "false");
registerBeanDefinitions(p);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
assertBeanNamesForType(TestBean.class, false, false);
assertThat(lbf.getBeanNamesForAnnotation(SuppressWarnings.class)).isEmpty();
@@ -209,7 +209,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class))).isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isEqualTo(DummyFactory.class);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
}
@Test
@@ -222,7 +222,7 @@ class DefaultListableBeanFactoryTests {
p.setProperty("x1.singleton", "true");
registerBeanDefinitions(p);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
assertBeanNamesForType(TestBean.class, false, false);
assertThat(lbf.getBeanNamesForAnnotation(SuppressWarnings.class)).isEmpty();
@@ -241,7 +241,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class))).isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isEqualTo(DummyFactory.class);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
}
@Test
@@ -253,7 +253,7 @@ class DefaultListableBeanFactoryTests {
p.setProperty("x1.singleton", "false");
registerBeanDefinitions(p);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
assertBeanNamesForType(TestBean.class, false, false);
assertThat(lbf.getBeanNamesForAnnotation(SuppressWarnings.class)).isEmpty();
@@ -272,7 +272,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class))).isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isEqualTo(DummyFactory.class);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
}
@Test
@@ -303,7 +303,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("&x1", Object.class)).isTrue();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isEqualTo(DummyFactory.class);
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
assertThat(DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isFalse();
lbf.registerAlias("x1", "x2");
assertThat(lbf.containsBean("x2")).isTrue();
@@ -449,9 +449,9 @@ class DefaultListableBeanFactoryTests {
@Test
void empty() {
assertThat(lbf.getBeanDefinitionNames() != null).as("No beans defined --> array != null").isTrue();
assertThat(lbf.getBeanDefinitionNames().length == 0).as("No beans defined after no arg constructor").isTrue();
assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after no arg constructor").isTrue();
assertThat(lbf.getBeanDefinitionNames()).as("No beans defined --> array != null").isNotNull();
assertThat(lbf.getBeanDefinitionNames()).as("No beans defined after no arg constructor").isEmpty();
assertThat(lbf.getBeanDefinitionCount()).as("No beans defined after no arg constructor").isEqualTo(0);
}
@Test
@@ -459,7 +459,7 @@ class DefaultListableBeanFactoryTests {
Properties p = new Properties();
registerBeanDefinitions(p);
assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after ignorable invalid").isTrue();
assertThat(lbf.getBeanDefinitionCount()).as("No beans defined after ignorable invalid").isEqualTo(0);
}
@Test
@@ -469,7 +469,7 @@ class DefaultListableBeanFactoryTests {
p.setProperty("qwert", "er");
registerBeanDefinitions(p, "test");
assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after harmless ignorable rubbish").isTrue();
assertThat(lbf.getBeanDefinitionCount()).as("No beans defined after harmless ignorable rubbish").isEqualTo(0);
}
@Test
@@ -480,7 +480,7 @@ class DefaultListableBeanFactoryTests {
p.setProperty("test.age", "48");
int count = registerBeanDefinitions(p);
assertThat(count == 1).as("1 beans registered, not " + count).isTrue();
assertThat(count).as("1 beans registered, not " + count).isEqualTo(1);
testPropertiesPopulation(lbf);
}
@@ -493,7 +493,7 @@ class DefaultListableBeanFactoryTests {
p.setProperty(PREFIX + "test.age", "0x30");
int count = registerBeanDefinitions(p, PREFIX);
assertThat(count == 1).as("1 beans registered, not " + count).isTrue();
assertThat(count).as("1 beans registered, not " + count).isEqualTo(1);
testPropertiesPopulation(lbf);
}
@@ -524,13 +524,13 @@ class DefaultListableBeanFactoryTests {
p.setProperty(PREFIX + "kerry.spouse(ref)", "rod");
int count = registerBeanDefinitions(p, PREFIX);
assertThat(count == 2).as("2 beans registered, not " + count).isTrue();
assertThat(count).as("2 beans registered, not " + count).isEqualTo(2);
TestBean kerry = lbf.getBean("kerry", TestBean.class);
assertThat("Kerry".equals(kerry.getName())).as("Kerry name is Kerry").isTrue();
assertThat(kerry.getName()).as("Kerry name is Kerry").isEqualTo("Kerry");
ITestBean spouse = kerry.getSpouse();
assertThat(spouse != null).as("Kerry spouse is non null").isTrue();
assertThat("Rod".equals(spouse.getName())).as("Kerry spouse name is Rod").isTrue();
assertThat(spouse).as("Kerry spouse is non null").isNotNull();
assertThat(spouse.getName()).as("Kerry spouse name is Rod").isEqualTo("Rod");
}
@Test
@@ -541,7 +541,7 @@ class DefaultListableBeanFactoryTests {
p.setProperty("tb.someMap[my.key]", "my.value");
int count = registerBeanDefinitions(p);
assertThat(count == 1).as("1 beans registered, not " + count).isTrue();
assertThat(count).as("1 beans registered, not " + count).isEqualTo(1);
assertThat(lbf.getBeanDefinitionCount()).isEqualTo(1);
TestBean tb = lbf.getBean("tb", TestBean.class);
@@ -682,8 +682,8 @@ class DefaultListableBeanFactoryTests {
registerBeanDefinitions(p);
TestBean kerry1 = (TestBean) lbf.getBean("kerry");
TestBean kerry2 = (TestBean) lbf.getBean("kerry");
assertThat(kerry1 != null).as("Non null").isTrue();
assertThat(kerry1 == kerry2).as("Singletons equal").isTrue();
assertThat(kerry1).as("Non null").isNotNull();
assertThat(kerry1).as("Singletons equal").isSameAs(kerry2);
p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
@@ -692,8 +692,8 @@ class DefaultListableBeanFactoryTests {
registerBeanDefinitions(p);
kerry1 = (TestBean) lbf.getBean("kerry");
kerry2 = (TestBean) lbf.getBean("kerry");
assertThat(kerry1 != null).as("Non null").isTrue();
assertThat(kerry1 != kerry2).as("Prototypes NOT equal").isTrue();
assertThat(kerry1).as("Non null").isNotNull();
assertThat(kerry1).as("Prototypes NOT equal").isNotSameAs(kerry2);
p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
@@ -702,8 +702,8 @@ class DefaultListableBeanFactoryTests {
registerBeanDefinitions(p);
kerry1 = (TestBean) lbf.getBean("kerry");
kerry2 = (TestBean) lbf.getBean("kerry");
assertThat(kerry1 != null).as("Non null").isTrue();
assertThat(kerry1 == kerry2).as("Specified singletons equal").isTrue();
assertThat(kerry1).as("Non null").isNotNull();
assertThat(kerry1).as("Specified singletons equal").isSameAs(kerry2);
}
@Test
@@ -737,7 +737,7 @@ class DefaultListableBeanFactoryTests {
TestBean kerry2 = (TestBean) lbf.getBean("kerry");
assertThat(kerry1.getName()).isEqualTo("kerry");
assertThat(kerry1).as("Non null").isNotNull();
assertThat(kerry1 == kerry2).as("Singletons equal").isTrue();
assertThat(kerry1).as("Singletons equal").isSameAs(kerry2);
p = new Properties();
p.setProperty("wife.(class)", TestBean.class.getName());
@@ -750,8 +750,8 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isSingleton("kerry")).isFalse();
kerry1 = (TestBean) lbf.getBean("kerry");
kerry2 = (TestBean) lbf.getBean("kerry");
assertThat(kerry1 != null).as("Non null").isTrue();
assertThat(kerry1 != kerry2).as("Prototypes NOT equal").isTrue();
assertThat(kerry1).as("Non null").isNotNull();
assertThat(kerry1).as("Prototypes NOT equal").isNotSameAs(kerry2);
p = new Properties();
p.setProperty("kerry.(class)", TestBean.class.getName());
@@ -760,8 +760,8 @@ class DefaultListableBeanFactoryTests {
registerBeanDefinitions(p);
kerry1 = (TestBean) lbf.getBean("kerry");
kerry2 = (TestBean) lbf.getBean("kerry");
assertThat(kerry1 != null).as("Non null").isTrue();
assertThat(kerry1 == kerry2).as("Specified singletons equal").isTrue();
assertThat(kerry1).as("Non null").isNotNull();
assertThat(kerry1).as("Specified singletons equal").isSameAs(kerry2);
}
@Test
@@ -790,6 +790,32 @@ class DefaultListableBeanFactoryTests {
assertThat(mergedBeanDefinition1).as("Use cached merged bean definition").isSameAs(mergedBeanDefinition2);
}
@Test
void hintAtPossibleDuplicateArgumentsInParentAndChildWhenMixingIndexAndNamed() {
final String EXPECTED_NAME = "Juergen";
final int EXPECTED_AGE = 41;
RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
parentDefinition.setAbstract(true);
parentDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, EXPECTED_NAME);
ChildBeanDefinition childDefinition = new ChildBeanDefinition("parent");
childDefinition.getConstructorArgumentValues().addGenericArgumentValue(new ConstructorArgumentValues.ValueHolder(EXPECTED_NAME, null, "name"));
childDefinition.getConstructorArgumentValues().addGenericArgumentValue(new ConstructorArgumentValues.ValueHolder(EXPECTED_AGE, null, "age"));
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("parent", parentDefinition);
factory.registerBeanDefinition("child", childDefinition);
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> factory.getBean("child", TestBean.class))
.withMessage("Error creating bean with name 'child': Could not resolve matching constructor on bean class " +
"[org.springframework.beans.testfixture.beans.TestBean] (hint: specify index/type/name arguments " +
"for simple parameters to avoid type ambiguities. " +
"You should also check the consistency of arguments when mixing indexed and named arguments, " +
"especially in case of bean definition inheritance)");
}
@Test
void getTypeWorksAfterParentChildMerging() {
RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
@@ -972,7 +998,7 @@ class DefaultListableBeanFactoryTests {
TestBean k = (TestBean) lbf.getBean("k");
TestBean r = (TestBean) lbf.getBean("r");
assertThat(k.getSpouse() == r).isTrue();
assertThat(k.getSpouse()).isSameAs(r);
}
@Test
@@ -984,7 +1010,7 @@ class DefaultListableBeanFactoryTests {
registerBeanDefinitions(p);
TestBean r = (TestBean) lbf.getBean("r");
assertThat(r.getName().equals(name)).isTrue();
assertThat(r.getName()).isEqualTo(name);
}
@Test
@@ -1000,7 +1026,7 @@ class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("testBean", bd);
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertThat(testBean.getMyFloat() == 1.1f).isTrue();
assertThat(testBean.getMyFloat()).isEqualTo(1.1f);
}
@Test
@@ -1024,7 +1050,7 @@ class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("testBean", bd);
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertThat(testBean.getMyFloat() == 1.1f).isTrue();
assertThat(testBean.getMyFloat()).isEqualTo(1.1f);
}
@Test
@@ -1041,7 +1067,7 @@ class DefaultListableBeanFactoryTests {
lbf.registerSingleton("myFloat", "1,1");
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertThat(testBean.getMyFloat() == 1.1f).isTrue();
assertThat(testBean.getMyFloat()).isEqualTo(1.1f);
}
@Test
@@ -1058,7 +1084,7 @@ class DefaultListableBeanFactoryTests {
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertThat(testBean.getName()).isEqualTo("myName");
assertThat(testBean.getAge()).isEqualTo(5);
assertThat(testBean.getMyFloat() == 1.1f).isTrue();
assertThat(testBean.getMyFloat()).isEqualTo(1.1f);
}
@Test
@@ -1076,7 +1102,7 @@ class DefaultListableBeanFactoryTests {
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertThat(testBean.getName()).isEqualTo("myName");
assertThat(testBean.getAge()).isEqualTo(5);
assertThat(testBean.getMyFloat() == 1.1f).isTrue();
assertThat(testBean.getMyFloat()).isEqualTo(1.1f);
}
@Test
@@ -1300,7 +1326,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.getBeanDefinitionCount()).isEqualTo(1);
Object registered = lbf.autowire(NoDependencies.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertThat(lbf.getBeanDefinitionCount()).isEqualTo(1);
assertThat(registered instanceof NoDependencies).isTrue();
assertThat(registered).isInstanceOf(NoDependencies.class);
}
@Test
@@ -1371,8 +1397,8 @@ class DefaultListableBeanFactoryTests {
lbf.autowire(ConstructorDependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
Object spouse = lbf.getBean("spouse");
assertThat(bean.getSpouse1() == spouse).isTrue();
assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse).isTrue();
assertThat(bean.getSpouse1()).isSameAs(spouse);
assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class)).isSameAs(spouse);
}
@Test
@@ -1384,7 +1410,7 @@ class DefaultListableBeanFactoryTests {
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertThat(bean.getSpouse()).isEqualTo(spouse);
assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse).isTrue();
assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class)).isSameAs(spouse);
}
@Test
@@ -2248,7 +2274,7 @@ class DefaultListableBeanFactoryTests {
for (int i = 0; i < 1000; i++) {
TestBean bean = (TestBean) lbf.getBean("bean" + i);
TestBean otherBean = (TestBean) lbf.getBean("bean" + (i < 99 ? i + 1 : 0));
assertThat(bean.getSpouse() == otherBean).isTrue();
assertThat(bean.getSpouse()).isSameAs(otherBean);
}
}
@@ -2350,8 +2376,8 @@ class DefaultListableBeanFactoryTests {
factory.registerBeanDefinition("tb2", bd2);
factory.registerBeanDefinition("tb3", new RootBeanDefinition(TestBean.class));
assertThat(((AbstractBeanDefinition) factory.getMergedBeanDefinition("tb1")).getLazyInit()).isEqualTo(Boolean.TRUE);
assertThat(((AbstractBeanDefinition) factory.getMergedBeanDefinition("tb2")).getLazyInit()).isEqualTo(Boolean.FALSE);
assertThat(((AbstractBeanDefinition) factory.getMergedBeanDefinition("tb1")).getLazyInit()).isTrue();
assertThat(((AbstractBeanDefinition) factory.getMergedBeanDefinition("tb2")).getLazyInit()).isFalse();
assertThat(((AbstractBeanDefinition) factory.getMergedBeanDefinition("tb3")).getLazyInit()).isNull();
factory.preInstantiateSingletons();
@@ -2405,7 +2431,7 @@ class DefaultListableBeanFactoryTests {
assertThat(tb.getBeanName()).isEqualTo("myBeanName");
DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
assertThat(tb != tb2).isTrue();
assertThat(tb).isNotSameAs(tb2);
assertThat(tb2.getName()).isEqualTo("myName");
assertThat(tb2.getBeanName()).isEqualTo("myBeanName");
}
@@ -2424,7 +2450,7 @@ class DefaultListableBeanFactoryTests {
assertThat(tb.getBeanName()).isEqualTo("myBeanName");
DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
assertThat(tb != tb2).isTrue();
assertThat(tb).isNotSameAs(tb2);
assertThat(tb2.getName()).isEqualTo("myName");
assertThat(tb2.getBeanName()).isEqualTo("myBeanName");
}
@@ -2747,7 +2773,7 @@ class DefaultListableBeanFactoryTests {
bd.setFactoryMethodName("empty");
lbf.registerBeanDefinition("optionalBean", bd);
assertThat((Optional<?>) lbf.getBean(Optional.class)).isSameAs(Optional.empty());
assertThat((Optional<?>) lbf.getBean(Optional.class)).isEmpty();
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -494,7 +494,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalFieldInjectionBean bean = (OptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean()).isPresent();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@@ -503,7 +503,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalFieldInjectionBean.class));
OptionalFieldInjectionBean bean = (OptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isFalse();
assertThat(bean.getTestBean()).isNotPresent();
}
@Test
@@ -512,7 +512,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalMethodInjectionBean bean = (OptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean()).isPresent();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@@ -521,7 +521,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalMethodInjectionBean.class));
OptionalMethodInjectionBean bean = (OptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isFalse();
assertThat(bean.getTestBean()).isNotPresent();
}
@Test
@@ -530,7 +530,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalListFieldInjectionBean bean = (OptionalListFieldInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean()).isPresent();
assertThat(bean.getTestBean().get().get(0)).isSameAs(bf.getBean("testBean"));
}
@@ -539,7 +539,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListFieldInjectionBean.class));
OptionalListFieldInjectionBean bean = (OptionalListFieldInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isFalse();
assertThat(bean.getTestBean()).isNotPresent();
}
@Test
@@ -548,7 +548,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean()).isPresent();
assertThat(bean.getTestBean().get().get(0)).isSameAs(bf.getBean("testBean"));
}
@@ -557,7 +557,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListMethodInjectionBean.class));
OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isFalse();
assertThat(bean.getTestBean()).isNotPresent();
}
@Test
@@ -566,7 +566,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
ProviderOfOptionalFieldInjectionBean bean = (ProviderOfOptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean()).isPresent();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@@ -575,7 +575,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalFieldInjectionBean.class));
ProviderOfOptionalFieldInjectionBean bean = (ProviderOfOptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isFalse();
assertThat(bean.getTestBean()).isNotPresent();
}
@Test
@@ -584,7 +584,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
ProviderOfOptionalMethodInjectionBean bean = (ProviderOfOptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean()).isPresent();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@@ -593,7 +593,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalMethodInjectionBean.class));
ProviderOfOptionalMethodInjectionBean bean = (ProviderOfOptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.getTestBean().isPresent()).isFalse();
assertThat(bean.getTestBean()).isNotPresent();
}
@Test
@@ -406,7 +406,7 @@ class BeanDefinitionMethodGeneratorTests {
compile(method, (actual, compiled) -> {
ManagedList<RootBeanDefinition> actualPropertyValue = (ManagedList<RootBeanDefinition>) actual
.getPropertyValues().get("someList");
assertThat(actualPropertyValue).isNotNull().hasSize(2);
assertThat(actualPropertyValue).hasSize(2);
assertThat(actualPropertyValue.get(0).getPropertyValues().get("name")).isEqualTo("one");
assertThat(actualPropertyValue.get(1).getPropertyValues().get("name")).isEqualTo("two");
assertThat(compiled.getSourceFileFromPackage(TestBean.class.getPackageName()))
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.beans.factory.aot;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
@@ -31,7 +30,9 @@ import org.springframework.aot.generate.ClassNameGenerator;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.generate.MethodReference;
import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.test.generate.TestGenerationContext;
import org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.Registration;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -47,7 +48,7 @@ import org.springframework.javapoet.MethodSpec;
import org.springframework.javapoet.ParameterizedTypeName;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.Registration;
import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection;
/**
* Tests for {@link BeanRegistrationsAotContribution}.
@@ -55,35 +56,25 @@ import static org.springframework.beans.factory.aot.BeanRegistrationsAotContribu
* @author Phillip Webb
* @author Sebastien Deleuze
* @author Stephane Nicoll
* @author Brian Clozel
*/
class BeanRegistrationsAotContributionTests {
private final DefaultListableBeanFactory beanFactory;
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
private final BeanDefinitionMethodGeneratorFactory methodGeneratorFactory;
private final BeanDefinitionMethodGeneratorFactory methodGeneratorFactory = new BeanDefinitionMethodGeneratorFactory(
AotServices.factoriesAndBeans(new MockSpringFactoriesLoader(), this.beanFactory));
private TestGenerationContext generationContext;
private TestGenerationContext generationContext = new TestGenerationContext();
private MockBeanFactoryInitializationCode beanFactoryInitializationCode;
BeanRegistrationsAotContributionTests() {
MockSpringFactoriesLoader springFactoriesLoader = new MockSpringFactoriesLoader();
this.beanFactory = new DefaultListableBeanFactory();
this.methodGeneratorFactory = new BeanDefinitionMethodGeneratorFactory(
AotServices.factoriesAndBeans(springFactoriesLoader, this.beanFactory));
this.generationContext = new TestGenerationContext();
this.beanFactoryInitializationCode = new MockBeanFactoryInitializationCode(this.generationContext);
}
private MockBeanFactoryInitializationCode beanFactoryInitializationCode = new MockBeanFactoryInitializationCode(this.generationContext);
@Test
void applyToAppliesContribution() {
RegisteredBean registeredBean = registerBean(
new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(
this.methodGeneratorFactory, registeredBean, null,
Collections.emptyList());
RegisteredBean registeredBean = registerBean(new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory,
registeredBean, null, List.of());
BeanRegistrationsAotContribution contribution = createContribution(generator);
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
compile((consumer, compiled) -> {
@@ -95,11 +86,9 @@ class BeanRegistrationsAotContributionTests {
@Test
void applyToAppliesContributionWithAliases() {
RegisteredBean registeredBean = registerBean(
new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(
this.methodGeneratorFactory, registeredBean, null,
Collections.emptyList());
RegisteredBean registeredBean = registerBean(new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory,
registeredBean, null, List.of());
BeanRegistrationsAotContribution contribution = createContribution(generator, "testAlias");
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
compile((consumer, compiled) -> {
@@ -114,11 +103,9 @@ class BeanRegistrationsAotContributionTests {
this.generationContext = new TestGenerationContext(
new ClassNameGenerator(TestGenerationContext.TEST_TARGET, "Management"));
this.beanFactoryInitializationCode = new MockBeanFactoryInitializationCode(this.generationContext);
RegisteredBean registeredBean = registerBean(
new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(
this.methodGeneratorFactory, registeredBean, null,
Collections.emptyList());
RegisteredBean registeredBean = registerBean(new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory,
registeredBean, null, List.of());
BeanRegistrationsAotContribution contribution = createContribution(generator);
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
compile((consumer, compiled) -> {
@@ -130,19 +117,15 @@ class BeanRegistrationsAotContributionTests {
@Test
void applyToCallsRegistrationsWithBeanRegistrationsCode() {
List<BeanRegistrationsCode> beanRegistrationsCodes = new ArrayList<>();
RegisteredBean registeredBean = registerBean(
new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(
this.methodGeneratorFactory, registeredBean, null,
Collections.emptyList()) {
RegisteredBean registeredBean = registerBean(new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory,
registeredBean, null, List.of()) {
@Override
MethodReference generateBeanDefinitionMethod(
GenerationContext generationContext,
MethodReference generateBeanDefinitionMethod(GenerationContext generationContext,
BeanRegistrationsCode beanRegistrationsCode) {
beanRegistrationsCodes.add(beanRegistrationsCode);
return super.generateBeanDefinitionMethod(generationContext,
beanRegistrationsCode);
return super.generateBeanDefinitionMethod(generationContext, beanRegistrationsCode);
}
};
@@ -153,6 +136,18 @@ class BeanRegistrationsAotContributionTests {
assertThat(actual.getMethods()).isNotNull();
}
@Test
void applyToRegisterReflectionHints() {
RegisteredBean registeredBean = registerBean(new RootBeanDefinition(TestBean.class));
BeanDefinitionMethodGenerator generator = new BeanDefinitionMethodGenerator(this.methodGeneratorFactory,
registeredBean, null, List.of());
BeanRegistrationsAotContribution contribution = createContribution(generator);
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
assertThat(reflection().onType(TestBean.class)
.withMemberCategory(MemberCategory.INTROSPECT_DECLARED_METHODS))
.accepts(this.generationContext.getRuntimeHints());
}
private RegisteredBean registerBean(RootBeanDefinition rootBeanDefinition) {
String beanName = "testBean";
this.beanFactory.registerBeanDefinition(beanName, rootBeanDefinition);
@@ -160,12 +155,9 @@ class BeanRegistrationsAotContributionTests {
}
@SuppressWarnings({ "unchecked", "cast" })
private void compile(
BiConsumer<Consumer<DefaultListableBeanFactory>, Compiled> result) {
MethodReference beanRegistrationsMethodReference = this.beanFactoryInitializationCode
.getInitializers().get(0);
MethodReference aliasesMethodReference = this.beanFactoryInitializationCode
.getInitializers().get(1);
private void compile(BiConsumer<Consumer<DefaultListableBeanFactory>, Compiled> result) {
MethodReference beanRegistrationsMethodReference = this.beanFactoryInitializationCode.getInitializers().get(0);
MethodReference aliasesMethodReference = this.beanFactoryInitializationCode.getInitializers().get(1);
this.beanFactoryInitializationCode.getTypeBuilder().set(type -> {
ArgumentCodeGenerator beanFactory = ArgumentCodeGenerator.of(DefaultListableBeanFactory.class, "beanFactory");
ClassName className = this.beanFactoryInitializationCode.getClassName();
@@ -173,7 +165,8 @@ class BeanRegistrationsAotContributionTests {
CodeBlock aliasesMethodInvocation = aliasesMethodReference.toInvokeCodeBlock(beanFactory, className);
type.addModifiers(Modifier.PUBLIC);
type.addSuperinterface(ParameterizedTypeName.get(Consumer.class, DefaultListableBeanFactory.class));
type.addMethod(MethodSpec.methodBuilder("accept").addModifiers(Modifier.PUBLIC)
type.addMethod(MethodSpec.methodBuilder("accept")
.addModifiers(Modifier.PUBLIC)
.addParameter(DefaultListableBeanFactory.class, "beanFactory")
.addStatement(beanRegistrationsMethodInvocation)
.addStatement(aliasesMethodInvocation)
@@ -186,7 +179,8 @@ class BeanRegistrationsAotContributionTests {
private BeanRegistrationsAotContribution createContribution(
BeanDefinitionMethodGenerator methodGenerator,String... aliases) {
return new BeanRegistrationsAotContribution(Map.of("testBean", new Registration(methodGenerator, aliases)));
return new BeanRegistrationsAotContribution(
Map.of(new BeanRegistrationKey("testBean", TestBean.class), new Registration(methodGenerator, aliases)));
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ class BeanRegistrationsAotProcessorTests {
BeanRegistrationsAotContribution contribution = processor
.processAheadOfTime(beanFactory);
assertThat(contribution).extracting("registrations")
.asInstanceOf(InstanceOfAssertFactories.MAP).containsKeys("b1", "b2");
.asInstanceOf(InstanceOfAssertFactories.MAP).hasSize(2);
}
@Test
@@ -63,7 +63,7 @@ class BeanRegistrationsAotProcessorTests {
BeanRegistrationsAotContribution contribution = processor
.processAheadOfTime(beanFactory);
assertThat(contribution).extracting("registrations").asInstanceOf(InstanceOfAssertFactories.MAP)
.hasEntrySatisfying("test", registration ->
.hasEntrySatisfying(new BeanRegistrationKey("test", TestBean.class), registration ->
assertThat(registration).extracting("aliases").asInstanceOf(InstanceOfAssertFactories.ARRAY)
.singleElement().isEqualTo("testAlias"));
}
@@ -67,7 +67,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) objectFactory.getObject();
Date date2 = (Date) objectFactory.getObject();
assertThat(date1 != date2).isTrue();
assertThat(date1).isNotSameAs(date2);
}
@Test
@@ -79,7 +79,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) objectFactory.getObject();
Date date2 = (Date) objectFactory.getObject();
assertThat(date1 != date2).isTrue();
assertThat(date1).isNotSameAs(date2);
}
@Test
@@ -89,7 +89,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) provider.get();
Date date2 = (Date) provider.get();
assertThat(date1 != date2).isTrue();
assertThat(date1).isNotSameAs(date2);
}
@Test
@@ -101,7 +101,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) provider.get();
Date date2 = (Date) provider.get();
assertThat(date1 != date2).isTrue();
assertThat(date1).isNotSameAs(date2);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -138,7 +138,7 @@ public class PropertiesFactoryBeanTests {
assertThat(props.getProperty("tb.array[0].age")).isEqualTo("99");
assertThat(props.getProperty("key2")).isEqualTo("value2");
Properties newProps = pfb.getObject();
assertThat(props != newProps).isTrue();
assertThat(props).isNotSameAs(newProps);
assertThat(newProps.getProperty("tb.array[0].age")).isEqualTo("99");
assertThat(newProps.getProperty("key2")).isEqualTo("value2");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ public class PropertyPathFactoryBeanTests {
Object result2 = xbf.getBean("otb.spouse");
boolean condition = result1 instanceof TestBean;
assertThat(condition).isTrue();
assertThat(result1 == result2).isTrue();
assertThat(result1).isSameAs(result2);
assertThat(((TestBean) result1).getAge()).isEqualTo(99);
}
@@ -73,9 +73,9 @@ public class PropertyPathFactoryBeanTests {
assertThat(((TestBean) result1).getAge()).isEqualTo(11);
assertThat(((TestBean) result2).getAge()).isEqualTo(11);
assertThat(((TestBean) result3).getAge()).isEqualTo(11);
assertThat(result1 != result2).isTrue();
assertThat(result1 != result3).isTrue();
assertThat(result2 != result3).isTrue();
assertThat(result1).isNotSameAs(result2);
assertThat(result1).isNotSameAs(result3);
assertThat(result2).isNotSameAs(result3);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -276,7 +276,7 @@ public class PropertyResourceConfigurerTests {
}
catch (BeanInitializationException ex) {
// prove that the processor chokes on the invalid key
assertThat(ex.getMessage().toLowerCase().contains("argh")).isTrue();
assertThat(ex.getMessage().toLowerCase()).contains("argh");
}
}
}
@@ -165,7 +165,7 @@ public class ServiceLocatorFactoryBeanTests {
assertThat(testBean4).isNotSameAs(testBean2);
assertThat(testBean4).isNotSameAs(testBean3);
assertThat(factory.toString().contains("TestServiceLocator3")).isTrue();
assertThat(factory.toString()).contains("TestServiceLocator3");
}
@Disabled @Test // worked when using an ApplicationContext (see commented), fails when using BeanFactory
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -180,7 +180,7 @@ class YamlPropertiesFactoryBeanTests {
factory.setResources(new ByteArrayResource("foo: bar\nspam:".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo")).isEqualTo("bar");
assertThat(properties.getProperty("spam")).isEqualTo("");
assertThat(properties.getProperty("spam")).isEmpty();
}
@Test
@@ -189,7 +189,7 @@ class YamlPropertiesFactoryBeanTests {
factory.setResources(new ByteArrayResource("a: alpha\ntest: []".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("a")).isEqualTo("alpha");
assertThat(properties.getProperty("test")).isEqualTo("");
assertThat(properties.getProperty("test")).isEmpty();
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ public class CustomProblemReporterTests {
@Test
public void testErrorsAreCollated() {
this.reader.loadBeanDefinitions(qualifiedResource(CustomProblemReporterTests.class, "context.xml"));
assertThat(this.problemReporter.getErrors().length).as("Incorrect number of errors collated").isEqualTo(4);
assertThat(this.problemReporter.getErrors()).as("Incorrect number of errors collated").hasSize(4);
TestBean bean = (TestBean) this.beanFactory.getBean("validBean");
assertThat(bean).isNotNull();
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class BeanDefinitionTests {
otherBd.setScope("request");
assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue();
assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
}
@Test
@@ -66,7 +66,7 @@ public class BeanDefinitionTests {
otherBd.getPropertyValues().add("age", "99");
assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue();
assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
}
@Test
@@ -88,7 +88,7 @@ public class BeanDefinitionTests {
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5);
assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue();
assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
}
@Test
@@ -111,7 +111,7 @@ public class BeanDefinitionTests {
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "long");
assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue();
assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
}
@Test
@@ -132,17 +132,17 @@ public class BeanDefinitionTests {
otherBd.setParentName("parent");
assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue();
assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
bd.getPropertyValues();
assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue();
assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
bd.getConstructorArgumentValues();
assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue();
assertThat(bd.hashCode() == otherBd.hashCode()).isTrue();
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
}
@Test
@@ -163,7 +163,7 @@ public class BeanDefinitionTests {
BeanDefinitionHolder otherHolder = new BeanDefinitionHolder(bd, "bd");
assertThat(holder.equals(otherHolder)).isTrue();
assertThat(otherHolder.equals(holder)).isTrue();
assertThat(holder.hashCode() == otherHolder.hashCode()).isTrue();
assertThat(holder.hashCode()).isEqualTo(otherHolder.hashCode());
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ public class ManagedMapTests {
ManagedMap child = ManagedMap.ofEntries(Map.entry("tree", "three"));
child.setMergeEnabled(true);
Map mergedMap = (Map) child.merge(parent);
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(3);
assertThat(mergedMap).as("merge() obviously did not work.").hasSize(3);
}
@Test
@@ -70,7 +70,7 @@ public class ManagedMapTests {
ManagedMap child = new ManagedMap();
child.setMergeEnabled(true);
Map mergedMap = (Map) child.merge(parent);
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(2);
assertThat(mergedMap).as("merge() obviously did not work.").hasSize(2);
}
@Test
@@ -81,7 +81,7 @@ public class ManagedMapTests {
child.setMergeEnabled(true);
Map mergedMap = (Map) child.merge(parent);
// child value for 'one' must override parent value...
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(2);
assertThat(mergedMap).as("merge() obviously did not work.").hasSize(2);
assertThat(mergedMap.get("one")).as("Parent value not being overridden during merge().").isEqualTo("fork");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
public class ManagedPropertiesTests {
@Test
@SuppressWarnings("unchecked")
public void mergeSunnyDay() {
ManagedProperties parent = new ManagedProperties();
parent.setProperty("one", "one");
@@ -41,7 +42,7 @@ public class ManagedPropertiesTests {
child.setProperty("three", "three");
child.setMergeEnabled(true);
Map mergedMap = (Map) child.merge(parent);
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(3);
assertThat(mergedMap).as("merge() obviously did not work.").hasSize(3);
}
@Test
@@ -67,6 +68,7 @@ public class ManagedPropertiesTests {
}
@Test
@SuppressWarnings("unchecked")
public void mergeEmptyChild() {
ManagedProperties parent = new ManagedProperties();
parent.setProperty("one", "one");
@@ -74,10 +76,11 @@ public class ManagedPropertiesTests {
ManagedProperties child = new ManagedProperties();
child.setMergeEnabled(true);
Map mergedMap = (Map) child.merge(parent);
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(2);
assertThat(mergedMap).as("merge() obviously did not work.").hasSize(2);
}
@Test
@SuppressWarnings("unchecked")
public void mergeChildValuesOverrideTheParents() {
ManagedProperties parent = new ManagedProperties();
parent.setProperty("one", "one");
@@ -87,7 +90,7 @@ public class ManagedPropertiesTests {
child.setMergeEnabled(true);
Map mergedMap = (Map) child.merge(parent);
// child value for 'one' must override parent value...
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(2);
assertThat(mergedMap).as("merge() obviously did not work.").hasSize(2);
assertThat(mergedMap.get("one")).as("Parent value not being overridden during merge().").isEqualTo("fork");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,8 +73,8 @@ public class Spr8954Tests {
@SuppressWarnings("rawtypes")
Map<String, FactoryBean> fbBeans = bf.getBeansOfType(FactoryBean.class);
assertThat(1).isEqualTo(fbBeans.size());
assertThat("&foo").isEqualTo(fbBeans.keySet().iterator().next());
assertThat(fbBeans.size()).isEqualTo(1);
assertThat(fbBeans.keySet().iterator().next()).isEqualTo("&foo");
Map<String, AnInterface> aiBeans = bf.getBeansOfType(AnInterface.class);
assertThat(aiBeans).hasSize(1);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,13 +56,13 @@ public class BeanNameGenerationTests {
GeneratedNameBean child1 = topLevel1.getChild();
assertThat(child1.getBeanName()).isNotNull();
assertThat(child1.getBeanName().startsWith(className)).isTrue();
assertThat(child1.getBeanName()).startsWith(className);
GeneratedNameBean child2 = topLevel2.getChild();
assertThat(child2.getBeanName()).isNotNull();
assertThat(child2.getBeanName().startsWith(className)).isTrue();
assertThat(child2.getBeanName()).startsWith(className);
assertThat(child1.getBeanName().equals(child2.getBeanName())).isFalse();
assertThat(child1.getBeanName()).isNotEqualTo(child2.getBeanName());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,8 +53,8 @@ public class CollectionMergingTests {
@Test
public void mergeList() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithList");
List list = bean.getSomeList();
assertThat(list.size()).as("Incorrect size").isEqualTo(3);
List<?> list = bean.getSomeList();
assertThat(list).as("Incorrect size").hasSize(3);
assertThat(list.get(0)).isEqualTo("Rob Harrop");
assertThat(list.get(1)).isEqualTo("Rod Johnson");
assertThat(list.get(2)).isEqualTo("Juergen Hoeller");
@@ -66,16 +66,14 @@ public class CollectionMergingTests {
List<?> list = bean.getSomeList();
assertThat(list).isNotNull();
assertThat(list).hasSize(3);
assertThat(list.get(2)).isNotNull();
boolean condition = list.get(2) instanceof TestBean;
assertThat(condition).isTrue();
assertThat(list.get(2) instanceof TestBean).isTrue();
}
@Test
public void mergeSet() {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSet");
Set set = bean.getSomeSet();
assertThat(set.size()).as("Incorrect size").isEqualTo(2);
Set<?> set = bean.getSomeSet();
assertThat(set).as("Incorrect size").hasSize(2);
assertThat(set.contains("Rob Harrop")).isTrue();
assertThat(set.contains("Sally Greenwood")).isTrue();
}
@@ -89,17 +87,15 @@ public class CollectionMergingTests {
Iterator it = set.iterator();
it.next();
Object o = it.next();
assertThat(o).isNotNull();
boolean condition = o instanceof TestBean;
assertThat(condition).isTrue();
assertThat(o instanceof TestBean).isTrue();
assertThat(((TestBean) o).getName()).isEqualTo("Sally");
}
@Test
public void mergeMap() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMap");
Map map = bean.getSomeMap();
assertThat(map.size()).as("Incorrect size").isEqualTo(3);
Map<?, ?> map = bean.getSomeMap();
assertThat(map).as("Incorrect size").hasSize(3);
assertThat(map.get("Rob")).isEqualTo("Sally");
assertThat(map.get("Rod")).isEqualTo("Kerry");
assertThat(map.get("Juergen")).isEqualTo("Eva");
@@ -112,8 +108,7 @@ public class CollectionMergingTests {
assertThat(map).isNotNull();
assertThat(map).hasSize(2);
assertThat(map.get("Rob")).isNotNull();
boolean condition = map.get("Rob") instanceof TestBean;
assertThat(condition).isTrue();
assertThat(map.get("Rob") instanceof TestBean).isTrue();
assertThat(((TestBean) map.get("Rob")).getName()).isEqualTo("Sally");
}
@@ -121,7 +116,7 @@ public class CollectionMergingTests {
public void mergeProperties() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithProps");
Properties props = bean.getSomeProperties();
assertThat(props.size()).as("Incorrect size").isEqualTo(3);
assertThat(props).as("Incorrect size").hasSize(3);
assertThat(props.getProperty("Rob")).isEqualTo("Sally");
assertThat(props.getProperty("Rod")).isEqualTo("Kerry");
assertThat(props.getProperty("Juergen")).isEqualTo("Eva");
@@ -130,8 +125,8 @@ public class CollectionMergingTests {
@Test
public void mergeListInConstructor() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListInConstructor");
List list = bean.getSomeList();
assertThat(list.size()).as("Incorrect size").isEqualTo(3);
List<?> list = bean.getSomeList();
assertThat(list).as("Incorrect size").hasSize(3);
assertThat(list.get(0)).isEqualTo("Rob Harrop");
assertThat(list.get(1)).isEqualTo("Rod Johnson");
assertThat(list.get(2)).isEqualTo("Juergen Hoeller");
@@ -144,15 +139,14 @@ public class CollectionMergingTests {
assertThat(list).isNotNull();
assertThat(list).hasSize(3);
assertThat(list.get(2)).isNotNull();
boolean condition = list.get(2) instanceof TestBean;
assertThat(condition).isTrue();
assertThat(list.get(2) instanceof TestBean).isTrue();
}
@Test
public void mergeSetInConstructor() {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetInConstructor");
Set set = bean.getSomeSet();
assertThat(set.size()).as("Incorrect size").isEqualTo(2);
Set<?> set = bean.getSomeSet();
assertThat(set).as("Incorrect size").hasSize(2);
assertThat(set.contains("Rob Harrop")).isTrue();
assertThat(set.contains("Sally Greenwood")).isTrue();
}
@@ -166,17 +160,15 @@ public class CollectionMergingTests {
Iterator it = set.iterator();
it.next();
Object o = it.next();
assertThat(o).isNotNull();
boolean condition = o instanceof TestBean;
assertThat(condition).isTrue();
assertThat(o instanceof TestBean).isTrue();
assertThat(((TestBean) o).getName()).isEqualTo("Sally");
}
@Test
public void mergeMapInConstructor() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapInConstructor");
Map map = bean.getSomeMap();
assertThat(map.size()).as("Incorrect size").isEqualTo(3);
Map<?, ?> map = bean.getSomeMap();
assertThat(map).as("Incorrect size").hasSize(3);
assertThat(map.get("Rob")).isEqualTo("Sally");
assertThat(map.get("Rod")).isEqualTo("Kerry");
assertThat(map.get("Juergen")).isEqualTo("Eva");
@@ -188,9 +180,7 @@ public class CollectionMergingTests {
Map<?, ?> map = bean.getSomeMap();
assertThat(map).isNotNull();
assertThat(map).hasSize(2);
assertThat(map.get("Rob")).isNotNull();
boolean condition = map.get("Rob") instanceof TestBean;
assertThat(condition).isTrue();
assertThat(map.get("Rob") instanceof TestBean).isTrue();
assertThat(((TestBean) map.get("Rob")).getName()).isEqualTo("Sally");
}
@@ -198,7 +188,7 @@ public class CollectionMergingTests {
public void mergePropertiesInConstructor() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("childWithPropsInConstructor");
Properties props = bean.getSomeProperties();
assertThat(props.size()).as("Incorrect size").isEqualTo(3);
assertThat(props).as("Incorrect size").hasSize(3);
assertThat(props.getProperty("Rob")).isEqualTo("Sally");
assertThat(props.getProperty("Rod")).isEqualTo("Kerry");
assertThat(props.getProperty("Juergen")).isEqualTo("Eva");
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,15 +81,15 @@ public class CollectionsWithDefaultTypesTests {
@SuppressWarnings("rawtypes")
public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception {
MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble");
assertThat(jumble.getJumble().size() == 3).as("Expected 3 elements, not " + jumble.getJumble().size()).isTrue();
assertThat(jumble.getJumble()).as("Expected 3 elements, not " + jumble.getJumble().size()).hasSize(3);
List l = (List) jumble.getJumble();
assertThat(l.get(0).equals("literal")).isTrue();
Integer[] array1 = (Integer[]) l.get(1);
assertThat(array1[0].equals(2)).isTrue();
assertThat(array1[1].equals(4)).isTrue();
int[] array2 = (int[]) l.get(2);
assertThat(array2[0] == 3).isTrue();
assertThat(array2[1] == 5).isTrue();
assertThat(array2[0]).isEqualTo(3);
assertThat(array2[1]).isEqualTo(5);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -282,7 +282,7 @@ public class FactoryMethodTests {
FactoryMethods fm2 = (FactoryMethods) xbf.getBean("testBeanOnlyPrototype", tbArg2);
assertThat(fm2.getTestBean().getName()).isEqualTo("arg2");
assertThat(fm2.getNum()).isEqualTo(fm1.getNum());
assertThat("testBeanOnlyPrototypeDISetterString").isEqualTo(fm2.getStringValue());
assertThat(fm2.getStringValue()).isEqualTo("testBeanOnlyPrototypeDISetterString");
assertThat(fm2.getStringValue()).isEqualTo(fm2.getStringValue());
// The TestBean reference is resolved to a prototype in the factory
assertThat(fm2.getTestBean()).isSameAs(fm2.getTestBean());
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,7 +91,7 @@ public class UtilNamespaceHandlerTests {
void testNestedProperties() {
TestBean bean = (TestBean) this.beanFactory.getBean("testBean");
Properties props = bean.getSomeProperties();
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props).as("Incorrect property value").containsEntry("foo", "bar");
}
@Test
@@ -111,7 +111,7 @@ public class UtilNamespaceHandlerTests {
Map<?, ?> map = (Map) this.beanFactory.getBean("simpleMap");
assertThat(map.get("foo")).isEqualTo("bar");
Map<?, ?> map2 = (Map) this.beanFactory.getBean("simpleMap");
assertThat(map == map2).isTrue();
assertThat(map).isSameAs(map2);
}
@Test
@@ -120,7 +120,7 @@ public class UtilNamespaceHandlerTests {
assertThat(map.get("foo")).isEqualTo("bar");
Map<?, ?> map2 = (Map) this.beanFactory.getBean("scopedMap");
assertThat(map2.get("foo")).isEqualTo("bar");
assertThat(map != map2).isTrue();
assertThat(map).isNotSameAs(map2);
}
@Test
@@ -128,7 +128,7 @@ public class UtilNamespaceHandlerTests {
List<?> list = (List) this.beanFactory.getBean("simpleList");
assertThat(list.get(0)).isEqualTo("Rob Harrop");
List<?> list2 = (List) this.beanFactory.getBean("simpleList");
assertThat(list == list2).isTrue();
assertThat(list).isSameAs(list2);
}
@Test
@@ -137,7 +137,7 @@ public class UtilNamespaceHandlerTests {
assertThat(list.get(0)).isEqualTo("Rob Harrop");
List<?> list2 = (List) this.beanFactory.getBean("scopedList");
assertThat(list2.get(0)).isEqualTo("Rob Harrop");
assertThat(list != list2).isTrue();
assertThat(list).isNotSameAs(list2);
}
@Test
@@ -145,7 +145,7 @@ public class UtilNamespaceHandlerTests {
Set<?> set = (Set) this.beanFactory.getBean("simpleSet");
assertThat(set.contains("Rob Harrop")).isTrue();
Set<?> set2 = (Set) this.beanFactory.getBean("simpleSet");
assertThat(set == set2).isTrue();
assertThat(set).isSameAs(set2);
}
@Test
@@ -154,7 +154,7 @@ public class UtilNamespaceHandlerTests {
assertThat(set.contains("Rob Harrop")).isTrue();
Set<?> set2 = (Set) this.beanFactory.getBean("scopedSet");
assertThat(set2.contains("Rob Harrop")).isTrue();
assertThat(set != set2).isTrue();
assertThat(set).isNotSameAs(set2);
}
@Test
@@ -194,9 +194,9 @@ public class UtilNamespaceHandlerTests {
assertThat(bean2.getSomeList()).isEqualTo(list);
assertThat(bean2.getSomeSet()).isEqualTo(set);
assertThat(bean2.getSomeMap()).isEqualTo(map);
assertThat(list == bean2.getSomeList()).isFalse();
assertThat(set == bean2.getSomeSet()).isFalse();
assertThat(map == bean2.getSomeMap()).isFalse();
assertThat(list).isNotSameAs(bean2.getSomeList());
assertThat(set).isNotSameAs(bean2.getSomeSet());
assertThat(map).isNotSameAs(bean2.getSomeMap());
}
@Test
@@ -216,11 +216,11 @@ public class UtilNamespaceHandlerTests {
TestBean bean2 = (TestBean) this.beanFactory.getBean("nestedShortcutCollections");
assertThat(Arrays.equals(bean.getStringArray(), bean2.getStringArray())).isTrue();
assertThat(bean.getStringArray() == bean2.getStringArray()).isFalse();
assertThat(bean.getStringArray()).isNotSameAs(bean2.getStringArray());
assertThat(bean2.getSomeList()).isEqualTo(list);
assertThat(bean2.getSomeSet()).isEqualTo(set);
assertThat(list == bean2.getSomeList()).isFalse();
assertThat(set == bean2.getSomeSet()).isFalse();
assertThat(list).isNotSameAs(bean2.getSomeList());
assertThat(set).isNotSameAs(bean2.getSomeSet());
}
@Test
@@ -244,9 +244,9 @@ public class UtilNamespaceHandlerTests {
assertThat(bean2.getSomeList()).isEqualTo(list);
assertThat(bean2.getSomeSet()).isEqualTo(set);
assertThat(bean2.getSomeMap()).isEqualTo(map);
assertThat(list == bean2.getSomeList()).isFalse();
assertThat(set == bean2.getSomeSet()).isFalse();
assertThat(map == bean2.getSomeMap()).isFalse();
assertThat(list).isNotSameAs(bean2.getSomeList());
assertThat(set).isNotSameAs(bean2.getSomeSet());
assertThat(map).isNotSameAs(bean2.getSomeMap());
}
@Test
@@ -338,56 +338,56 @@ public class UtilNamespaceHandlerTests {
@Test
void testLoadProperties() {
Properties props = (Properties) this.beanFactory.getBean("myProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
assertThat(props).as("Incorrect property value").containsEntry("foo", "bar");
assertThat(props).as("Incorrect property value").doesNotContainKey("foo2");
Properties props2 = (Properties) this.beanFactory.getBean("myProperties");
assertThat(props == props2).isTrue();
assertThat(props).isSameAs(props2);
}
@Test
void testScopedProperties() {
Properties props = (Properties) this.beanFactory.getBean("myScopedProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
assertThat(props).as("Incorrect property value").containsEntry("foo", "bar");
assertThat(props).as("Incorrect property value").doesNotContainKey("foo2");
Properties props2 = (Properties) this.beanFactory.getBean("myScopedProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
assertThat(props != props2).isTrue();
assertThat(props).as("Incorrect property value").containsEntry("foo", "bar");
assertThat(props).as("Incorrect property value").doesNotContainKey("foo2");
assertThat(props).isNotSameAs(props2);
}
@Test
void testLocalProperties() {
Properties props = (Properties) this.beanFactory.getBean("myLocalProperties");
assertThat(props.get("foo")).as("Incorrect property value").isNull();
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("bar2");
assertThat(props).as("Incorrect property value").doesNotContainKey("foo");
assertThat(props).as("Incorrect property value").containsEntry("foo2", "bar2");
}
@Test
void testMergedProperties() {
Properties props = (Properties) this.beanFactory.getBean("myMergedProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("bar2");
assertThat(props).as("Incorrect property value").containsEntry("foo", "bar");
assertThat(props).as("Incorrect property value").containsEntry("foo2", "bar2");
}
@Test
void testLocalOverrideDefault() {
Properties props = (Properties) this.beanFactory.getBean("defaultLocalOverrideProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("local2");
assertThat(props).as("Incorrect property value").containsEntry("foo", "bar");
assertThat(props).as("Incorrect property value").containsEntry("foo2", "local2");
}
@Test
void testLocalOverrideFalse() {
Properties props = (Properties) this.beanFactory.getBean("falseLocalOverrideProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("local2");
assertThat(props).as("Incorrect property value").containsEntry("foo", "bar");
assertThat(props).as("Incorrect property value").containsEntry("foo2", "local2");
}
@Test
void testLocalOverrideTrue() {
Properties props = (Properties) this.beanFactory.getBean("trueLocalOverrideProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("local");
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("local2");
assertThat(props).as("Incorrect property value").containsEntry("foo", "local");
assertThat(props).as("Incorrect property value").containsEntry("foo2", "local2");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,25 +91,25 @@ public class XmlBeanCollectionTests {
//assertTrue("5 beans in reftypes, not " + this.beanFactory.getBeanDefinitionCount(), this.beanFactory.getBeanDefinitionCount() == 5);
TestBean jen = (TestBean) this.beanFactory.getBean("jenny");
TestBean dave = (TestBean) this.beanFactory.getBean("david");
assertThat(jen.getSpouse() == dave).isTrue();
assertThat(jen.getSpouse()).isSameAs(dave);
}
@Test
public void testPropertyWithLiteralValueSubelement() throws Exception {
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose");
assertThat(verbose.getName().equals("verbose")).isTrue();
assertThat(verbose.getName()).isEqualTo("verbose");
}
@Test
public void testPropertyWithIdRefLocalAttrSubelement() throws Exception {
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose2");
assertThat(verbose.getName().equals("verbose")).isTrue();
assertThat(verbose.getName()).isEqualTo("verbose");
}
@Test
public void testPropertyWithIdRefBeanAttrSubelement() throws Exception {
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose3");
assertThat(verbose.getName().equals("verbose")).isTrue();
assertThat(verbose.getName()).isEqualTo("verbose");
}
@Test
@@ -122,10 +122,10 @@ public class XmlBeanCollectionTests {
// Our bean doesn't modify the collection:
// of course it could be a different copy in a real object.
Object[] friends = rod.getFriends().toArray();
assertThat(friends.length == 2).isTrue();
assertThat(friends.length).isEqualTo(2);
assertThat(friends[0] == jen).as("First friend must be jen, not " + friends[0]).isTrue();
assertThat(friends[1] == dave).isTrue();
assertThat(friends[0]).as("First friend must be jen, not " + friends[0]).isSameAs(jen);
assertThat(friends[1]).isSameAs(dave);
// Should be ordered
}
@@ -136,34 +136,34 @@ public class XmlBeanCollectionTests {
TestBean rod = (TestBean) this.beanFactory.getBean("pRod");
Object[] friends = rod.getFriends().toArray();
assertThat(friends.length == 2).isTrue();
assertThat(friends[0].toString().equals(jen.toString())).as("First friend must be jen, not " + friends[0]).isTrue();
assertThat(friends[0] != jen).as("Jen not same instance").isTrue();
assertThat(friends[1].toString().equals(dave.toString())).isTrue();
assertThat(friends[1] != dave).as("Dave not same instance").isTrue();
assertThat(friends.length).isEqualTo(2);
assertThat(friends[0].toString()).as("First friend must be jen, not " + friends[0]).isEqualTo(jen.toString());
assertThat(friends[0]).as("Jen not same instance").isNotSameAs(jen);
assertThat(friends[1].toString()).isEqualTo(dave.toString());
assertThat(friends[1]).as("Dave not same instance").isNotSameAs(dave);
assertThat(dave.getSpouse().getName()).isEqualTo("Jen");
TestBean rod2 = (TestBean) this.beanFactory.getBean("pRod");
Object[] friends2 = rod2.getFriends().toArray();
assertThat(friends2.length == 2).isTrue();
assertThat(friends2[0].toString().equals(jen.toString())).as("First friend must be jen, not " + friends2[0]).isTrue();
assertThat(friends2[0] != friends[0]).as("Jen not same instance").isTrue();
assertThat(friends2[1].toString().equals(dave.toString())).isTrue();
assertThat(friends2[1] != friends[1]).as("Dave not same instance").isTrue();
assertThat(friends2.length).isEqualTo(2);
assertThat(friends2[0].toString()).as("First friend must be jen, not " + friends2[0]).isEqualTo(jen.toString());
assertThat(friends2[0]).as("Jen not same instance").isNotSameAs(friends[0]);
assertThat(friends2[1].toString()).isEqualTo(dave.toString());
assertThat(friends2[1]).as("Dave not same instance").isNotSameAs(friends[1]);
}
@Test
public void testRefSubelementsBuildCollectionFromSingleElement() throws Exception {
TestBean loner = (TestBean) this.beanFactory.getBean("loner");
TestBean dave = (TestBean) this.beanFactory.getBean("david");
assertThat(loner.getFriends().size() == 1).isTrue();
assertThat(loner.getFriends().size()).isEqualTo(1);
assertThat(loner.getFriends().contains(dave)).isTrue();
}
@Test
public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception {
MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble");
assertThat(jumble.getJumble().size() == 5).as("Expected 5 elements, not " + jumble.getJumble().size()).isTrue();
assertThat(jumble.getJumble().size()).as("Expected 5 elements, not " + jumble.getJumble().size()).isEqualTo(5);
List l = (List) jumble.getJumble();
assertThat(l.get(0).equals(this.beanFactory.getBean("david"))).isTrue();
assertThat(l.get(1).equals("literal")).isTrue();
@@ -185,25 +185,25 @@ public class XmlBeanCollectionTests {
@Test
public void testEmptyMap() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyMap");
assertThat(hasMap.getMap().size() == 0).isTrue();
assertThat(hasMap.getMap().size()).isEqualTo(0);
}
@Test
public void testMapWithLiteralsOnly() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("literalMap");
assertThat(hasMap.getMap().size() == 3).isTrue();
assertThat(hasMap.getMap().size()).isEqualTo(3);
assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue();
assertThat(hasMap.getMap().get("fi").equals("fum")).isTrue();
assertThat(hasMap.getMap().get("fa") == null).isTrue();
assertThat(hasMap.getMap().get("fa")).isNull();
}
@Test
public void testMapWithLiteralsAndReferences() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap");
assertThat(hasMap.getMap().size() == 5).isTrue();
assertThat(hasMap.getMap().size()).isEqualTo(5);
assertThat(hasMap.getMap().get("foo").equals(10)).isTrue();
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
assertThat(hasMap.getMap().get("jenny") == jenny).isTrue();
assertThat(hasMap.getMap().get("jenny")).isSameAs(jenny);
assertThat(hasMap.getMap().get(5).equals("david")).isTrue();
boolean condition1 = hasMap.getMap().get("bar") instanceof Long;
assertThat(condition1).isTrue();
@@ -217,22 +217,22 @@ public class XmlBeanCollectionTests {
public void testMapWithLiteralsAndPrototypeReferences() throws Exception {
TestBean jenny = (TestBean) this.beanFactory.getBean("pJenny");
HasMap hasMap = (HasMap) this.beanFactory.getBean("pMixedMap");
assertThat(hasMap.getMap().size() == 2).isTrue();
assertThat(hasMap.getMap().size()).isEqualTo(2);
assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue();
assertThat(hasMap.getMap().get("jenny").toString().equals(jenny.toString())).isTrue();
assertThat(hasMap.getMap().get("jenny") != jenny).as("Not same instance").isTrue();
assertThat(hasMap.getMap().get("jenny").toString()).isEqualTo(jenny.toString());
assertThat(hasMap.getMap().get("jenny")).as("Not same instance").isNotSameAs(jenny);
HasMap hasMap2 = (HasMap) this.beanFactory.getBean("pMixedMap");
assertThat(hasMap2.getMap().size() == 2).isTrue();
assertThat(hasMap2.getMap().size()).isEqualTo(2);
assertThat(hasMap2.getMap().get("foo").equals("bar")).isTrue();
assertThat(hasMap2.getMap().get("jenny").toString().equals(jenny.toString())).isTrue();
assertThat(hasMap2.getMap().get("jenny") != hasMap.getMap().get("jenny")).as("Not same instance").isTrue();
assertThat(hasMap2.getMap().get("jenny").toString()).isEqualTo(jenny.toString());
assertThat(hasMap2.getMap().get("jenny")).as("Not same instance").isNotSameAs(hasMap.getMap().get("jenny"));
}
@Test
public void testMapWithLiteralsReferencesAndList() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMapWithList");
assertThat(hasMap.getMap().size() == 4).isTrue();
assertThat(hasMap.getMap().size()).isEqualTo(4);
assertThat(hasMap.getMap().get(null).equals("bar")).isTrue();
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
assertThat(hasMap.getMap().get("jenny").equals(jenny)).isTrue();
@@ -240,28 +240,28 @@ public class XmlBeanCollectionTests {
// Check list
List l = (List) hasMap.getMap().get("list");
assertThat(l).isNotNull();
assertThat(l.size() == 4).isTrue();
assertThat(l.size()).isEqualTo(4);
assertThat(l.get(0).equals("zero")).isTrue();
assertThat(l.get(3) == null).isTrue();
assertThat(l.get(3)).isNull();
// Check nested map in list
Map m = (Map) l.get(1);
assertThat(m).isNotNull();
assertThat(m.size() == 2).isTrue();
assertThat(m.size()).isEqualTo(2);
assertThat(m.get("fo").equals("bar")).isTrue();
assertThat(m.get("jen").equals(jenny)).as("Map element 'jenny' should be equal to jenny bean, not " + m.get("jen")).isTrue();
// Check nested list in list
l = (List) l.get(2);
assertThat(l).isNotNull();
assertThat(l.size() == 2).isTrue();
assertThat(l.size()).isEqualTo(2);
assertThat(l.get(0).equals(jenny)).isTrue();
assertThat(l.get(1).equals("ba")).isTrue();
// Check nested map
m = (Map) hasMap.getMap().get("map");
assertThat(m).isNotNull();
assertThat(m.size() == 2).isTrue();
assertThat(m.size()).isEqualTo(2);
assertThat(m.get("foo").equals("bar")).isTrue();
assertThat(m.get("jenny").equals(jenny)).as("Map element 'jenny' should be equal to jenny bean, not " + m.get("jenny")).isTrue();
}
@@ -269,13 +269,13 @@ public class XmlBeanCollectionTests {
@Test
public void testEmptySet() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptySet");
assertThat(hasMap.getSet().size() == 0).isTrue();
assertThat(hasMap.getSet().size()).isEqualTo(0);
}
@Test
public void testPopulatedSet() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("set");
assertThat(hasMap.getSet().size() == 3).isTrue();
assertThat(hasMap.getSet().size()).isEqualTo(3);
assertThat(hasMap.getSet().contains("bar")).isTrue();
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
assertThat(hasMap.getSet().contains(jenny)).isTrue();
@@ -289,7 +289,7 @@ public class XmlBeanCollectionTests {
@Test
public void testPopulatedConcurrentSet() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("concurrentSet");
assertThat(hasMap.getConcurrentSet().size() == 3).isTrue();
assertThat(hasMap.getConcurrentSet().size()).isEqualTo(3);
assertThat(hasMap.getConcurrentSet().contains("bar")).isTrue();
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
assertThat(hasMap.getConcurrentSet().contains(jenny)).isTrue();
@@ -299,7 +299,7 @@ public class XmlBeanCollectionTests {
@Test
public void testPopulatedIdentityMap() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("identityMap");
assertThat(hasMap.getIdentityMap().size() == 2).isTrue();
assertThat(hasMap.getIdentityMap().size()).isEqualTo(2);
HashSet set = new HashSet(hasMap.getIdentityMap().keySet());
assertThat(set.contains("foo")).isTrue();
assertThat(set.contains("jenny")).isTrue();
@@ -308,14 +308,14 @@ public class XmlBeanCollectionTests {
@Test
public void testEmptyProps() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyProps");
assertThat(hasMap.getProps().size() == 0).isTrue();
assertThat(hasMap.getProps().size()).isEqualTo(0);
assertThat(Properties.class).isEqualTo(hasMap.getProps().getClass());
}
@Test
public void testPopulatedProps() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("props");
assertThat(hasMap.getProps().size() == 2).isTrue();
assertThat(hasMap.getProps().size()).isEqualTo(2);
assertThat(hasMap.getProps().get("foo").equals("bar")).isTrue();
assertThat(hasMap.getProps().get("2").equals("TWO")).isTrue();
}
@@ -323,7 +323,7 @@ public class XmlBeanCollectionTests {
@Test
public void testObjectArray() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("objectArray");
assertThat(hasMap.getObjectArray().length == 2).isTrue();
assertThat(hasMap.getObjectArray().length).isEqualTo(2);
assertThat(hasMap.getObjectArray()[0].equals("one")).isTrue();
assertThat(hasMap.getObjectArray()[1].equals(this.beanFactory.getBean("jenny"))).isTrue();
}
@@ -331,16 +331,16 @@ public class XmlBeanCollectionTests {
@Test
public void testIntegerArray() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray");
assertThat(hasMap.getIntegerArray().length == 3).isTrue();
assertThat(hasMap.getIntegerArray()[0] == 0).isTrue();
assertThat(hasMap.getIntegerArray()[1] == 1).isTrue();
assertThat(hasMap.getIntegerArray()[2] == 2).isTrue();
assertThat(hasMap.getIntegerArray().length).isEqualTo(3);
assertThat(hasMap.getIntegerArray()[0]).isEqualTo(0);
assertThat(hasMap.getIntegerArray()[1]).isEqualTo(1);
assertThat(hasMap.getIntegerArray()[2]).isEqualTo(2);
}
@Test
public void testClassArray() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("classArray");
assertThat(hasMap.getClassArray().length == 2).isTrue();
assertThat(hasMap.getClassArray().length).isEqualTo(2);
assertThat(hasMap.getClassArray()[0].equals(String.class)).isTrue();
assertThat(hasMap.getClassArray()[1].equals(Exception.class)).isTrue();
}
@@ -348,7 +348,7 @@ public class XmlBeanCollectionTests {
@Test
public void testClassList() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("classList");
assertThat(hasMap.getClassList().size()== 2).isTrue();
assertThat(hasMap.getClassList().size()).isEqualTo(2);
assertThat(hasMap.getClassList().get(0).equals(String.class)).isTrue();
assertThat(hasMap.getClassList().get(1).equals(Exception.class)).isTrue();
}
@@ -371,7 +371,7 @@ public class XmlBeanCollectionTests {
List list = (List) this.beanFactory.getBean("listFactory");
boolean condition = list instanceof LinkedList;
assertThat(condition).isTrue();
assertThat(list.size() == 2).isTrue();
assertThat(list.size()).isEqualTo(2);
assertThat(list.get(0)).isEqualTo("bar");
assertThat(list.get(1)).isEqualTo("jenny");
}
@@ -381,7 +381,7 @@ public class XmlBeanCollectionTests {
List list = (List) this.beanFactory.getBean("pListFactory");
boolean condition = list instanceof LinkedList;
assertThat(condition).isTrue();
assertThat(list.size() == 2).isTrue();
assertThat(list.size()).isEqualTo(2);
assertThat(list.get(0)).isEqualTo("bar");
assertThat(list.get(1)).isEqualTo("jenny");
}
@@ -391,7 +391,7 @@ public class XmlBeanCollectionTests {
Set set = (Set) this.beanFactory.getBean("setFactory");
boolean condition = set instanceof TreeSet;
assertThat(condition).isTrue();
assertThat(set.size() == 2).isTrue();
assertThat(set.size()).isEqualTo(2);
assertThat(set.contains("bar")).isTrue();
assertThat(set.contains("jenny")).isTrue();
}
@@ -401,7 +401,7 @@ public class XmlBeanCollectionTests {
Set set = (Set) this.beanFactory.getBean("pSetFactory");
boolean condition = set instanceof TreeSet;
assertThat(condition).isTrue();
assertThat(set.size() == 2).isTrue();
assertThat(set.size()).isEqualTo(2);
assertThat(set.contains("bar")).isTrue();
assertThat(set.contains("jenny")).isTrue();
}
@@ -411,7 +411,7 @@ public class XmlBeanCollectionTests {
Map map = (Map) this.beanFactory.getBean("mapFactory");
boolean condition = map instanceof TreeMap;
assertThat(condition).isTrue();
assertThat(map.size() == 2).isTrue();
assertThat(map.size()).isEqualTo(2);
assertThat(map.get("foo")).isEqualTo("bar");
assertThat(map.get("jen")).isEqualTo("jenny");
}
@@ -421,7 +421,7 @@ public class XmlBeanCollectionTests {
Map map = (Map) this.beanFactory.getBean("pMapFactory");
boolean condition = map instanceof TreeMap;
assertThat(condition).isTrue();
assertThat(map.size() == 2).isTrue();
assertThat(map.size()).isEqualTo(2);
assertThat(map.get("foo")).isEqualTo("bar");
assertThat(map.get("jen")).isEqualTo("jenny");
}
@@ -441,7 +441,7 @@ public class XmlBeanCollectionTests {
@Test
public void testEnumSetFactory() throws Exception {
Set set = (Set) this.beanFactory.getBean("enumSetFactory");
assertThat(set.size() == 2).isTrue();
assertThat(set.size()).isEqualTo(2);
assertThat(set.contains("ONE")).isTrue();
assertThat(set.contains("TWO")).isTrue();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -124,7 +124,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
@Test
public void descriptionButNoProperties() {
TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription");
assertThat(validEmpty.getAge()).isEqualTo(0);
assertThat(validEmpty.getAge()).isZero();
}
/**
@@ -136,71 +136,71 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased");
TestBean alias1 = (TestBean) getBeanFactory().getBean("myalias");
assertThat(tb1 == alias1).isTrue();
assertThat(tb1).isSameAs(alias1);
List tb1Aliases = Arrays.asList(getBeanFactory().getAliases("aliased"));
assertThat(tb1Aliases).hasSize(2);
assertThat(tb1Aliases.contains("myalias")).isTrue();
assertThat(tb1Aliases.contains("youralias")).isTrue();
assertThat(beanNames.contains("aliased")).isTrue();
assertThat(beanNames.contains("myalias")).isFalse();
assertThat(beanNames.contains("youralias")).isFalse();
assertThat(tb1Aliases).contains("myalias");
assertThat(tb1Aliases).contains("youralias");
assertThat(beanNames).contains("aliased");
assertThat(beanNames).doesNotContain("myalias");
assertThat(beanNames).doesNotContain("youralias");
TestBean tb2 = (TestBean) getBeanFactory().getBean("multiAliased");
TestBean alias2 = (TestBean) getBeanFactory().getBean("alias1");
TestBean alias3 = (TestBean) getBeanFactory().getBean("alias2");
TestBean alias3a = (TestBean) getBeanFactory().getBean("alias3");
TestBean alias3b = (TestBean) getBeanFactory().getBean("alias4");
assertThat(tb2 == alias2).isTrue();
assertThat(tb2 == alias3).isTrue();
assertThat(tb2 == alias3a).isTrue();
assertThat(tb2 == alias3b).isTrue();
assertThat(tb2).isSameAs(alias2);
assertThat(tb2).isSameAs(alias3);
assertThat(tb2).isSameAs(alias3a);
assertThat(tb2).isSameAs(alias3b);
List tb2Aliases = Arrays.asList(getBeanFactory().getAliases("multiAliased"));
assertThat(tb2Aliases).hasSize(4);
assertThat(tb2Aliases.contains("alias1")).isTrue();
assertThat(tb2Aliases.contains("alias2")).isTrue();
assertThat(tb2Aliases.contains("alias3")).isTrue();
assertThat(tb2Aliases.contains("alias4")).isTrue();
assertThat(beanNames.contains("multiAliased")).isTrue();
assertThat(beanNames.contains("alias1")).isFalse();
assertThat(beanNames.contains("alias2")).isFalse();
assertThat(beanNames.contains("alias3")).isFalse();
assertThat(beanNames.contains("alias4")).isFalse();
assertThat(tb2Aliases).contains("alias1");
assertThat(tb2Aliases).contains("alias2");
assertThat(tb2Aliases).contains("alias3");
assertThat(tb2Aliases).contains("alias4");
assertThat(beanNames).contains("multiAliased");
assertThat(beanNames).doesNotContain("alias1");
assertThat(beanNames).doesNotContain("alias2");
assertThat(beanNames).doesNotContain("alias3");
assertThat(beanNames).doesNotContain("alias4");
TestBean tb3 = (TestBean) getBeanFactory().getBean("aliasWithoutId1");
TestBean alias4 = (TestBean) getBeanFactory().getBean("aliasWithoutId2");
TestBean alias5 = (TestBean) getBeanFactory().getBean("aliasWithoutId3");
assertThat(tb3 == alias4).isTrue();
assertThat(tb3 == alias5).isTrue();
assertThat(tb3).isSameAs(alias4);
assertThat(tb3).isSameAs(alias5);
List tb3Aliases = Arrays.asList(getBeanFactory().getAliases("aliasWithoutId1"));
assertThat(tb3Aliases).hasSize(2);
assertThat(tb3Aliases.contains("aliasWithoutId2")).isTrue();
assertThat(tb3Aliases.contains("aliasWithoutId3")).isTrue();
assertThat(beanNames.contains("aliasWithoutId1")).isTrue();
assertThat(beanNames.contains("aliasWithoutId2")).isFalse();
assertThat(beanNames.contains("aliasWithoutId3")).isFalse();
assertThat(tb3Aliases).contains("aliasWithoutId2");
assertThat(tb3Aliases).contains("aliasWithoutId3");
assertThat(beanNames).contains("aliasWithoutId1");
assertThat(beanNames).doesNotContain("aliasWithoutId2");
assertThat(beanNames).doesNotContain("aliasWithoutId3");
TestBean tb4 = (TestBean) getBeanFactory().getBean(TestBean.class.getName() + "#0");
assertThat(tb4.getName()).isNull();
Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false);
assertThat(drs).hasSize(5);
assertThat(drs.containsKey(DummyReferencer.class.getName() + "#0")).isTrue();
assertThat(drs.containsKey(DummyReferencer.class.getName() + "#1")).isTrue();
assertThat(drs.containsKey(DummyReferencer.class.getName() + "#2")).isTrue();
assertThat(drs).containsKey(DummyReferencer.class.getName() + "#0");
assertThat(drs).containsKey(DummyReferencer.class.getName() + "#1");
assertThat(drs).containsKey(DummyReferencer.class.getName() + "#2");
}
@Test
public void factoryNesting() {
ITestBean father = (ITestBean) getBeanFactory().getBean("father");
assertThat(father != null).as("Bean from root context").isTrue();
assertThat(father).as("Bean from root context").isNotNull();
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
assertThat("Rod".equals(rod.getName())).as("Bean from child context").isTrue();
assertThat(rod.getSpouse() == father).as("Bean has external reference").isTrue();
assertThat(rod.getName()).as("Bean from child context").isEqualTo("Rod");
assertThat(rod.getSpouse()).as("Bean has external reference").isSameAs(father);
rod = (TestBean) parent.getBean("rod");
assertThat("Roderick".equals(rod.getName())).as("Bean from root context").isTrue();
assertThat(rod.getName()).as("Bean from root context").isEqualTo("Roderick");
}
@Test
@@ -208,25 +208,25 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer");
assertThat(ref.getTestBean1() == ref.getTestBean2()).isTrue();
assertThat(ref.getDummyFactory() == factory).isTrue();
assertThat(ref.getTestBean1()).isSameAs(ref.getTestBean2());
assertThat(ref.getDummyFactory()).isSameAs(factory);
DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("factoryReferencerWithConstructor");
assertThat(ref2.getTestBean1() == ref2.getTestBean2()).isTrue();
assertThat(ref2.getDummyFactory() == factory).isTrue();
assertThat(ref2.getTestBean1()).isSameAs(ref2.getTestBean2());
assertThat(ref2.getDummyFactory()).isSameAs(factory);
}
@Test
public void prototypeReferences() {
// check that not broken by circular reference resolution mechanism
DummyReferencer ref1 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
assertThat(ref1.getTestBean1() != ref1.getTestBean2()).as("Not referencing same bean twice").isTrue();
assertThat(ref1.getTestBean1()).as("Not referencing same bean twice").isNotSameAs(ref1.getTestBean2());
DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
assertThat(ref1 != ref2).as("Not the same referencer").isTrue();
assertThat(ref2.getTestBean1() != ref2.getTestBean2()).as("Not referencing same bean twice").isTrue();
assertThat(ref1.getTestBean1() != ref2.getTestBean1()).as("Not referencing same bean twice").isTrue();
assertThat(ref1.getTestBean2() != ref2.getTestBean2()).as("Not referencing same bean twice").isTrue();
assertThat(ref1.getTestBean1() != ref2.getTestBean2()).as("Not referencing same bean twice").isTrue();
assertThat(ref1).as("Not the same referencer").isNotSameAs(ref2);
assertThat(ref2.getTestBean1()).as("Not referencing same bean twice").isNotSameAs(ref2.getTestBean2());
assertThat(ref1.getTestBean1()).as("Not referencing same bean twice").isNotSameAs(ref2.getTestBean1());
assertThat(ref1.getTestBean2()).as("Not referencing same bean twice").isNotSameAs(ref2.getTestBean2());
assertThat(ref1.getTestBean1()).as("Not referencing same bean twice").isNotSameAs(ref2.getTestBean2());
}
@Test
@@ -245,8 +245,8 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
public void emptyValues() {
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
assertThat("".equals(rod.getTouchy())).as("Touchy is empty").isTrue();
assertThat("".equals(kerry.getTouchy())).as("Touchy is empty").isTrue();
assertThat(rod.getTouchy()).as("Touchy is empty").isEqualTo("");
assertThat(kerry.getTouchy()).as("Touchy is empty").isEqualTo("");
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public class ByteArrayPropertyEditorTests {
byteEditor.setAsText(text);
Object value = byteEditor.getValue();
assertThat(value).isNotNull().isInstanceOf(byte[].class);
assertThat(value).isInstanceOf(byte[].class);
byte[] bytes = (byte[]) value;
for (int i = 0; i < text.length(); ++i) {
assertThat(bytes[i]).as("cyte[] differs at index '" + i + "'").isEqualTo((byte) text.charAt(i));
@@ -47,10 +47,10 @@ public class ByteArrayPropertyEditorTests {
@Test
public void getAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
assertThat(byteEditor.getAsText()).isEqualTo("");
assertThat(byteEditor.getAsText()).isEmpty();
byteEditor.setAsText(null);
assertThat(byteEditor.getAsText()).isEqualTo("");
assertThat(byteEditor.getAsText()).isEmpty();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public class CharArrayPropertyEditorTests {
charEditor.setAsText(text);
Object value = charEditor.getValue();
assertThat(value).isNotNull().isInstanceOf(char[].class);
assertThat(value).isInstanceOf(char[].class);
char[] chars = (char[]) value;
for (int i = 0; i < text.length(); ++i) {
assertThat(chars[i]).as("char[] differs at index '" + i + "'").isEqualTo(text.charAt(i));
@@ -47,10 +47,10 @@ public class CharArrayPropertyEditorTests {
@Test
public void getAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
assertThat(charEditor.getAsText()).isEqualTo("");
assertThat(charEditor.getAsText()).isEmpty();
charEditor.setAsText(null);
assertThat(charEditor.getAsText()).isEqualTo("");
assertThat(charEditor.getAsText()).isEmpty();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public class CustomCollectionEditorTests {
boolean condition = value instanceof ArrayList;
assertThat(condition).isTrue();
List<?> list = (List<?>) value;
assertThat(list.size()).as("There must be 3 elements in the converted collection").isEqualTo(3);
assertThat(list).as("There must be 3 elements in the converted collection").hasSize(3);
assertThat(list.get(0)).isEqualTo(0);
assertThat(list.get(1)).isEqualTo(1);
assertThat(list.get(2)).isEqualTo(2);
@@ -74,7 +74,7 @@ public class CustomCollectionEditorTests {
editor.setValue("0, 1, 2");
Collection<?> value = (Collection<?>) editor.getValue();
assertThat(value).isNotNull();
assertThat(value.size()).as("There must be 1 element in the converted collection").isEqualTo(1);
assertThat(value).as("There must be 1 element in the converted collection").hasSize(1);
assertThat(value.iterator().next()).isEqualTo("0, 1, 2");
}
@@ -87,7 +87,7 @@ public class CustomCollectionEditorTests {
boolean condition = value instanceof ArrayList;
assertThat(condition).isTrue();
List<?> list = (List<?>) value;
assertThat(list.size()).as("There must be 1 element in the converted collection").isEqualTo(1);
assertThat(list).as("There must be 1 element in the converted collection").hasSize(1);
assertThat(list.get(0)).isEqualTo("0, 1, 2");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -350,30 +350,30 @@ class CustomEditorTests {
bw.setPropertyValue("double2", "6.1");
bw.setPropertyValue("bigDecimal", "4.5");
assertThat(Short.valueOf("1").equals(bw.getPropertyValue("short1"))).as("Correct short1 value").isTrue();
assertThat(tb.getShort1() == 1).as("Correct short1 value").isTrue();
assertThat(Short.valueOf("2").equals(bw.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
assertThat(Short.valueOf("2").equals(tb.getShort2())).as("Correct short2 value").isTrue();
assertThat(Integer.valueOf("7").equals(bw.getPropertyValue("int1"))).as("Correct int1 value").isTrue();
assertThat(tb.getInt1() == 7).as("Correct int1 value").isTrue();
assertThat(Integer.valueOf("8").equals(bw.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
assertThat(Integer.valueOf("8").equals(tb.getInt2())).as("Correct int2 value").isTrue();
assertThat(Long.valueOf("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
assertThat(Long.valueOf("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(Long.valueOf("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
assertThat(new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
assertThat(new BigInteger("3").equals(tb.getBigInteger())).as("Correct bigInteger value").isTrue();
assertThat(Float.valueOf("7.1").equals(bw.getPropertyValue("float1"))).as("Correct float1 value").isTrue();
assertThat(Float.valueOf("7.1").equals(tb.getFloat1())).as("Correct float1 value").isTrue();
assertThat(Float.valueOf("8.1").equals(bw.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
assertThat(Float.valueOf("8.1").equals(tb.getFloat2())).as("Correct float2 value").isTrue();
assertThat(Double.valueOf("5.1").equals(bw.getPropertyValue("double1"))).as("Correct double1 value").isTrue();
assertThat(tb.getDouble1() == 5.1).as("Correct double1 value").isTrue();
assertThat(Double.valueOf("6.1").equals(bw.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
assertThat(Double.valueOf("6.1").equals(tb.getDouble2())).as("Correct double2 value").isTrue();
assertThat(new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
assertThat(new BigDecimal("4.5").equals(tb.getBigDecimal())).as("Correct bigDecimal value").isTrue();
assertThat(Short.valueOf("1")).as("Correct short1 value").isEqualTo(bw.getPropertyValue("short1"));
assertThat(tb.getShort1()).as("Correct short1 value").isOne();
assertThat(Short.valueOf("2")).as("Correct short2 value").isEqualTo(bw.getPropertyValue("short2"));
assertThat(Short.valueOf("2")).as("Correct short2 value").isEqualTo(tb.getShort2());
assertThat(Integer.valueOf("7")).as("Correct int1 value").isEqualTo(bw.getPropertyValue("int1"));
assertThat(tb.getInt1()).as("Correct int1 value").isEqualTo(7);
assertThat(Integer.valueOf("8")).as("Correct int2 value").isEqualTo(bw.getPropertyValue("int2"));
assertThat(Integer.valueOf("8")).as("Correct int2 value").isEqualTo(tb.getInt2());
assertThat(Long.valueOf("5")).as("Correct long1 value").isEqualTo(bw.getPropertyValue("long1"));
assertThat(tb.getLong1()).as("Correct long1 value").isEqualTo(5);
assertThat(Long.valueOf("6")).as("Correct long2 value").isEqualTo(bw.getPropertyValue("long2"));
assertThat(Long.valueOf("6")).as("Correct long2 value").isEqualTo(tb.getLong2());
assertThat(new BigInteger("3")).as("Correct bigInteger value").isEqualTo(bw.getPropertyValue("bigInteger"));
assertThat(new BigInteger("3")).as("Correct bigInteger value").isEqualTo(tb.getBigInteger());
assertThat(Float.valueOf("7.1")).as("Correct float1 value").isEqualTo(bw.getPropertyValue("float1"));
assertThat(Float.valueOf("7.1")).as("Correct float1 value").isEqualTo(tb.getFloat1());
assertThat(Float.valueOf("8.1")).as("Correct float2 value").isEqualTo(bw.getPropertyValue("float2"));
assertThat(Float.valueOf("8.1")).as("Correct float2 value").isEqualTo(tb.getFloat2());
assertThat(Double.valueOf("5.1")).as("Correct double1 value").isEqualTo(bw.getPropertyValue("double1"));
assertThat(tb.getDouble1()).as("Correct double1 value").isEqualTo(5.1);
assertThat(Double.valueOf("6.1")).as("Correct double2 value").isEqualTo(bw.getPropertyValue("double2"));
assertThat(Double.valueOf("6.1")).as("Correct double2 value").isEqualTo(tb.getDouble2());
assertThat(new BigDecimal("4.5")).as("Correct bigDecimal value").isEqualTo(bw.getPropertyValue("bigDecimal"));
assertThat(new BigDecimal("4.5")).as("Correct bigDecimal value").isEqualTo(tb.getBigDecimal());
}
@Test
@@ -408,29 +408,29 @@ class CustomEditorTests {
bw.setPropertyValue("bigDecimal", "4,5");
assertThat(bw.getPropertyValue("short1")).as("Correct short1 value").isEqualTo(Short.valueOf("1"));
assertThat(tb.getShort1() == 1).as("Correct short1 value").isTrue();
assertThat(tb.getShort1()).as("Correct short1 value").isOne();
assertThat(bw.getPropertyValue("short2")).as("Correct short2 value").isEqualTo(Short.valueOf("2"));
assertThat(tb.getShort2()).as("Correct short2 value").isEqualTo(Short.valueOf("2"));
assertThat(bw.getPropertyValue("int1")).as("Correct int1 value").isEqualTo(Integer.valueOf("7"));
assertThat(tb.getInt1() == 7).as("Correct int1 value").isTrue();
assertThat(tb.getInt1()).as("Correct int1 value").isEqualTo(7);
assertThat(bw.getPropertyValue("int2")).as("Correct int2 value").isEqualTo(Integer.valueOf("8"));
assertThat(tb.getInt2()).as("Correct int2 value").isEqualTo(Integer.valueOf("8"));
assertThat(bw.getPropertyValue("long1")).as("Correct long1 value").isEqualTo(Long.valueOf("5"));
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
assertThat(tb.getLong1()).as("Correct long1 value").isEqualTo(5);
assertThat(bw.getPropertyValue("long2")).as("Correct long2 value").isEqualTo(Long.valueOf("6"));
assertThat(tb.getLong2()).as("Correct long2 value").isEqualTo(Long.valueOf("6"));
assertThat(new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
assertThat(new BigInteger("3").equals(tb.getBigInteger())).as("Correct bigInteger value").isTrue();
assertThat(new BigInteger("3")).as("Correct bigInteger value").isEqualTo(bw.getPropertyValue("bigInteger"));
assertThat(new BigInteger("3")).as("Correct bigInteger value").isEqualTo(tb.getBigInteger());
assertThat(bw.getPropertyValue("float1")).as("Correct float1 value").isEqualTo(Float.valueOf("7.1"));
assertThat(Float.valueOf(tb.getFloat1())).as("Correct float1 value").isEqualTo(Float.valueOf("7.1"));
assertThat(bw.getPropertyValue("float2")).as("Correct float2 value").isEqualTo(Float.valueOf("8.1"));
assertThat(tb.getFloat2()).as("Correct float2 value").isEqualTo(Float.valueOf("8.1"));
assertThat(bw.getPropertyValue("double1")).as("Correct double1 value").isEqualTo(Double.valueOf("5.1"));
assertThat(tb.getDouble1() == 5.1).as("Correct double1 value").isTrue();
assertThat(tb.getDouble1()).as("Correct double1 value").isEqualTo(5.1);
assertThat(bw.getPropertyValue("double2")).as("Correct double2 value").isEqualTo(Double.valueOf("6.1"));
assertThat(tb.getDouble2()).as("Correct double2 value").isEqualTo(Double.valueOf("6.1"));
assertThat(new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
assertThat(new BigDecimal("4.5").equals(tb.getBigDecimal())).as("Correct bigDecimal value").isTrue();
assertThat(new BigDecimal("4.5")).as("Correct bigDecimal value").isEqualTo(bw.getPropertyValue("bigDecimal"));
assertThat(new BigDecimal("4.5")).as("Correct bigDecimal value").isEqualTo(tb.getBigDecimal());
}
@Test
@@ -444,13 +444,13 @@ class CustomEditorTests {
bw.setPropertyValue("long1", "5");
bw.setPropertyValue("long2", "6");
assertThat(Long.valueOf("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
assertThat(tb.getLong1()).as("Correct long1 value").isEqualTo(5);
assertThat(Long.valueOf("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
assertThat(Long.valueOf("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
bw.setPropertyValue("long2", "");
assertThat(bw.getPropertyValue("long2") == null).as("Correct long2 value").isTrue();
assertThat(tb.getLong2() == null).as("Correct long2 value").isTrue();
assertThat(bw.getPropertyValue("long2")).as("Correct long2 value").isNull();
assertThat(tb.getLong2()).as("Correct long2 value").isNull();
assertThatExceptionOfType(BeansException.class).isThrownBy(() ->
bw.setPropertyValue("long1", ""));
assertThat(bw.getPropertyValue("long1")).isEqualTo(5L);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ public class FileEditorTests {
boolean condition = value instanceof File;
assertThat(condition).isTrue();
File file = (File) value;
assertThat(file.exists()).isTrue();
assertThat(file).exists();
}
@Test
@@ -86,9 +86,9 @@ public class FileEditorTests {
boolean condition = value instanceof File;
assertThat(condition).isTrue();
File file = (File) value;
assertThat(file.exists()).isTrue();
assertThat(file).exists();
String absolutePath = file.getAbsolutePath().replace('\\', '/');
assertThat(absolutePath.endsWith(fileName)).isTrue();
assertThat(absolutePath).endsWith(fileName);
}
@Test
@@ -101,9 +101,9 @@ public class FileEditorTests {
boolean condition = value instanceof File;
assertThat(condition).isTrue();
File file = (File) value;
assertThat(file.exists()).isFalse();
assertThat(file).doesNotExist();
String absolutePath = file.getAbsolutePath().replace('\\', '/');
assertThat(absolutePath.endsWith(fileName)).isTrue();
assertThat(absolutePath).endsWith(fileName);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ public class InputStreamEditorTests {
boolean condition = value instanceof InputStream;
assertThat(condition).isTrue();
stream = (InputStream) value;
assertThat(stream.available() > 0).isTrue();
assertThat(stream.available()).isGreaterThan(0);
}
finally {
if (stream != null) {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,9 +39,9 @@ public class PathEditorTests {
pathEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
ClassUtils.getShortName(getClass()) + ".class");
Object value = pathEditor.getValue();
assertThat(value instanceof Path).isTrue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
assertThat(path.toFile().exists()).isTrue();
assertThat(path.toFile()).exists();
}
@Test
@@ -56,9 +56,9 @@ public class PathEditorTests {
PropertyEditor pathEditor = new PathEditor();
pathEditor.setAsText("file:/no_way_this_file_is_found.doc");
Object value = pathEditor.getValue();
assertThat(value instanceof Path).isTrue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
assertThat(!path.toFile().exists()).isTrue();
assertThat(path.toFile()).doesNotExist();
}
@Test
@@ -66,9 +66,9 @@ public class PathEditorTests {
PropertyEditor pathEditor = new PathEditor();
pathEditor.setAsText("/no_way_this_file_is_found.doc");
Object value = pathEditor.getValue();
assertThat(value instanceof Path).isTrue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
assertThat(!path.toFile().exists()).isTrue();
assertThat(path.toFile()).doesNotExist();
}
@Test
@@ -76,9 +76,9 @@ public class PathEditorTests {
PropertyEditor pathEditor = new PathEditor();
pathEditor.setAsText("C:\\no_way_this_file_is_found.doc");
Object value = pathEditor.getValue();
assertThat(value instanceof Path).isTrue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
assertThat(!path.toFile().exists()).isTrue();
assertThat(path.toFile()).doesNotExist();
}
@Test
@@ -87,9 +87,9 @@ public class PathEditorTests {
try {
pathEditor.setAsText("file://C:\\no_way_this_file_is_found.doc");
Object value = pathEditor.getValue();
assertThat(value instanceof Path).isTrue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
assertThat(!path.toFile().exists()).isTrue();
assertThat(path.toFile()).doesNotExist();
}
catch (IllegalArgumentException ex) {
if (File.separatorChar == '\\') { // on Windows, otherwise silently ignore
@@ -105,15 +105,15 @@ public class PathEditorTests {
ClassUtils.getShortName(getClass()) + ".class";
pathEditor.setAsText(fileName);
Object value = pathEditor.getValue();
assertThat(value instanceof Path).isTrue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
File file = path.toFile();
assertThat(file.exists()).isTrue();
assertThat(file).exists();
String absolutePath = file.getAbsolutePath();
if (File.separatorChar == '\\') {
absolutePath = absolutePath.replace('\\', '/');
}
assertThat(absolutePath.endsWith(fileName)).isTrue();
assertThat(absolutePath).endsWith(fileName);
}
@Test
@@ -123,15 +123,15 @@ public class PathEditorTests {
ClassUtils.getShortName(getClass()) + ".clazz";
pathEditor.setAsText(fileName);
Object value = pathEditor.getValue();
assertThat(value instanceof Path).isTrue();
assertThat(value).isInstanceOf(Path.class);
Path path = (Path) value;
File file = path.toFile();
assertThat(file.exists()).isFalse();
assertThat(file).doesNotExist();
String absolutePath = file.getAbsolutePath();
if (File.separatorChar == '\\') {
absolutePath = absolutePath.replace('\\', '/');
}
assertThat(absolutePath.endsWith(fileName)).isTrue();
assertThat(absolutePath).endsWith(fileName);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ public class PropertiesEditorTests {
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
assertThat(p.entrySet().size() == 1).as("contains one entry").isTrue();
assertThat(p.entrySet().size()).as("contains one entry").isEqualTo(1);
assertThat(p.get("foo").equals("bar")).as("foo=bar").isTrue();
}
@@ -51,7 +51,7 @@ public class PropertiesEditorTests {
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
assertThat(p.entrySet().size() == 2).as("contains two entries").isTrue();
assertThat(p.entrySet().size()).as("contains two entries").isEqualTo(2);
assertThat(p.get("foo").equals("bar with whitespace")).as("foo=bar with whitespace").isTrue();
assertThat(p.get("me").equals("mi")).as("me=mi").isTrue();
}
@@ -64,7 +64,7 @@ public class PropertiesEditorTests {
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
assertThat(p.entrySet().size() == 3).as("contains two entries").isTrue();
assertThat(p.entrySet().size()).as("contains two entries").isEqualTo(3);
assertThat(p.get("foo").equals("bar")).as("foo=bar").isTrue();
assertThat(p.get("me").equals("mi")).as("me=mi").isTrue();
assertThat(p.get("x").equals("y=z")).as("x='y=z'").isTrue();
@@ -76,7 +76,7 @@ public class PropertiesEditorTests {
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
assertThat(p.entrySet().size() == 3).as("contains two entries").isTrue();
assertThat(p.entrySet().size()).as("contains two entries").isEqualTo(3);
assertThat(p.get("foo").equals("bar")).as("foo=bar").isTrue();
assertThat(p.get("me").equals("mi")).as("me=mi").isTrue();
assertThat(p.get("x").equals("")).as("x='y=z'").isTrue();
@@ -88,7 +88,7 @@ public class PropertiesEditorTests {
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
assertThat(p.entrySet().size() == 3).as("contains three entries").isTrue();
assertThat(p.entrySet().size()).as("contains three entries").isEqualTo(3);
assertThat(p.get("foo").equals("")).as("foo is empty").isTrue();
assertThat(p.get("me").equals("mi")).as("me=mi").isTrue();
}
@@ -107,7 +107,7 @@ public class PropertiesEditorTests {
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
assertThat(p.entrySet().size() == 3).as("contains three entries").isTrue();
assertThat(p.entrySet().size()).as("contains three entries").isEqualTo(3);
assertThat(p.get("foo").equals("bar")).as("foo is bar").isTrue();
assertThat(p.get("me").equals("mi")).as("me=mi").isTrue();
}
@@ -129,7 +129,7 @@ public class PropertiesEditorTests {
PropertiesEditor pe= new PropertiesEditor();
pe.setAsText(s);
Properties p = (Properties) pe.getValue();
assertThat(p.size() == 3).as("contains 3 entries, not " + p.size()).isTrue();
assertThat(p.size()).as("contains 3 entries, not " + p.size()).isEqualTo(3);
assertThat(p.get("foo").equals("bar")).as("foo is bar").isTrue();
assertThat(p.get("me").equals("mi")).as("me=mi").isTrue();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ public class URIEditorTests {
assertThat(condition).isTrue();
URI uri = (URI) value;
assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
assertThat(uri.getScheme().startsWith("classpath")).isTrue();
assertThat(uri.getScheme()).startsWith("classpath");
}
@Test
@@ -107,13 +107,13 @@ public class URIEditorTests {
PropertyEditor uriEditor = new URIEditor();
uriEditor.setAsText(null);
assertThat(uriEditor.getValue()).isNull();
assertThat(uriEditor.getAsText()).isEqualTo("");
assertThat(uriEditor.getAsText()).isEmpty();
}
@Test
public void getAsTextReturnsEmptyStringIfValueNotSet() throws Exception {
PropertyEditor uriEditor = new URIEditor();
assertThat(uriEditor.getAsText()).isEqualTo("");
assertThat(uriEditor.getAsText()).isEmpty();
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -86,13 +86,13 @@ public class URLEditorTests {
PropertyEditor urlEditor = new URLEditor();
urlEditor.setAsText(null);
assertThat(urlEditor.getValue()).isNull();
assertThat(urlEditor.getAsText()).isEqualTo("");
assertThat(urlEditor.getAsText()).isEmpty();
}
@Test
public void testGetAsTextReturnsEmptyStringIfValueNotSet() throws Exception {
PropertyEditor urlEditor = new URLEditor();
assertThat(urlEditor.getAsText()).isEqualTo("");
assertThat(urlEditor.getAsText()).isEmpty();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ class ZoneIdEditorTests {
@Test
void getNullAsText() {
assertThat(editor.getAsText()).as("The returned value is not correct.").isEqualTo("");
assertThat(editor.getAsText()).as("The returned value is not correct.").isEmpty();
}
@Test
@@ -52,101 +52,101 @@ public class PagedListHolderTests {
tbs.add(tb3);
PagedListHolder holder = new PagedListHolder(tbs);
assertThat(holder.getSource() == tbs).as("Correct source").isTrue();
assertThat(holder.getNrOfElements() == 3).as("Correct number of elements").isTrue();
assertThat(holder.getPageCount() == 1).as("Correct number of pages").isTrue();
assertThat(holder.getPageSize() == PagedListHolder.DEFAULT_PAGE_SIZE).as("Correct page size").isTrue();
assertThat(holder.getPage() == 0).as("Correct page number").isTrue();
assertThat(holder.getSource()).as("Correct source").isSameAs(tbs);
assertThat(holder.getNrOfElements()).as("Correct number of elements").isEqualTo(3);
assertThat(holder.getPageCount()).as("Correct number of pages").isEqualTo(1);
assertThat(holder.getPageSize()).as("Correct page size").isEqualTo(PagedListHolder.DEFAULT_PAGE_SIZE);
assertThat(holder.getPage()).as("Correct page number").isEqualTo(0);
assertThat(holder.isFirstPage()).as("First page").isTrue();
assertThat(holder.isLastPage()).as("Last page").isTrue();
assertThat(holder.getFirstElementOnPage() == 0).as("Correct first element").isTrue();
assertThat(holder.getLastElementOnPage() == 2).as("Correct first element").isTrue();
assertThat(holder.getPageList().size() == 3).as("Correct page list size").isTrue();
assertThat(holder.getPageList().get(0) == tb1).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(1) == tb2).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(2) == tb3).as("Correct page list contents").isTrue();
assertThat(holder.getFirstElementOnPage()).as("Correct first element").isEqualTo(0);
assertThat(holder.getLastElementOnPage()).as("Correct first element").isEqualTo(2);
assertThat(holder.getPageList().size()).as("Correct page list size").isEqualTo(3);
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb1);
assertThat(holder.getPageList().get(1)).as("Correct page list contents").isSameAs(tb2);
assertThat(holder.getPageList().get(2)).as("Correct page list contents").isSameAs(tb3);
holder.setPageSize(2);
assertThat(holder.getPageCount() == 2).as("Correct number of pages").isTrue();
assertThat(holder.getPageSize() == 2).as("Correct page size").isTrue();
assertThat(holder.getPage() == 0).as("Correct page number").isTrue();
assertThat(holder.getPageCount()).as("Correct number of pages").isEqualTo(2);
assertThat(holder.getPageSize()).as("Correct page size").isEqualTo(2);
assertThat(holder.getPage()).as("Correct page number").isEqualTo(0);
assertThat(holder.isFirstPage()).as("First page").isTrue();
assertThat(holder.isLastPage()).as("Last page").isFalse();
assertThat(holder.getFirstElementOnPage() == 0).as("Correct first element").isTrue();
assertThat(holder.getLastElementOnPage() == 1).as("Correct last element").isTrue();
assertThat(holder.getPageList().size() == 2).as("Correct page list size").isTrue();
assertThat(holder.getPageList().get(0) == tb1).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(1) == tb2).as("Correct page list contents").isTrue();
assertThat(holder.getFirstElementOnPage()).as("Correct first element").isEqualTo(0);
assertThat(holder.getLastElementOnPage()).as("Correct last element").isEqualTo(1);
assertThat(holder.getPageList().size()).as("Correct page list size").isEqualTo(2);
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb1);
assertThat(holder.getPageList().get(1)).as("Correct page list contents").isSameAs(tb2);
holder.setPage(1);
assertThat(holder.getPage() == 1).as("Correct page number").isTrue();
assertThat(holder.getPage()).as("Correct page number").isEqualTo(1);
assertThat(holder.isFirstPage()).as("First page").isFalse();
assertThat(holder.isLastPage()).as("Last page").isTrue();
assertThat(holder.getFirstElementOnPage() == 2).as("Correct first element").isTrue();
assertThat(holder.getLastElementOnPage() == 2).as("Correct last element").isTrue();
assertThat(holder.getPageList().size() == 1).as("Correct page list size").isTrue();
assertThat(holder.getPageList().get(0) == tb3).as("Correct page list contents").isTrue();
assertThat(holder.getFirstElementOnPage()).as("Correct first element").isEqualTo(2);
assertThat(holder.getLastElementOnPage()).as("Correct last element").isEqualTo(2);
assertThat(holder.getPageList().size()).as("Correct page list size").isEqualTo(1);
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb3);
holder.setPageSize(3);
assertThat(holder.getPageCount() == 1).as("Correct number of pages").isTrue();
assertThat(holder.getPageSize() == 3).as("Correct page size").isTrue();
assertThat(holder.getPage() == 0).as("Correct page number").isTrue();
assertThat(holder.getPageCount()).as("Correct number of pages").isEqualTo(1);
assertThat(holder.getPageSize()).as("Correct page size").isEqualTo(3);
assertThat(holder.getPage()).as("Correct page number").isEqualTo(0);
assertThat(holder.isFirstPage()).as("First page").isTrue();
assertThat(holder.isLastPage()).as("Last page").isTrue();
assertThat(holder.getFirstElementOnPage() == 0).as("Correct first element").isTrue();
assertThat(holder.getLastElementOnPage() == 2).as("Correct last element").isTrue();
assertThat(holder.getFirstElementOnPage()).as("Correct first element").isEqualTo(0);
assertThat(holder.getLastElementOnPage()).as("Correct last element").isEqualTo(2);
holder.setPage(1);
holder.setPageSize(2);
assertThat(holder.getPageCount() == 2).as("Correct number of pages").isTrue();
assertThat(holder.getPageSize() == 2).as("Correct page size").isTrue();
assertThat(holder.getPage() == 1).as("Correct page number").isTrue();
assertThat(holder.getPageCount()).as("Correct number of pages").isEqualTo(2);
assertThat(holder.getPageSize()).as("Correct page size").isEqualTo(2);
assertThat(holder.getPage()).as("Correct page number").isEqualTo(1);
assertThat(holder.isFirstPage()).as("First page").isFalse();
assertThat(holder.isLastPage()).as("Last page").isTrue();
assertThat(holder.getFirstElementOnPage() == 2).as("Correct first element").isTrue();
assertThat(holder.getLastElementOnPage() == 2).as("Correct last element").isTrue();
assertThat(holder.getFirstElementOnPage()).as("Correct first element").isEqualTo(2);
assertThat(holder.getLastElementOnPage()).as("Correct last element").isEqualTo(2);
holder.setPageSize(2);
holder.setPage(1);
((MutableSortDefinition) holder.getSort()).setProperty("name");
((MutableSortDefinition) holder.getSort()).setIgnoreCase(false);
holder.resort();
assertThat(holder.getSource() == tbs).as("Correct source").isTrue();
assertThat(holder.getNrOfElements() == 3).as("Correct number of elements").isTrue();
assertThat(holder.getPageCount() == 2).as("Correct number of pages").isTrue();
assertThat(holder.getPageSize() == 2).as("Correct page size").isTrue();
assertThat(holder.getPage() == 0).as("Correct page number").isTrue();
assertThat(holder.getSource()).as("Correct source").isSameAs(tbs);
assertThat(holder.getNrOfElements()).as("Correct number of elements").isEqualTo(3);
assertThat(holder.getPageCount()).as("Correct number of pages").isEqualTo(2);
assertThat(holder.getPageSize()).as("Correct page size").isEqualTo(2);
assertThat(holder.getPage()).as("Correct page number").isEqualTo(0);
assertThat(holder.isFirstPage()).as("First page").isTrue();
assertThat(holder.isLastPage()).as("Last page").isFalse();
assertThat(holder.getFirstElementOnPage() == 0).as("Correct first element").isTrue();
assertThat(holder.getLastElementOnPage() == 1).as("Correct last element").isTrue();
assertThat(holder.getPageList().size() == 2).as("Correct page list size").isTrue();
assertThat(holder.getPageList().get(0) == tb3).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(1) == tb1).as("Correct page list contents").isTrue();
assertThat(holder.getFirstElementOnPage()).as("Correct first element").isEqualTo(0);
assertThat(holder.getLastElementOnPage()).as("Correct last element").isEqualTo(1);
assertThat(holder.getPageList().size()).as("Correct page list size").isEqualTo(2);
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb3);
assertThat(holder.getPageList().get(1)).as("Correct page list contents").isSameAs(tb1);
((MutableSortDefinition) holder.getSort()).setProperty("name");
holder.resort();
assertThat(holder.getPageList().get(0) == tb2).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(1) == tb1).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb2);
assertThat(holder.getPageList().get(1)).as("Correct page list contents").isSameAs(tb1);
((MutableSortDefinition) holder.getSort()).setProperty("name");
holder.resort();
assertThat(holder.getPageList().get(0) == tb3).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(1) == tb1).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb3);
assertThat(holder.getPageList().get(1)).as("Correct page list contents").isSameAs(tb1);
holder.setPage(1);
assertThat(holder.getPageList().size() == 1).as("Correct page list size").isTrue();
assertThat(holder.getPageList().get(0) == tb2).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().size()).as("Correct page list size").isEqualTo(1);
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb2);
((MutableSortDefinition) holder.getSort()).setProperty("age");
holder.resort();
assertThat(holder.getPageList().get(0) == tb1).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(1) == tb3).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb1);
assertThat(holder.getPageList().get(1)).as("Correct page list contents").isSameAs(tb3);
((MutableSortDefinition) holder.getSort()).setIgnoreCase(true);
holder.resort();
assertThat(holder.getPageList().get(0) == tb1).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(1) == tb3).as("Correct page list contents").isTrue();
assertThat(holder.getPageList().get(0)).as("Correct page list contents").isSameAs(tb1);
assertThat(holder.getPageList().get(1)).as("Correct page list contents").isSameAs(tb3);
holder.nextPage();
assertThat(holder.getPage()).isEqualTo(1);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,9 +39,9 @@ public class PropertyComparatorTests {
dog2.setNickName("biscy");
PropertyComparator<Dog> c = new PropertyComparator<>("nickName", false, true);
assertThat(c.compare(dog, dog2) > 0).isTrue();
assertThat(c.compare(dog, dog) == 0).isTrue();
assertThat(c.compare(dog2, dog) < 0).isTrue();
assertThat(c.compare(dog, dog2)).isGreaterThan(0);
assertThat(c.compare(dog, dog)).isEqualTo(0);
assertThat(c.compare(dog2, dog)).isLessThan(0);
}
@Test
@@ -49,7 +49,7 @@ public class PropertyComparatorTests {
Dog dog = new Dog();
Dog dog2 = new Dog();
PropertyComparator<Dog> c = new PropertyComparator<>("nickName", false, true);
assertThat(c.compare(dog, dog2) == 0).isTrue();
assertThat(c.compare(dog, dog2)).isEqualTo(0);
}
@Test
@@ -64,13 +64,13 @@ public class PropertyComparatorTests {
dog2.setFirstName("biscuit");
dog2.setLastName("grayspots");
assertThat(c.compare(dog1, dog2) == 0).isTrue();
assertThat(c.compare(dog1, dog2)).isEqualTo(0);
c = c.thenComparing(new PropertyComparator<>("firstName", false, true));
assertThat(c.compare(dog1, dog2) > 0).isTrue();
assertThat(c.compare(dog1, dog2)).isGreaterThan(0);
dog2.setLastName("konikk dog");
assertThat(c.compare(dog2, dog1) > 0).isTrue();
assertThat(c.compare(dog2, dog1)).isGreaterThan(0);
}
@Test
@@ -86,9 +86,9 @@ public class PropertyComparatorTests {
dog2.setFirstName("biscuit");
dog2.setLastName("grayspots");
assertThat(c.compare(dog1, dog2) > 0).isTrue();
assertThat(c.compare(dog1, dog2)).isGreaterThan(0);
c = c.reversed();
assertThat(c.compare(dog1, dog2) < 0).isTrue();
assertThat(c.compare(dog1, dog2)).isLessThan(0);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,11 +58,11 @@ public abstract class AbstractBeanFactoryTests {
assertThat(getBeanFactory().containsBean("roderick")).isTrue();
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
TestBean roderick = (TestBean) getBeanFactory().getBean("roderick");
assertThat(rod != roderick).as("not == ").isTrue();
assertThat(rod).as("not == ").isNotSameAs(roderick);
assertThat(rod.getName().equals("Rod")).as("rod.name is Rod").isTrue();
assertThat(rod.getAge() == 31).as("rod.age is 31").isTrue();
assertThat(rod.getAge()).as("rod.age is 31").isEqualTo(31);
assertThat(roderick.getName().equals("Roderick")).as("roderick.name is Roderick").isTrue();
assertThat(roderick.getAge() == rod.getAge()).as("roderick.age was inherited").isTrue();
assertThat(roderick.getAge()).as("roderick.age was inherited").isEqualTo(rod.getAge());
}
@Test
@@ -104,7 +104,7 @@ public abstract class AbstractBeanFactoryTests {
assertThat(condition).as("Rod bean is a TestBean").isTrue();
TestBean rod = (TestBean) o;
assertThat(rod.getName().equals("Rod")).as("rod.name is Rod").isTrue();
assertThat(rod.getAge() == 31).as("rod.age is 31").isTrue();
assertThat(rod.getAge()).as("rod.age is 31").isEqualTo(31);
}
@Test
@@ -158,19 +158,19 @@ public abstract class AbstractBeanFactoryTests {
Object o1 = getBeanFactory().getBean("rod");
boolean condition = o1 instanceof TestBean;
assertThat(condition).as("Rod bean2 is a TestBean").isTrue();
assertThat(o == o1).as("Object equals applies").isTrue();
assertThat(o).as("Object equals applies").isSameAs(o1);
}
@Test
public void prototypeInstancesAreIndependent() {
TestBean tb1 = (TestBean) getBeanFactory().getBean("kathy");
TestBean tb2 = (TestBean) getBeanFactory().getBean("kathy");
assertThat(tb1 != tb2).as("ref equal DOES NOT apply").isTrue();
assertThat(tb1).as("ref equal DOES NOT apply").isNotSameAs(tb2);
assertThat(tb1.equals(tb2)).as("object equal true").isTrue();
tb1.setAge(1);
tb2.setAge(2);
assertThat(tb1.getAge() == 1).as("1 age independent = 1").isTrue();
assertThat(tb2.getAge() == 2).as("2 age independent = 2").isTrue();
assertThat(tb1.getAge()).as("1 age independent = 1").isEqualTo(1);
assertThat(tb2.getAge()).as("2 age independent = 2").isEqualTo(2);
boolean condition = !tb1.equals(tb2);
assertThat(condition).as("object equal now false").isTrue();
}
@@ -212,8 +212,8 @@ public abstract class AbstractBeanFactoryTests {
assertThat(tb.getName().equals(DummyFactory.SINGLETON_NAME)).as("Singleton from factory has correct name, not " + tb.getName()).isTrue();
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
TestBean tb2 = (TestBean) getBeanFactory().getBean("singletonFactory");
assertThat(tb == tb2).as("Singleton references ==").isTrue();
assertThat(factory.getBeanFactory() != null).as("FactoryBean is BeanFactoryAware").isTrue();
assertThat(tb).as("Singleton references ==").isSameAs(tb2);
assertThat(factory.getBeanFactory()).as("FactoryBean is BeanFactoryAware").isNotNull();
}
@Test
@@ -224,7 +224,7 @@ public abstract class AbstractBeanFactoryTests {
boolean condition = !tb.getName().equals(DummyFactory.SINGLETON_NAME);
assertThat(condition).isTrue();
TestBean tb2 = (TestBean) getBeanFactory().getBean("prototypeFactory");
assertThat(tb != tb2).as("Prototype references !=").isTrue();
assertThat(tb).as("Prototype references !=").isNotSameAs(tb2);
}
/**
@@ -274,7 +274,7 @@ public abstract class AbstractBeanFactoryTests {
cbf.registerAlias("rod", alias);
Object rod = getBeanFactory().getBean("rod");
Object aliasRod = getBeanFactory().getBean(alias);
assertThat(rod == aliasRod).isTrue();
assertThat(rod).isSameAs(aliasRod);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,24 +50,25 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
protected final void assertCount(int count) {
String[] defnames = getListableBeanFactory().getBeanDefinitionNames();
assertThat(defnames.length == count).as("We should have " + count + " beans, not " + defnames.length).isTrue();
assertThat(defnames.length).as("We should have " + count + " beans, not " + defnames.length).isEqualTo(count);
}
protected void assertTestBeanCount(int count) {
String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false);
assertThat(defNames.length == count).as("We should have " + count + " beans for class org.springframework.beans.testfixture.beans.TestBean, not " +
defNames.length).isTrue();
assertThat(defNames.length).as("We should have " + count + " beans for class org.springframework.beans.testfixture.beans.TestBean, not " +
defNames.length).isEqualTo(count);
int countIncludingFactoryBeans = count + 2;
String[] names = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, true);
assertThat(names.length == countIncludingFactoryBeans).as("We should have " + countIncludingFactoryBeans +
" beans for class org.springframework.beans.testfixture.beans.TestBean, not " + names.length).isTrue();
assertThat(names.length).as("We should have " + countIncludingFactoryBeans +
" beans for class org.springframework.beans.testfixture.beans.TestBean, not " + names.length)
.isEqualTo(countIncludingFactoryBeans);
}
@Test
public void getDefinitionsForNoSuchClass() {
String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class);
assertThat(defnames.length == 0).as("No string definitions").isTrue();
assertThat(defnames.length).as("No string definitions").isEqualTo(0);
}
/**
@@ -76,11 +77,11 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
*/
@Test
public void getCountForFactoryClass() {
assertThat(getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2).as("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length).isTrue();
assertThat(getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length).as("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length).isEqualTo(2);
assertThat(getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2).as("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length).isTrue();
assertThat(getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length).as("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length).isEqualTo(2);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -222,7 +222,7 @@ class CandidateComponentsIndexerTests {
for (Class<?> c : classes) {
assertThat(metadata).has(Metadata.of(c, Component.class));
}
assertThat(metadata.getItems()).hasSize(classes.length);
assertThat(metadata.getItems()).hasSameSizeAs(classes);
}
private void testSingleComponent(Class<?> target, Class<?>... stereotypes) {
@@ -93,11 +93,11 @@ public class CaffeineCacheManagerTests {
Cache cache1x = cm.getCache("c1");
boolean condition1 = cache1x instanceof CaffeineCache;
assertThat(condition1).isTrue();
assertThat(cache1x != cache1).isTrue();
assertThat(cache1x).isNotSameAs(cache1);
Cache cache2x = cm.getCache("c2");
boolean condition = cache2x instanceof CaffeineCache;
assertThat(condition).isTrue();
assertThat(cache2x != cache2).isTrue();
assertThat(cache2x).isNotSameAs(cache2);
Cache cache3x = cm.getCache("c3");
assertThat(cache3x).isNull();
@@ -123,7 +123,7 @@ public class CaffeineCacheManagerTests {
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().maximumSize(10);
cm.setCaffeine(caffeine);
Cache cache1x = cm.getCache("c1");
assertThat(cache1x != cache1).isTrue();
assertThat(cache1x).isNotSameAs(cache1);
cm.setCaffeine(caffeine); // Set same instance
Cache cache1xx = cm.getCache("c1");
@@ -137,7 +137,7 @@ public class CaffeineCacheManagerTests {
cm.setCaffeineSpec(CaffeineSpec.parse("maximumSize=10"));
Cache cache1x = cm.getCache("c1");
assertThat(cache1x != cache1).isTrue();
assertThat(cache1x).isNotSameAs(cache1);
}
@Test
@@ -147,7 +147,7 @@ public class CaffeineCacheManagerTests {
cm.setCacheSpecification("maximumSize=10");
Cache cache1x = cm.getCache("c1");
assertThat(cache1x != cache1).isTrue();
assertThat(cache1x).isNotSameAs(cache1);
}
@Test
@@ -160,7 +160,7 @@ public class CaffeineCacheManagerTests {
cm.setCacheLoader(loader);
Cache cache1x = cm.getCache("c1");
assertThat(cache1x != cache1).isTrue();
assertThat(cache1x).isNotSameAs(cache1);
cm.setCacheLoader(loader); // Set same instance
Cache cache1xx = cm.getCache("c1");
@@ -201,11 +201,11 @@ public class CaffeineCacheManagerTests {
Cache cache1 = cm.getCache("c1");
Cache cache2 = cm.getCache("c2");
assertThat(nc == cache2.getNativeCache()).isTrue();
assertThat(nc).isSameAs(cache2.getNativeCache());
cm.setCaffeine(Caffeine.newBuilder().maximumSize(10));
assertThat(cm.getCache("c1") != cache1).isTrue();
assertThat(cm.getCache("c2") == cache2).isTrue();
assertThat(cm.getCache("c1")).isNotSameAs(cache1);
assertThat(cm.getCache("c2")).isSameAs(cache2);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ public class JCacheCustomInterceptorTests {
@Test
public void onlyOneInterceptorIsAvailable() {
Map<String, JCacheInterceptor> interceptors = ctx.getBeansOfType(JCacheInterceptor.class);
assertThat(interceptors.size()).as("Only one interceptor should be defined").isEqualTo(1);
assertThat(interceptors).as("Only one interceptor should be defined").hasSize(1);
JCacheInterceptor interceptor = interceptors.values().iterator().next();
assertThat(interceptor.getClass()).as("Custom interceptor not defined").isEqualTo(TestCacheInterceptor.class);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,8 @@ public abstract class AbstractCacheOperationTests<O extends JCacheOperation<?>>
public void simple() {
O operation = createSimpleOperation();
assertThat(operation.getCacheName()).as("Wrong cache name").isEqualTo("simpleCache");
assertThat(operation.getAnnotations().size()).as("Unexpected number of annotation on " + operation.getMethod()).isEqualTo(1);
assertThat(operation.getAnnotations()).as("Unexpected number of annotation on " + operation.getMethod())
.hasSize(1);
assertThat(operation.getAnnotations().iterator().next()).as("Wrong method annotation").isEqualTo(operation.getCacheAnnotation());
assertThat(operation.getCacheResolver()).as("cache resolver should be set").isNotNull();
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,25 +37,25 @@ public class InternetAddressEditorTests {
@Test
public void uninitialized() {
assertThat(editor.getAsText()).as("Uninitialized editor did not return empty value string").isEqualTo(EMPTY);
assertThat(editor.getAsText()).as("Uninitialized editor did not return empty value string").isEmpty();
}
@Test
public void setNull() {
editor.setAsText(null);
assertThat(editor.getAsText()).as("Setting null did not result in empty value string").isEqualTo(EMPTY);
assertThat(editor.getAsText()).as("Setting null did not result in empty value string").isEmpty();
}
@Test
public void setEmpty() {
editor.setAsText(EMPTY);
assertThat(editor.getAsText()).as("Setting empty string did not result in empty value string").isEqualTo(EMPTY);
assertThat(editor.getAsText()).as("Setting empty string did not result in empty value string").isEmpty();
}
@Test
public void allWhitespace() {
editor.setAsText(" ");
assertThat(editor.getAsText()).as("All whitespace was not recognized").isEqualTo(EMPTY);
assertThat(editor.getAsText()).as("All whitespace was not recognized").isEmpty();
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,8 +39,8 @@ public class QuartzSchedulerLifecycleTests {
sw.start("lazyScheduler");
context.close();
sw.stop();
assertThat(sw.getTotalTimeMillis() < 500).as("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis()).isTrue();
assertThat(sw.getTotalTimeMillis()).as("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis()).isLessThan(500);
}
@Test // SPR-6354
@@ -52,8 +52,8 @@ public class QuartzSchedulerLifecycleTests {
sw.start("lazyScheduler");
context.close();
sw.stop();
assertThat(sw.getTotalTimeMillis() < 500).as("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis()).isTrue();
assertThat(sw.getTotalTimeMillis()).as("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis()).isLessThan(500);
}
}
@@ -126,7 +126,7 @@ class QuartzSupportTests {
bean.start();
Thread.sleep(500);
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
assertThat(DummyJob.count).as("DummyJob should have been executed at least once.").isGreaterThan(0);
assertThat(taskExecutor.count).isEqualTo(DummyJob.count);
bean.destroy();
@@ -168,7 +168,7 @@ class QuartzSupportTests {
Thread.sleep(500);
assertThat(DummyJobBean.param).isEqualTo(10);
assertThat(DummyJobBean.count > 0).isTrue();
assertThat(DummyJobBean.count).isGreaterThan(0);
bean.destroy();
}
@@ -203,7 +203,7 @@ class QuartzSupportTests {
Thread.sleep(500);
assertThat(DummyJob.param).isEqualTo(10);
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
assertThat(DummyJob.count).as("DummyJob should have been executed at least once.").isGreaterThan(0);
bean.destroy();
}
@@ -239,7 +239,7 @@ class QuartzSupportTests {
Thread.sleep(500);
assertThat(DummyJob.param).isEqualTo(0);
assertThat(DummyJob.count == 0).isTrue();
assertThat(DummyJob.count).isEqualTo(0);
bean.destroy();
}
@@ -273,7 +273,7 @@ class QuartzSupportTests {
Thread.sleep(500);
assertThat(DummyJobBean.param).isEqualTo(10);
assertThat(DummyJobBean.count > 0).isTrue();
assertThat(DummyJobBean.count).isGreaterThan(0);
bean.destroy();
}
@@ -292,7 +292,7 @@ class QuartzSupportTests {
Thread.sleep(500);
assertThat(DummyJob.param).isEqualTo(10);
assertThat(DummyJob.count > 0).as("DummyJob should have been executed at least once.").isTrue();
assertThat(DummyJob.count).as("DummyJob should have been executed at least once.").isGreaterThan(0);
bean.destroy();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,7 +106,7 @@ import org.springframework.core.io.support.PropertySourceFactory;
*
* <h3>A note on property overriding with {@code @PropertySource}</h3>
*
* <p>In cases where a given property key exists in more than one {@code .properties}
* <p>In cases where a given property key exists in more than one property resource
* file, the last {@code @PropertySource} annotation processed will 'win' and override
* any previous key with the same name.
*
@@ -182,14 +182,13 @@ public @interface PropertySource {
String name() default "";
/**
* Indicate the resource location(s) of the properties file to be loaded.
* <p>Both traditional and XML-based properties file formats are supported
* &mdash; for example, {@code "classpath:/com/myco/app.properties"}
* or {@code "file:/path/to/file.xml"}.
* Indicate the resource locations of the properties files to be loaded.
* <p>The default {@link #factory() factory} supports both traditional and
* XML-based properties file formats &mdash; for example,
* {@code "classpath:/com/myco/app.properties"} or {@code "file:/path/to/file.xml"}.
* <p>Resource location wildcards (e.g. *&#42;/*.properties) are not permitted;
* each location must evaluate to exactly one {@code .properties} or {@code .xml}
* resource.
* <p>${...} placeholders will be resolved against any/all property sources already
* each location must evaluate to exactly one resource.
* <p>${...} placeholders will be resolved against property sources already
* registered with the {@code Environment}. See {@linkplain PropertySource above}
* for examples.
* <p>Each location will be added to the enclosing {@code Environment} as its own
@@ -214,7 +213,9 @@ public @interface PropertySource {
/**
* Specify a custom {@link PropertySourceFactory}, if any.
* <p>By default, a default factory for standard resource files will be used.
* <p>By default, a default factory for standard resource files will be used
* which supports {@code *.properties} and {@code *.xml} file formats for
* {@link java.util.Properties}.
* @since 4.3
* @see org.springframework.core.io.support.DefaultPropertySourceFactory
* @see org.springframework.core.io.support.ResourcePropertySource
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -281,11 +281,11 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
return executor.schedule(task, new TriggerAdapter(trigger));
}
private static class TriggerAdapter implements jakarta.enterprise.concurrent.Trigger {
private final Trigger adaptee;
public TriggerAdapter(Trigger adaptee) {
this.adaptee = adaptee;
}
@@ -294,48 +294,45 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
@Nullable
public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) {
Instant instant = this.adaptee.nextExecution(new LastExecutionAdapter(le));
return instant != null ? Date.from(instant) : null;
return (instant != null ? Date.from(instant) : null);
}
@Nullable
private static Instant toInstant(@Nullable Date date) {
return date != null ? date.toInstant() : null;
}
@Override
public boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime) {
return false;
}
private static class LastExecutionAdapter implements TriggerContext {
@Nullable
private final LastExecution le;
public LastExecutionAdapter(@Nullable LastExecution le) {
this.le = le;
}
@Override
public Instant lastScheduledExecution() {
return (this.le != null) ? toInstant(this.le.getScheduledStart()) : null;
return (this.le != null ? toInstant(this.le.getScheduledStart()) : null);
}
@Override
public Instant lastActualExecution() {
return (this.le != null) ? toInstant(this.le.getRunStart()) : null;
return (this.le != null ? toInstant(this.le.getRunStart()) : null);
}
@Override
public Instant lastCompletion() {
return (this.le != null) ? toInstant(this.le.getRunEnd()) : null;
return (this.le != null ? toInstant(this.le.getRunEnd()) : null);
}
@Nullable
private static Instant toInstant(@Nullable Date date) {
return (date != null ? date.toInstant() : null);
}
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,7 +125,7 @@ public class FieldError extends ObjectError {
@Override
public String toString() {
return "Field error in object '" + getObjectName() + "' on field '" + this.field +
"': rejected value [" + ObjectUtils.nullSafeToString(this.rejectedValue) + "]; " +
"': rejected value [" + ObjectUtils.nullSafeConciseToString(this.rejectedValue) + "]; " +
resolvableToString();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,8 +74,9 @@ class ProceedTests {
@Test
void testProceedWithArgsInSameAspect() {
this.testBean.setMyFloat(1.0F);
assertThat(this.testBean.getMyFloat() > 1.9F).as("value changed in around advice").isTrue();
assertThat(this.firstTestAspect.getLastBeforeFloatValue() > 1.9F).as("changed value visible to next advice in chain").isTrue();
assertThat(this.testBean.getMyFloat()).as("value changed in around advice").isGreaterThan(1.9F);
assertThat(this.firstTestAspect.getLastBeforeFloatValue()).as("changed value visible to next advice in chain")
.isGreaterThan(1.9F);
}
@Test
@@ -258,7 +258,7 @@ class AspectJAutoProxyCreatorTests {
AdviceUsingThisJoinPoint aspectInstance = (AdviceUsingThisJoinPoint) bf.getBean("aspect");
//(AdviceUsingThisJoinPoint) Aspects.aspectOf(AdviceUsingThisJoinPoint.class);
//assertEquals("method-execution(int TestBean.getAge())",aspectInstance.getLastMethodEntered());
assertThat(aspectInstance.getLastMethodEntered().indexOf("TestBean.getAge())") != 0).isTrue();
assertThat(aspectInstance.getLastMethodEntered()).doesNotStartWith("TestBean.getAge())");
}
@Test

Some files were not shown because too many files have changed in this diff Show More