Commit Graph

115 Commits (98f14f2ee98595a441d900523dce4c127e8b8559)

Author SHA1 Message Date
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
Johnny Lim 503d735fdd Polish
Closes gh-7081
8 years ago
Johnny Lim 30a677646f Polish
Closes gh-7030
8 years ago
Stephane Nicoll 6bd670edbc Initiate 1.4.x branch 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
Johnny Lim 9627d0ed66 Polish
Closes gh-6487
8 years ago
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
8 years ago
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
8 years ago
Andy Wilkinson ec7a9a32b9 Upgrade to AssertJ 2.5.0
Closes gh-6473
8 years ago
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
8 years ago
Johnny Lim a9f6ae4422 Polish
Closes gh-6374
8 years ago
Phillip Webb 43afc149a1 Consider WebAppConfiguration in @SpringBootTest
Update SpringBootTestContextBootstrapper to consider the
`@WebAppConfiguration` annotation and use sensible resourceBasePath
defaults.

Fixes gh-6371
8 years ago
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
8 years ago
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
9 years ago
Phillip Webb be884d4e33 Polish 9 years ago
Stephane Nicoll 669da59b4a Polish 9 years ago
Johnny Lim 5bc9d5b380 Polish
Closes gh-6244
9 years ago
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
9 years ago