Commit Graph

128 Commits (500a3df6e941e43a98850617bae23de29179216b)

Author SHA1 Message Date
Stephane Nicoll eddb10e4c9 Merge branch '1.4.x' into 1.5.x 8 years ago
Stephane Nicoll 4603d8259a Make MockitoTestExecutionListener public
Closes gh-7016
8 years ago
Andy Wilkinson 3ea09d2e04 Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 02e89acd1e Add managed version for kotlin-runtime to spring-boot-parent
See gh-7101
8 years ago
Andy Wilkinson f942fe4947 Merge branch '1.4.x' into 1.5.x 8 years ago
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
8 years ago
Phillip Webb d3e06c4627 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb db3f488d5a Polish 8 years ago
Phillip Webb f2b0fa284e Merge branch '1.4.x' into 1.5.x 8 years ago
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
8 years ago
Phillip Webb 3326841a97 Formatting 8 years ago
Phillip Webb f59cc25e2b Fix eclipse warnings 8 years ago
Stephane Nicoll e643fc5bd1 Merge branch '1.4.x' into 1.5.x 8 years ago
Johnny Lim 503d735fdd Polish
Closes gh-7081
8 years ago
Stephane Nicoll cdd59707fc Merge branch '1.4.x' into 1.5.x 8 years ago
Johnny Lim 30a677646f Polish
Closes gh-7030
8 years ago
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
8 years ago
Stephane Nicoll 6bd670edbc Initiate 1.4.x branch 8 years ago
Spring Buildmaster 7e9ed5e1a7 Next Development Version 8 years ago
Stephane Nicoll 111743275f Polish 8 years ago
Johnny Lim a994b11a73 Polish 8 years ago
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
8 years ago
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
8 years ago
Phillip Webb 04448d6bd9 Polish 8 years ago
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
8 years ago
Phillip Webb 25c4e261e9 Fix failing tests
See gh-6897
8 years ago
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
8 years ago
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
8 years ago
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
8 years ago
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
8 years ago
Andy Wilkinson 21a25ce855 Revert "Fail fast if @WebAppConfiguration and @SpringBootTest are used together"
This reverts commit c54cdd6735.
8 years ago
Andy Wilkinson c54cdd6735 Fail fast if @WebAppConfiguration and @SpringBootTest are used together
Closes gh-6795
8 years ago
Johnny Lim caa4c0800f Polish
Closes gh-6872
8 years ago
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
8 years ago
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
8 years ago
Johnny Lim 11aa4d0749 Fix ResetMocksTestExecutionListenerTests
Align test implementation with names.

Closes gh-6842
8 years ago
Phillip Webb 41dc53f5dd Polish 8 years ago
Johnny Lim 4b9f6869f0 Polish
Closes gh-6817
8 years ago
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
8 years ago
Andy Wilkinson 3814e509a3 Polish @deprecated javadoc and link to replacements where available
Closes gh-6765
8 years ago
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
8 years ago
Phillip Webb 565ad79856 Polish 8 years ago
Andy Wilkinson 3c5cf02882 Provide method to create TestRestTemplate with basic auth from existing
Closes gh-6732
8 years ago
Andy Wilkinson 2377d78a40 Update auto-configured TestRestTemplate to use SSL when it’s enabled
Closes gh-6731
8 years ago
Andy Wilkinson 5a1741e2e8 Improve documentation of when TestRestTemplate is auto-configured
Closes gh-6729
8 years ago
Andy Wilkinson f117b93d49 Polish “Add constructor to TestRestTemplate that takes a RestTemplateBuilder”
Closes gh-6702
8 years ago
Maciej Walkowiak 53d7fd5aab Add constructor to TestRestTemplate that takes a RestTemplateBuilder
Closes gh-6706
See gh-6702
8 years ago
Andy Wilkinson 1752773815 Default JSON loading to UTF-8 and provide methods to configure charset
Closes gh-6597
8 years ago
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
8 years ago
Spring Buildmaster 334baaeffd Next development version 8 years ago