Polishing
This commit is contained in:
@@ -27,15 +27,17 @@ import org.springframework.test.context.support.DefaultTestContextBootstrapper;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.web.WebTestContextBootstrapper;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.context.BootstrapUtils.*;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link BootstrapUtils}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Phillip Webb
|
||||
* @since 4.2
|
||||
*/
|
||||
public class BootstrapUtilsTests {
|
||||
@@ -43,7 +45,7 @@ public class BootstrapUtilsTests {
|
||||
private final CacheAwareContextLoaderDelegate delegate = mock(CacheAwareContextLoaderDelegate.class);
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void resolveTestContextBootstrapperForNonAnnotatedClass() {
|
||||
@@ -51,8 +53,8 @@ public class BootstrapUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveTestContextBootstrapperForWithWebAppConfigurationAnnotatedClass() throws Exception {
|
||||
assertBootstrapper(WithWebAppConfiguration.class, WebTestContextBootstrapper.class);
|
||||
public void resolveTestContextBootstrapperForWebAppConfigurationAnnotatedClass() {
|
||||
assertBootstrapper(WebAppConfigurationAnnotatedClass.class, WebTestContextBootstrapper.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,6 +134,6 @@ public class BootstrapUtilsTests {
|
||||
static class DoubleMetaAnnotatedBootstrapWithAnnotationClass {}
|
||||
|
||||
@WebAppConfiguration
|
||||
static class WithWebAppConfiguration {}
|
||||
static class WebAppConfigurationAnnotatedClass {}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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
|
||||
*
|
||||
* http://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.test.context.web;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.BootstrapWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfigurationBootstrapWithTests.CustomWebTestContextBootstrapper;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* JUnit-based integration tests that verify support for loading a
|
||||
* {@link WebApplicationContext} with a custom {@link WebTestContextBootstrapper}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Phillip Webb
|
||||
* @since 4.3
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@WebAppConfiguration
|
||||
@BootstrapWith(CustomWebTestContextBootstrapper.class)
|
||||
public class WebAppConfigurationBootstrapWithTests {
|
||||
|
||||
@Autowired
|
||||
WebApplicationContext wac;
|
||||
|
||||
|
||||
@Test
|
||||
public void webApplicationContextIsLoaded() {
|
||||
// from: src/test/webapp/resources/Spring.js
|
||||
Resource resource = wac.getResource("/resources/Spring.js");
|
||||
assertNotNull(resource);
|
||||
assertTrue(resource.exists());
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom {@link WebTestContextBootstrapper} that requires {@code @WebAppConfiguration}
|
||||
* but hard codes the resource base path.
|
||||
*/
|
||||
static class CustomWebTestContextBootstrapper extends WebTestContextBootstrapper {
|
||||
|
||||
@Override
|
||||
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
|
||||
return new WebMergedContextConfiguration(mergedConfig, "src/test/webapp");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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
|
||||
*
|
||||
* http://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.test.context.web;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.BootstrapWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebbAppConfigurationBootstrapWithTests.TestWebTestContextBootstrapper;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* JUnit-based integration tests that verify support for loading a
|
||||
* {@link WebApplicationContext} with a custom {@code @BootstrapWith}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 4.3
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@WebAppConfiguration
|
||||
@BootstrapWith(TestWebTestContextBootstrapper.class)
|
||||
public class WebbAppConfigurationBootstrapWithTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
|
||||
@Test
|
||||
public void testApplicationContextIsWebApplicationContext() throws Exception {
|
||||
assertTrue(this.context instanceof WebApplicationContext);
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class TestWebTestContextBootstrapper extends WebTestContextBootstrapper {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user