Commit Graph

1410 Commits

Author SHA1 Message Date
Phillip Webb 95a9d46a87 Migrate Hamcrest assertions to AssertJ
Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ
and add checkstyle rules to ensure they don't return.

See gh-23022
2019-05-23 15:49:59 -07:00
Phillip Webb 02850f357f Migrate exception checking tests to use AssertJ
Migrate tests that use `@Test(expectedException=...)` or
`try...fail...catch` to use AssertJ's `assertThatException`
instead.
2019-05-20 10:47:53 -07:00
Juergen Hoeller 9755b59197 Merge branch '5.1.x' 2019-05-13 18:05:07 +02:00
Juergen Hoeller 5910d2d4dc Add missing Nullable annotation to assertNotNull
See gh-22932
2019-05-13 18:03:01 +02:00
stsypanov 9ca8681f79 Iteration over a map using EntrySet 2019-05-13 15:38:13 +02:00
Sam Brannen 73dbd06361 Enforces static imports for JUnit 4 assertions and assumptions
This commit configures Checkstyle to enforces static imports for JUnit 4
assertions and assumptions.

See gh-22932
2019-05-12 15:13:07 +02:00
Sam Brannen da1b004254 Merge branch '5.1.x' 2019-05-11 18:21:44 +02:00
Sam Brannen e1b0bf22bf Polish Javadoc for AssertionErrors
See gh-22932
2019-05-11 18:21:06 +02:00
Sam Brannen 33fcde4c3e Merge branch '5.1.x' 2019-05-11 18:04:48 +02:00
Sam Brannen 233b225b4f Remove JUnit dependency from HeaderResultMatchers
Prior to this commit, HeaderResultMatchers had a direct dependency on
org.junit.Assert which forces JUnit 4 to be present on the classpath.

This commit fixes this by introducing assertNotNull() in
org.springframework.test.util.AssertionErrors and delegating to that
instead.

Fixes gh-22932
2019-05-11 18:03:42 +02:00
Sam Brannen 0cff7eb32c Fix Javadoc links 2019-05-10 17:40:03 +02:00
Phillip Webb 798b51f4a3 Migrate to BDD Mockito
Migrate all tests to consistently use BDD Mockito. Also add
checksyle rule to enforce going forwards.
2019-05-08 13:46:13 -07:00
Phillip Webb 816bbee8de Remove '.*' imports from tests
Organize test imports to expand all '.*' static imports into
fully qualified imports.

This update will allow us to use additional checkstyle rules in
the future, and will also help if we migrate fully to AssertJ.
2019-05-08 09:55:09 -07:00
Juergen Hoeller d3b713d5f0 Upgrade to Protobuf 3.7.1 and HtmlUnit 2.35 2019-05-08 17:52:56 +02:00
Sam Brannen 6a05b97df3 Log identity hash for ApplicationContext for context cache hits/misses
DefaultCacheAwareContextLoaderDelegate now logs the identity hash code
for an application context instance that was stored in or retrieved from
the context cache in the Spring TestContext Framework.

Closes gh-22925
2019-05-08 16:39:23 +02:00
Phil Webb d7320de871 Migrate away from ExpectedException (#22922)
* Add limited checkstyles to test code

Add a limited set of checkstyle rules to the test codebase to improve
code consistency.

* Fix checksyle violations in test code

* Organize imports to fix checkstyle for test code

* Migrate to assertThatExceptionOfType

Migrate aware from ExpectedException rules to AssertJ exception
assertions. Also include a checkstyle rules to ensure that the
the ExpectedException is not accidentally used in the future.

See gh-22894
2019-05-08 16:25:52 +02:00
Sam Brannen 77eef47483 Support automatic constructor injection in JUnit Jupiter
Prior to this commit, dependency injection of all arguments in a test
class constructor invoked by JUnit Jupiter was only possible if the
constructor was explicitly annotated with @Autowired.

This commit introduces support for a configurable "test constructor
autowire" mode which defaults to false in order to remain backwards
compatible.

Specifically, this mode can be configured globally for an entire test
suite via a new "spring.test.constructor.autowire" JVM system property
that can alternatively be configured via the SpringProperties
mechanism. In addition, the global "test constructor autowire" mode can
be overridden locally on a per-class basis via the new @TestConstructor
annotation.

Closes gh-22286
2019-05-08 14:51:43 +02:00
Sam Brannen d4379630e2 Use assertThat from Hamcrest instead of JUnit 4
org.junit.Assert.assertThat() is deprecated as of JUnit 4.13.

See gh-22894
2019-05-05 17:31:31 +02:00
Sam Brannen 772ef40920 Upgrade to JUnit 4.13-beta-3
See gh-22894
2019-05-05 16:56:48 +02:00
Juergen Hoeller ec8689d1fc Merge branch '5.1.x' 2019-05-03 14:23:59 +02:00
Juergen Hoeller 4e10735e8f MockHttpServletRequest restores default locale for empty accept header
Closes gh-22877
2019-05-03 14:08:12 +02:00
Juergen Hoeller 0be610b0ee Support for reactive transactions in TransactionInterceptor
Introduces TransactionManager marker interface for PlatformTransactionManager as well as ReactiveTransactionManager, allowing for a common configuration type in TransactionAspectSupport and TransactionManagementConfigurer.

Closes gh-22590
2019-05-02 16:23:48 +02:00
Sebastien Deleuze 89454e69c3 Deprecate MediaType.APPLICATION_JSON_UTF8
This commit deprecates MediaType.APPLICATION_JSON_UTF8 and
MediaType.APPLICATION_PROBLEM_JSON_UTF8 in favor of
MediaType.APPLICATION_JSON and MediaType.APPLICATION_PROBLEM_JSON since
UTF-8 encoding is now handled correctly by most browsers
(related bug has been fixed in Chrome since September 2017).

MediaType.APPLICATION_JSON is now used as the default JSON content type.

Closes gh-22788
2019-04-30 16:11:50 +02:00
Juergen Hoeller 55418b256d Merge branch '5.1.x' 2019-04-26 16:56:04 +02:00
Juergen Hoeller e5e2d2d661 Polishing (includes minor performance refinements from master) 2019-04-26 16:51:18 +02:00
Johnny Lim 33ac14f099 Add missing fail() calls in MockRestServiceServerTests
Closes gh-22836
2019-04-25 17:34:50 +03:00
Sam Brannen 4a090922d7 Polish Javadoc 2019-04-21 15:33:53 +02:00
Rossen Stoyanchev de3238dbea Merge branch '5.1.x' 2019-04-16 21:08:54 -04:00
Rossen Stoyanchev 5b711a964b Pass Mono to Reactor Netty when feasible
Closes gh-22800
2019-04-16 20:52:19 -04:00
Juergen Hoeller 44df98c82d Merge branch '5.1.x' 2019-04-12 11:37:07 +02:00
Juergen Hoeller b07d46da99 MockCookie compares attributes in case-insensitive manner
Closes gh-22786
2019-04-12 11:10:02 +02:00
Sam Brannen 7f58e395d3 Remove @Deprecated from org.springframework.mock.jndi package
This commit removes the @Deprecated declaration on the
org.springframework.mock.jndi package, since such usage results in a
compiler warning on JDK 9+ which breaks Spring's JDK 9 and JDK 11 CI
builds.

https://bugs.openjdk.java.net/browse/JDK-6481080

See gh-22779
2019-04-11 16:17:58 +02:00
Sam Brannen 88e3b84164 Deprecate mock JNDI support in the spring-test module
Closes gh-22779
2019-04-10 16:00:05 +02:00
Rossen Stoyanchev d1f888a7a9 Empty path mapping behaves consistently
An empty path mapping in an @RequestMapping now consistently matches to
empty paths regardless of whether there are both type and method level,
annotations, or method-level only.

Closes gh-22543
2019-04-09 15:03:43 -04:00
Sam Brannen cf5d0e6aa9 Introduce publishEvent() convenience method in TestContext
This commit introduces a publishEvent() method in the TestContext API
as a convenience for publishing an ApplicationEvent to the test's
ApplicationContext but only if the ApplicationContext is currently
available and with lazy creation of the ApplicationEvent.

For example, the beforeTestClass() method in
EventPublishingTestExecutionListener is now implemented as follows.

  public void beforeTestClass(TestContext testContext) {
      testContext.publishEvent(BeforeTestClassEvent::new);
  }

Closes gh-22765
2019-04-08 15:14:39 +02:00
Sam Brannen 353e092bf6 Register EventPublishingTestExecutionListener by default (round 2)
This commit registers the EventPublishingTestExecutionListener as a
default TestExecutionListener with an order of 10,000. This registers
the EventPublishingTestExecutionListener as the last listener provided
by the Spring Framework.

With EventPublishingTestExecutionListener registered with an order of
10,000, it is effectively wrapped by all other Spring listeners,
including support for @DirtiesContext and test-managed transactions.

Furthermore, this commit revises the implementation of
EventPublishingTestExecutionListener to take advantage of the new
TestContext#hasApplicationContext() support which allows the
EventPublishingTestExecutionListener to publish events only if the
test's ApplicationContext is currently available. This avoids
undesirable side-effects such as eager loading of the
ApplicationContext before it is needed or re-loading of the
ApplicationContext after it has been intentionally closed.

Closes gh-18490
2019-04-06 16:39:26 +02:00
Sam Brannen c3d0459a4e Add support to query if ApplicationContext is available in the TCF
This commit introduces support in the Spring TestContext Framework
(TCF) to query whether the test's ApplicationContext is available.

Specifically, this commit introduces the following two `default`
methods along with corresponding implementations in DefaultTestContext
and DefaultCacheAwareContextLoaderDelegate.

- `boolean hasApplicationContext()` in the TestContext API

- `boolean isContextLoaded(MergedContextConfiguration)` in the
  CacheAwareContextLoaderDelegate API

Closes gh-22756
2019-04-06 16:00:33 +02:00
Rossen Stoyanchev ed70978071 verify() fails if there are failed requests
Normally failed requests fail the test but they're suppressed for some
reason (e.g. in async callback) then verify should still correctly
report the failures.

Closes gh-21799
2019-04-04 16:49:46 -04:00
Sam Brannen 4be605eb1e Revert "Fix tests"
This reverts commit 07e9f802f2.
2019-04-04 19:10:58 +02:00
Sam Brannen d6ba5259d8 Revert "Register EventPublishingTestExecutionListener by default"
This reverts commit 86fb7362b1.
2019-04-04 19:10:58 +02:00
Sam Brannen a66e6d3231 Revert "Fix tests"
This reverts commit 65365d91c8.
2019-04-04 19:10:58 +02:00
Sam Brannen f7a5b3013e Revert "Register EventPublishingTestExecutionListener by default"
This reverts commit 13543f5e0f.
2019-04-04 19:10:58 +02:00
Juergen Hoeller 1741b6dcd9 Merge branch '5.1.x' 2019-04-04 16:12:07 +02:00
Juergen Hoeller 95232d5bf8 Upgrade to Apache HttpClient 4.5.8 and Jetty Reactive HttpClient 1.0.3 2019-04-04 16:10:16 +02:00
Sam Brannen 07e9f802f2 Fix tests
See gh-18490
2019-04-04 12:55:55 +02:00
Sam Brannen 86fb7362b1 Register EventPublishingTestExecutionListener by default
See gh-18490
2019-04-04 12:55:06 +02:00
Brian Clozel 65365d91c8 Fix tests
See gh-18490
2019-04-04 11:19:31 +02:00
Sam Brannen 13543f5e0f Register EventPublishingTestExecutionListener by default
Closes gh-18490
2019-04-03 18:31:16 +02:00
Sam Brannen d6173512fe Document test execution event support in the Reference Manual
Closes gh-18490
2019-04-03 18:18:39 +02:00
Brian Clozel 47c8d1de7b Avoid calling other bean methods in web config
This commit changes the main configuration classes for Spring MVC and
Spring WebFlux to not call other bean methods when setting up the web
infrastructure. This allows configuration classes extending
`DelegatingWebFluxConfiguration` and `DelegatingWebMvcConfiguration`
to opt-in the lite-mode, as introduced in gh-22461.
2019-04-03 10:16:41 +02:00