Commit Graph

267 Commits

Author SHA1 Message Date
Phillip Webb
fac6b8da47 Upgrade to JSONassert 1.4.0
Closes gh-7846
2017-01-05 00:00:07 -08:00
Johnny Lim
f915ae197a Polish 2017-01-04 09:53:45 +01:00
Phillip Webb
8ccd4db513 Merge branch '1.4.x' into 1.5.x 2017-01-03 15:14:14 -08:00
Phillip Webb
556ce14f2d Fix TestRestTemplate.withBasicAuth interceptors
Update `TestRestTemplate` to handle `BasicAuthorizationInterceptor`s
correctly. Prior to this commit the `BasicAuthorizationInterceptor`
was added directly to the `ClientHttpRequestFactory` rather than
to the `RestTemplate`. This meant that it could not easily be removed
when `TestRestTemplate.withBasicAuth` was invoked.

The `TestRestTemplate` now sets the interceptor on `RestTemplate`
directly and relies on the logic in `InterceptingHttpAccessor` to
add it to the `ClientHttpRequestFactory`.

Fixes gh-7812
2017-01-03 15:12:30 -08:00
Phillip Webb
8b69856fc9 Polish 2016-12-28 15:23:26 -08:00
Stephane Nicoll
25bd0e0455 Do not reset server.port if a custom inline property is set
This commit allows to define `server.port` in a non-embedded web
environment. Previously, `server.port` would have been set to `-1`
regardless.

Closes gh-7353
2016-12-28 12:10:04 +01:00
Phillip Webb
884c9ef11e Remove accidentally committed file 2016-12-27 15:18:17 -08:00
Phillip Webb
e0541d0f74 Polish 2016-12-27 14:48:44 -08:00
Stephane Nicoll
37519ecfef Merge branch '1.4.x' into 1.5.x 2016-12-25 10:00:33 +01:00
Stephane Nicoll
062104f1d6 Fix TestRestTemplate#patchFor methods visibility
Closes gh-7742
2016-12-25 10:00:20 +01:00
Spring Buildmaster
9057f9ae1f Next development version 2016-12-23 00:15:23 +00:00
Phillip Webb
765fd1dca0 Merge branch '1.4.x' into 1.5.x 2016-12-21 20:15:54 -08:00
Phillip Webb
138b96cf5f Use unique testRestTemplate bean name
Update `SpringBootTestContextCustomizer` to use the full qualified
TestRestTemplate as the registered bean name. Prior to this commit it
was possible that the customizer would replace the relatively common
bean name `testRestTemplate`.

Fixes gh-7711
2016-12-21 11:42:56 -08:00
Phillip Webb
73a45797c0 Merge branch '1.4.x' into 1.5.x 2016-12-19 18:45:35 -08:00
Phillip Webb
7824171413 Allow @SpyBean to work with @Primary beans
Update `MockitoPostProcessor` so that `@SpyBean` will automatically
pick the `@Primary` bean when multiple candidates exist.

Fixes gh-7621
2016-12-19 18:14:51 -08:00
Phillip Webb
87547f208a Add test for @SpyBean for generic bean definition
Add an integration test to check that @SpyBean can be used with on a
bean definition that returns a generic type.

Closes gh-7625
2016-12-19 15:58:25 -08:00
Phillip Webb
4b9cba351b Merge branch '1.4.x' into 1.5.x 2016-12-19 12:36:57 -08:00
Phillip Webb
bd74c3d327 Polish formatting 2016-12-19 12:25:09 -08:00
Stephane Nicoll
28e86272e8 Merge branch '1.4.x' into 1.5.x 2016-12-19 11:30:56 +01:00
Stephane Nicoll
863f97dc11 Polish since version
Closes gh-7412
2016-12-19 11:30:38 +01:00
Andy Wilkinson
367de7bf71 Add support for new PATCH methods to TestRestTemplate
Closes gh-7412
2016-12-19 11:27:10 +01:00
Phillip Webb
f6b0652369 Merge branch '1.4.x' into 1.5.x 2016-12-05 11:17:13 -08:00
Phillip Webb
e430583eaf Polish 2016-12-05 11:08:38 -08:00
Stephane Nicoll
ee72e788ed Rename spring-boot-junit-runners to spring-boot-test-support
Closes gh-7421
2016-12-01 16:25:47 +01:00
Andy Wilkinson
3ac22e7cdf Merge branch '1.4.x' into 1.5.x 2016-12-01 09:38:41 +00:00
Andy Wilkinson
d9b8fc960c Correct the scope of the spock-core dependency in spring-boot-test
See gh-7524
2016-12-01 09:38:07 +00:00
Andy Wilkinson
1d476b375f Merge branch '1.4.x' into 1.5.x 2016-11-30 21:00:36 +00:00
Andy Wilkinson
45d672f5b3 Ignore Spock annotations when creating test context cache key
Closes gh-7524
2016-11-30 20:59:09 +00:00
Andy Wilkinson
3dcb2d5316 Merge branch '1.4.x' into 1.5.x 2016-11-25 10:41:41 +00:00
Andy Wilkinson
46e8cf4a43 Test that a broken factory bean does not break resetting of mocks
Previously, ResetMocksTestExecutionListener used getBean(name) to
retrieve each instantiated singleton. When the instantiated singleton
was a factory bean, this would cause getObject on the factory bean to
be called. If the factory bean was unable to produce its object, for
example due to test slicing excluding something, an exception would
be thrown.

The previous commit updated ResetMocksTestsExecutionListener to
use getSingleton(name) rather than getBean(name).  This will retrieve
the factory bean itself rather than causing the factory bean to
attempt to create an object. This commit updates the tests to verify
the new behaviour.

Closes gh-7270
2016-11-25 10:40:02 +00:00
Aleksander Bartnikiewicz
eb927f1b29 Prevent a broken factory bean from breaking the resetting of mocks
Closes gh-7271
2016-11-25 10:39:30 +00:00
Phillip Webb
88c84ce234 Merge branch '1.4.x' into 1.5.x 2016-11-22 14:53:30 -08:00
Phillip Webb
a3b79be6b3 Support @MockBean on FactoryBeans
Update @MockBean support so that FactoryBean classes can be mocked.

Fixes gh-7439
2016-11-22 13:49:28 -08:00
Phillip Webb
1452d3cd51 Ensure withBasicAuth keeps error handler
Fix `TestRestTemplate` so that any custom `ErrorHandler` isn't lost
when calling `withBasicAuth`.

Fixes gh-7441
2016-11-22 10:58:30 -08:00
Phillip Webb
1657120286 Move ModifiedClassPathRunner to its own module
Migrate `ModifiedClassPathRunner` from `spring-boot` test source to
its own module.

Fixes gh-7420
2016-11-18 17:27:54 -08:00
Andy Wilkinson
f35fa87366 Fix problems in SpringBootMockUtil reported by Checkstyle 2016-11-18 16:56:36 +00:00
Andy Wilkinson
1cd781b242 Make spring-boot-test compatible with Mockito 2.1 and 2.2
We use some internal Mockito classes and some  breaking API changes
have been made to them in Mockito 2. This commit introduces a utility
class, SpringBootMockUtil, to shield our code from these differences.
Mockito 1 is called directly and Mockito 2 is called via reflection.

To allow these changes to be tested, FilteredClassPathRunner has been
enhanced to also support overriding a dependency on the class path.
As a result it has been renamed to ModifiedClassPathRunner. The new
ClassPathOverrides annotation can be used to provide the Maven
coordinates of one or more dependencies that should be resolved and
added to the class path. Such additions are added to the start of
the class path so that they override any existing dependency that
contains the same classes.

Closes gh-6520
2016-11-18 16:39:44 +00:00
Phillip Webb
7daf69a393 Upgrade to HTMLUnit 2.23 (+selenium module 2.23.2)
Fixes gh-7232
2016-11-16 15:30:34 -08:00
Spring Buildmaster
e712a9ba8c Next Development Version 2016-11-08 16:55:37 +00:00
Stephane Nicoll
eddb10e4c9 Merge branch '1.4.x' into 1.5.x 2016-10-24 11:39:26 +02:00
Stephane Nicoll
4603d8259a Make MockitoTestExecutionListener public
Closes gh-7016
2016-10-24 11:37:20 +02:00
Andy Wilkinson
3ea09d2e04 Merge branch '1.4.x' into 1.5.x 2016-10-19 12:22:11 +01:00
Andy Wilkinson
02e89acd1e Add managed version for kotlin-runtime to spring-boot-parent
See gh-7101
2016-10-19 12:20:37 +01:00
Andy Wilkinson
f942fe4947 Merge branch '1.4.x' into 1.5.x 2016-10-19 12:09:35 +01:00
Andy Wilkinson
64d32191cf Ignore Kotlin annotations when creating test context cache key
Every classes that's compiled by Kotlin is annotated with
kotlin.Metadata. The attributes of this annotation always differ so
if they are used in the cache key, context caching will effectively
be disabled.

This commit updates the key used by ImportsContextCustomizer to
ignore the kotlin.Metadata annotation. Additionally, to align with
with Java where annotations in java.lang.annotation are ignored,
annotations in kotlin.annotation are also ignored.

Closes gh-7101
2016-10-19 12:03:33 +01:00
Phillip Webb
d3e06c4627 Merge branch '1.4.x' into 1.5.x 2016-10-11 21:46:06 -07:00
Phillip Webb
db3f488d5a Polish 2016-10-11 17:54:00 -07:00
Phillip Webb
f2b0fa284e Merge branch '1.4.x' into 1.5.x 2016-10-03 22:38:22 -07:00
Madhura Bhave
16fe332f51 Fix NoClassDefFoundError when Mockito is missing
Update MockReset class to check for the presence of the MockUtil class
before attempting to use it.

Fixes gh-7065
2016-10-03 22:27:20 -07:00
Phillip Webb
3326841a97 Formatting 2016-10-03 22:19:35 -07:00
Phillip Webb
f59cc25e2b Fix eclipse warnings 2016-10-03 21:51:16 -07:00
Stephane Nicoll
e643fc5bd1 Merge branch '1.4.x' into 1.5.x 2016-10-02 11:08:33 +02:00
Johnny Lim
503d735fdd Polish
Closes gh-7081
2016-10-02 11:07:04 +02:00
Stephane Nicoll
cdd59707fc Merge branch '1.4.x' into 1.5.x 2016-09-28 17:00:30 +02:00
Johnny Lim
30a677646f Polish
Closes gh-7030
2016-09-28 16:45:19 +02:00
Stephane Nicoll
ce1e41dce3 Remove deprecated code
This code removes code deprecated in 1.4 with the exception of code that
requires an update to Spring Framework 5.

Closes gh-6971
2016-09-21 14:30:28 +02:00
Stephane Nicoll
6bd670edbc Initiate 1.4.x branch 2016-09-21 11:11:24 +02:00
Spring Buildmaster
7e9ed5e1a7 Next Development Version 2016-09-21 07:58:07 +00:00
Stephane Nicoll
111743275f Polish 2016-09-19 15:17:27 +02:00
Johnny Lim
a994b11a73 Polish 2016-09-18 23:38:21 -07:00
Eddú Meléndez
bc55b6e0d4 Add contextPath LocalHostUriTemplateHandler URIs
Update `LocalHostUriTemplateHandler` so that the `server.context-path`
property is also considered when building the URL.

Fixes gh-6904
Closes gh-6919
2016-09-17 19:33:06 -07:00
Phillip Webb
aad40093ff Make Mock/Spy qualifiers part of context cache key
Refine @MockBean/@SpyBean qualifier support so that qualifiers form part
of the context cache key. Prior to this commit is was possible that two
different tests could accidentally share the same context if they
defined the same @Mock but with different @Qualifiers.

See gh-6753
2016-09-17 18:43:43 -07:00
Phillip Webb
04448d6bd9 Polish 2016-09-17 18:43:43 -07:00
Stephane Nicoll
3f236dc951 Support Qualifiers on MockBean and SpyBean
Previously, if an injection point used a qualifier, `MockBean` and
`SpyBean` couldn't be used to mock/spy it as there was no way to
specify that qualifier information.

This commit now detects qualifier information on the injection point
and associate it with the created `BeanDefintion`. If one wants to
mock a bean that is qualified with `@Qualifier("foo")`, the definition
of the mock should be as follows:

```
public class MyTest {

	@MockBean
	@Qualifier("foo")
	private ExampleService service;
}
```

As a side effect, it is now possible to mock a service by type even if
there are multiple instances of that type in the application context. The
provided qualifier information is used to determine the right candidate
and the proper bean definition is replaced accordingly.

Closes gh-6753
2016-09-16 11:17:23 +02:00
Phillip Webb
25c4e261e9 Fix failing tests
See gh-6897
2016-09-15 17:16:26 -07:00
Phillip Webb
5f7897ba41 Refine inner-class test @Configuration detection
Update detection logic to also consider `@Rules` classes. Also make the
documentation a little clearer.

Fixes gh-6768
2016-09-15 16:55:49 -07:00
Phillip Webb
ebb08c3655 Generate property meta-data for test projects
Add annotation processor to `spring-boot-test` and
`spring-boot-test-autoconfigure`.

Fixes gh-6893
2016-09-15 10:14:21 -07:00
Andy Wilkinson
7b3382e332 Fail fast if @WebAppConfiguration is used with a non-mock web environement
@WebAppConfiguration expects a mock web environment. If it is used
in conjuction with @SpringBootTest configured with a RANDOM_PORT or
DEFINED_PORT web environment a null pointer exception occurs as an
assumption that's made by MockServerContainerContextCustomizer doesn't
hold true in a non-mock web environment.

This commit updates SpringBootTestContextBootstrap to detect the
illegal configuration combination and fail fast, advising the user
to remove @WebAppConfiguration or reconfigure @SpringBootTest.

Closes gh-6795
2016-09-15 11:16:42 +01:00
Phillip Webb
7134586310 Ensure test @PostConstructs are only called once
Rename AutoConfigureReportTestExecutionListener to
SpringBootDependencyInjectionTestExecutionListener and ensure that it
replaces any existing DependencyInjectionTestExecutionListener.

Prior to this commit the registration of two DependencyInjection
listeners would cause @PostConstruct methods on tests to be called
twice.

In order to allow the standard DependencyInjectionTestExecutionListener
to be removed a new DefaultTestExecutionListenersPostProcessor interface
has been introduced.

Fixes gh-6874
2016-09-14 22:03:07 -07:00
Andy Wilkinson
21a25ce855 Revert "Fail fast if @WebAppConfiguration and @SpringBootTest are used together"
This reverts commit c54cdd6735.
2016-09-14 15:04:34 +01:00
Andy Wilkinson
c54cdd6735 Fail fast if @WebAppConfiguration and @SpringBootTest are used together
Closes gh-6795
2016-09-14 14:59:32 +01:00
Johnny Lim
caa4c0800f Polish
Closes gh-6872
2016-09-13 09:25:06 +02:00
Phillip Webb
3684c2ec56 Ensure argument matchers work with AOP spies
Update MockitoAopProxyTargetInterceptor to deal with deal with any
existing argument matchers when working with the VerificationMode.

Prior to this commit `@SpyBean` when combined with AOP could not support
argument matchers.

Fixes gh-6871
2016-09-12 14:53:07 -07:00
Phillip Webb
41a36c4d40 Prevent CastCastException when stripping root URI
Update RootUriRequestExpectationManager to only wrap requests when
they cannot be cast to MockClientHttpRequest. This prevents later
ClassCastExceptions from being thrown with @RestClientTests that
define expected body content.

Fixes gh-6845
2016-09-12 12:44:31 -07:00
Johnny Lim
11aa4d0749 Fix ResetMocksTestExecutionListenerTests
Align test implementation with names.

Closes gh-6842
2016-09-08 16:13:59 -07:00
Phillip Webb
41dc53f5dd Polish 2016-09-07 08:34:45 -07:00
Johnny Lim
4b9f6869f0 Polish
Closes gh-6817
2016-09-05 09:08:08 +02:00
Andy Wilkinson
0e00a49dcc Prevent beans created with @MockBean from being post-processed
Post-processing of mocked beans causes a number of problems:

 - The mock may be proxied for asynchronous processing which can cause
   problems when configuring expectations on a mock (gh-6573)
 - The mock may be proxied so that its return values can be cached or
   so that its methods can be transactional. This causes problems with
   verification of the expected calls to a mock (gh-6573, gh-5837)
 - If the mock is created from a class that uses field injection, the
   container will attempt to inject values into its fields. This causes
   problems if the mock is being created to avoid the use of one of
   those dependencies (gh-6663)
 - Proxying a mocked bean can lead to a JDK proxy being created
   (if proxyTargetClass=false) as the mock implements a Mockito
   interface. This can then cause injection failures as the types don’t
   match (gh-6405, gh-6665)

All of these problems can be avoided if a mocked bean is not
post-processed. Avoiding post-processing prevents proxies from being
created and autowiring from being performed. This commit avoids
post-processing by registering mocked beans as singletons as well as
via a bean definition. The latter is still used by the context for type
matching purposes.

Closes gh-6573, gh-6663, gh-6664
2016-09-02 10:23:06 +02:00
Andy Wilkinson
3814e509a3 Polish @deprecated javadoc and link to replacements where available
Closes gh-6765
2016-08-31 14:34:49 +01:00
Phillip Webb
a985a5c861 Update @MockBean to support generics
Update @MockBean and @SpyBean to support field generics. Prior to this
commit the following fields would fail with a "Duplicate mock
definition" exception:

  @MockBean
  private IdentityProvider<PasswordIdentity> passwordIdentityProvider;

  @MockBean
  private IdentityProvider<Oauth2Identity> oauth2IdentityProvider;

Fixes gh-6602
2016-08-29 21:42:44 +01:00
Phillip Webb
565ad79856 Polish 2016-08-29 20:26:30 +01:00
Andy Wilkinson
3c5cf02882 Provide method to create TestRestTemplate with basic auth from existing
Closes gh-6732
2016-08-25 12:07:19 +01:00
Andy Wilkinson
2377d78a40 Update auto-configured TestRestTemplate to use SSL when it’s enabled
Closes gh-6731
2016-08-25 09:47:23 +01:00
Andy Wilkinson
5a1741e2e8 Improve documentation of when TestRestTemplate is auto-configured
Closes gh-6729
2016-08-23 15:48:40 +01:00
Andy Wilkinson
f117b93d49 Polish “Add constructor to TestRestTemplate that takes a RestTemplateBuilder”
Closes gh-6702
2016-08-22 20:51:54 +01:00
Maciej Walkowiak
53d7fd5aab Add constructor to TestRestTemplate that takes a RestTemplateBuilder
Closes gh-6706
See gh-6702
2016-08-22 20:51:54 +01:00
Andy Wilkinson
1752773815 Default JSON loading to UTF-8 and provide methods to configure charset
Closes gh-6597
2016-08-16 15:17:30 +01:00
Andy Wilkinson
f4985abf3c Use factoryBeanObjectType attribute to find factory bean to replace
Previously, MockitoPostProcessor would fail to replace a factory bean
with a mock if the factory bean didn't return a matching type from
getObjectType(). This prevented Spring Data respoitories from being
replaced with a mock as Spring Data's repository factory beans
generally do not know the specific repository type that they will
produce when MockPostProcesser (a bean factory post-processor) is
running.

Spring Data has been updated to add a factoryBeanObjectType attribute
to its factory bean definitions. MockitoPostProcessor has been updated
to look for FactoryBeans with this attribute and to use its value
to determine whether or not the factory bean produces a bean of the
required type and, therefore, should be replaced with a mock.

Closes gh-6541
2016-08-10 10:27:00 +01:00
Spring Buildmaster
334baaeffd Next development version 2016-07-28 19:54:01 +00:00
Johnny Lim
9627d0ed66 Polish
Closes gh-6487
2016-07-27 12:29:33 +01:00
Phillip Webb
753a7e1d33 Document how to to customize the TestRestTemplate
Update the reference documentation and add some additional Javadoc to
provide hints on how to customize the `TestRestTemplate`.

Fixes gh-6465
2016-07-26 22:08:53 -07:00
Phillip Webb
296dc7132b Allow JSON Testers to be @Autowired
Switch `@AutoConfigureJsonTesters` to use regular `@Autowired` injection
for JSON testers. Prior to this commit JSON Tester fields were
initialized directly which caused IDE issues and was also a little
confusing.

Fixes gh-6451
2016-07-26 21:41:37 -07:00
Andy Wilkinson
ec7a9a32b9 Upgrade to AssertJ 2.5.0
Closes gh-6473
2016-07-26 21:19:02 +01:00
Phillip Webb
05ff4ed4e0 Upgrade to Tomcat 8.5.4 & remove tomcat-juli
Upgrade the managed Tomcat dependency to 8.5.4 and remove `tomcat-juli`
since it's now included in `tomcat-embed-core`.

Fixes gh-6192
2016-07-18 17:52:35 -07:00
Johnny Lim
a9f6ae4422 Polish
Closes gh-6374
2016-07-12 08:46:58 +02:00
Phillip Webb
43afc149a1 Consider WebAppConfiguration in @SpringBootTest
Update SpringBootTestContextBootstrapper to consider the
`@WebAppConfiguration` annotation and use sensible resourceBasePath
defaults.

Fixes gh-6371
2016-07-11 16:38:10 -07:00
Marcin Zajaczkowski
ed829d7981 Fix compatibility with Mockito 2.0
Update MockDefinition to only call `Answers.get()` if a direct cast
isn't possible. This provides compatibility with Mockito 2.0 (currently
2.0.47-beta) without breaking support for Mockto 1.x.

Closes gh-6323
2016-07-06 14:28:36 -07:00
Andy Wilkinson
92bb24e365 Avoid synchronizing on this and use an internal monitor instead
Where possible, code that previously synchronized on this (or on the
class in the case of static methods) has been updated to use an
internal monitor object instead. This allows the locking model that's
employed to be an implementation detail rather than part of the
class's API.

Classes that override a synchronized method continue to declare
the overriding method as synchronized. This ensures that locking
is consistent across the superclass and its subclass.

Closes gh-6262
2016-07-01 10:44:23 +01:00
Phillip Webb
be884d4e33 Polish 2016-06-29 10:57:43 -07:00
Stephane Nicoll
669da59b4a Polish 2016-06-29 16:28:41 +02:00
Johnny Lim
5bc9d5b380 Polish
Closes gh-6244
2016-06-29 08:08:53 +02:00
Stephane Nicoll
f54bec835d Move BasicAuthorizationInterceptor
`BasicAuthorizationInterceptor` is now available in the core framework
and this commit uses that instead of the outdated copy in Boot.

Closes gh-6237
2016-06-29 08:07:30 +02:00
Andy Wilkinson
f28e3d54c5 Upgrade to Tomcat 8.5.3
This commit changes the default version of Tomcat to 8.5.3 while
also retaining support for Tomcat 8.0 and 7.0. The main difference
in 8.5 is that the ServerSocketFactory abstraction that allowed the
TrustStore and KeyStore to be configured programatically no longer
exists. This logic has been replaced with the use of a custom URL
protocol (springbootssl) that provides access to the key store and
trust store of an SslStoreProvider. In addition to working with 8.5,
this approach has the advantage of also working with 8.0 and 7.0.

Closes gh-6164
2016-06-20 13:27:47 +01:00
Johnny Lim
a70a8635f9 Polish
Closes gh-6155
2016-06-14 08:35:22 +02:00
Phillip Webb
99c6194e17 Don't use MockitoJUnitRunner
Replace `@RunWith(MockitoJUnitRunner.class)` with direct Mockito
initialization since the running doesn't support parallel test
execution.
2016-06-09 20:55:59 -07:00
Johnny Lim
5de9516255 Fix typos
Closes gh-6114
2016-06-03 07:20:39 -04:00
Phillip Webb
433f5e7930 Configure TestRestTemplate using builder
Update SpringBootTestContextCustomizer to create the TestRestTemplate
using the RestTemplateBuilder whenever possible.

Fixes gh-5509
2016-05-31 18:01:55 -07:00
Phillip Webb
2eafb3d887 Add @RestClientTest support
Add @RestClientTest annotation that can be used when testing REST
clients. Provides auto-configuration for a MockRestServiceServer which
can be used when the bean under test builds a single RestTemplate
via the auto-configured RestTemplateBuilder.

Closes gh-6030
2016-05-31 10:18:07 -07:00
Phillip Webb
b641e63466 Add RestTemplateBuilder support
Add a RestTemplateBuilder that allows RestTemplates to be easily created
and configured.

See gh-5507
2016-05-31 09:50:46 -07:00
Johnny Lim
70adefc87b Polish
Closes gh-6046
2016-05-26 14:58:41 +02:00
Phillip Webb
f0b6d346d7 Filter scoped target proxy beans from Mockito
Update MockitoPostProcessor to filter bean names that match
`ScopedProxyUtils.isScopedTarget` from the candidates list.

Fixes gh-5724
2016-05-16 13:56:13 -07:00
Johnny Lim
5759f685e5 Fix Mockito tests to align with name and comments
Fixup Mockto tests where the test implementation didn't align with the
name of the test or the test Javadoc.

Closes gh-5972
2016-05-16 13:20:01 -07:00
Phillip Webb
2fc86b2d5a Only attempt mock reset on instantiated singletons
Update ResetMocksTestExecutionListener to only attempt a mock reset when
a singleton has actually been created.

Fixes gh-5870
2016-05-16 13:03:04 -07:00
Phillip Webb
bcfa2e6676 Make TestRestTemplate not extend RestTemplate
Update TestRestTemplate so that it no longer directly extends
RestTemplate. Prior to this commit it was possible that TestRestTemplate
could interfere with user defined RestTemplate beans.

TestRestTemplate offers the same methods as RestTemplate so should be
a drop-in replacement. If access is needed to the actual underlying
template the `getRestTemplate()` method should be used.

Fixes gh-5915
2016-05-16 12:35:31 -07:00
Johnny Lim
29898c73d3 Remove superflous if in MockitoPostProcessor
The `if` in registerSpies() is not required as it's covered by the
Assert check.

Closes gh-5889
2016-05-13 20:09:02 -07:00
Johnny Lim
7a62b7d066 Polish
Closes gh-5936
2016-05-13 08:55:28 +02:00
Phillip Webb
cdfbf28099 Allow @MockBean/@SpyBean on Spring AOP proxies
Update Mockito support so that AOP Proxies automatically get additional
`Advice` that allows them to work with Mockito. Prior to this commit a
call to `verify` would fail because exiting AOP advice would confuse
Mockito and an `UnfinishedVerificationException` would be thrown.

The `MockitoAopProxyTargetInterceptor` works by detecting calls to a
mock that have been proceeded by `verify()` and bypassing AOP to
directly call the mock.

The order that `@SpyBean` creation occurs has also been updated to
ensure that that the spy is created before AOP advice is applied.
Without this, the creation of a spy would fail because Mockito copies
'state' to the newly created spied instance. Unfortunately, in the case
of AOP proxies, 'state' includes cglib interceptor fields. This means
that Mockito's own interceptors are clobbered by Spring's AOP
interceptors.

Fixes gh-5837
2016-05-11 20:20:02 -07:00
Phillip Webb
cf6212b955 Polish 2016-05-10 10:22:37 -07:00
Johnny Lim
38dc9ec441 Polish 2016-05-10 14:48:42 +01:00
Andy Wilkinson
0a765e36f1 Protect against stack overflow when searching meta annotations
It is legal for an annotation to be annotated with itself. Previously,
when searching for meta annotations this could lead to a stack overflow.
This was likely to occur when using Kotlin as, like Java, its Target
annotation is annotated with itself. A stack overflow doesn’t occur
with Java’s Target annotation due to some short-circuiting logic for
annotations in java.lang.

This commit updates the logic for finding meta-annotations to
short-circuit when an annotation that has already been seen is
encountered.

Closes gh-5902
2016-05-10 09:39:55 +01:00
Andy Wilkinson
db21bcdff6 Make SpringApplicationConfiguration use SpringApplicationContextLoader
The intention in 1.4 is for the deprecated testing functionality to
behave exactly as it did in 1.3. To help with this, this commit
updates SpringApplicationConfiguration to use
SpringApplicationContextLoader as its loader, just as it did in 1.3.

Closes gh-5882
2016-05-09 12:27:44 +01:00
Dave Syer
bdc71f693c Fix checksyle 'violations' 2016-05-06 13:11:09 +01:00
Dave Syer
be398741e1 Fix binary incompatibility of old TestRestTemplate
The TestRestTemplate is deprecated (so people can still use it)
but unusable because it only has constructors which depend on the
new options enum.
2016-05-06 13:07:39 +01:00
Johnny Lim
7763c2ae4c Polish
Closes gh-5843
2016-05-03 09:33:32 +02:00
Johnny Lim
06143195d0 Make json-path and selenium-api optional
Make json-path and selenium-api optional in spring-boot-test and
spring-boot-test-autoconfigure.

Fixes gh-5828
2016-05-02 17:17:29 -07:00
Johnny Lim
e5715df7e3 Polish
Closes gh-5836
2016-05-02 17:08:34 -07:00
Johnny Lim
0efa0038c3 Polish
Closes gh-5815
2016-04-30 10:24:33 +02:00
Phillip Webb
609cb52cd4 Move to relocated web classes
Refactor code to move from recently deprecated classes.

Closes gh-5822
2016-04-28 12:45:15 -07:00
Phillip Webb
a7cb689f95 Move @LocalServerPort annotation
Move the @LocalServerPort to org.springframework.boot.context.embedded
since it's only really useful when working with embedded servlet
containers.

See gh-5822
2016-04-28 12:45:15 -07:00
Phillip Webb
93382648ab Formatting 2016-04-24 22:54:27 -07:00
Andy Wilkinson
aa19c19753 Merge branch '1.3.x' 2016-04-20 10:58:50 +01:00
Andy Wilkinson
601791c664 Configure test property sources before ConfigFileApplicationListener runs
Previously, SpringBootContextLoader configured the environment with the
test property sources using an ApplicationContextInitializer. This was
because TestPropertySourceUtils did not provide a method to directly
configure the environment using properties files, it had to be done
via an application context. An unwanted side-effect of this was that
the test property sources were not being configured before
ConfigFileApplicationListener examined the environment to determine the
name and locations of the files that it should be loading.

This commit takes advantage of a new method that was added to
TestPropertySourceUtils which allows properties files to be added
directly to the environment without using an application context. This
means that the use of the ApplicationContextInitializer can be removed
and the test property sources can be applied to the environment before
the application context is created.

Closes gh-5728
2016-04-19 13:30:18 +01:00
Stephane Nicoll
786004e297 Fix build 2016-04-16 10:58:28 +02:00
Phillip Webb
cf41512e66 Don't throw checked exceptions from Assert classes
Fixes gh-5709
2016-04-15 22:46:12 -07:00
Andy Wilkinson
35270e939f Update dependency management for Selenium and its HTMLUnit Driver
Closes gh-5705
2016-04-15 17:08:04 +01:00
Johnny Lim
90d897eb9d Polish
Closes gh-5685
2016-04-14 08:03:52 +02:00
Andy Wilkinson
a37ae5d556 Polish test property source changes made in 69b08291
TestPropertySourcesInitializer needs to be ordered with a high
precedence, specifically higher than
ContextIdApplicationContextInitializer, to ensure that any properties
used in setting the context’s id are available in the environment.

Closes gh-4828
2016-04-07 11:34:36 +01:00
Andy Wilkinson
69b0829199 Align precedence of @SpringBootTest properties with @TestPropertySource
This commit updates the precedence of properties configured using
@SpringBootTest to align with @TestPropertySource. Properties configured
using properties on @SpringBootTest are now added to the same property
source as those configured using properties on @TestPropertySource so
the precedence described in the javadoc of @TestPropertySource now
applies in full. Additionally, if both @TestPropertySource properties
and @SpringBootTest properties configure the same property, the value
from @TestPropertySource will win.

Closes gh-4828
2016-04-07 10:41:07 +01:00
Phillip Webb
01c9d72644 Polish 2016-04-06 15:19:58 -07:00
Johnny Lim
a55315b5b5 Polish
Closes gh-5614
2016-04-06 10:25:45 +02:00
Johnny Lim
8864f85b82 Remove System.out.println() 2016-04-04 22:37:37 -07:00
Phillip Webb
b398b3319c Rename @SpringApplicationTest -> @SpringBootTest
Rename @SpringApplicationTest to SpringBootTest and
@SpringApplicationContextLoader to @SpringBootContextLoader.

Fixes gh-5562
2016-04-04 22:36:58 -07:00
Phillip Webb
b0b190b362 Delete @SpringApplicationConfiguration
Remove the @SpringApplicationConfiguration annotation since it offers
little value over @SpringApplicationTest.

See gh-5562
2016-04-04 22:36:58 -07:00
Stephane Nicoll
0a8975bc84 Polish 2016-04-02 08:05:02 +02:00
Phillip Webb
34070e5a8e Add Support for Mockito spies
Add a @SpyBean annotation that can be used to create spies.

Fixes gh-5538
2016-04-01 17:16:40 -07:00
Andy Wilkinson
33f0ea3480 Rework SpringApplicationTest to support web modes
Rework the new testing support so that @SpringApplicationTest can be
used for standard integration tests, web integration tests with a
mock Servlet environment and web integration tests with an embedded
servlet container. This means that it a replacement for 1.3's
@IntegrationTest and @WebIntegrationTest and allows all
SpringApplication testing to be configured using a common annotation.

The old @IntegrationTest and @WebIntegrationTest along with their
supporting classes have been reinstated to their previous form (while
remaining deprecated). This should ensure that they continue to work
in 1.4 exactly as they did in 1.3 giving users a smooth path to
@SpringApplicationTest.

See gh-5477
2016-03-31 21:35:10 -07:00
Phillip Webb
893a6c32f3 Upgrade to checkstyle 6.17
Fixes gh-5547
2016-03-31 13:14:53 -07:00
Johnny Lim
a28dd9d9e6 Polish
Closes gh-5532
2016-03-30 08:43:23 +02:00
Johnny Lim
51bbe5e37a Polish
Closes gh-5508
2016-03-28 11:47:02 +02:00
Johnny Lim
46517cddd8 Fix MockDefinition.toString()
Closes gh-5500
2016-03-27 17:52:03 +02:00