Browse Source
Prior to Java 8 it never really made much sense to author integration tests using interfaces. Consequently, the Spring TestContext Framework has never supported finding test-related annotations on interfaces in its search algorithms. However, Java 8's support for interface default methods introduces new testing use cases for which it makes sense to declare test configuration (e.g., @ContextConfiguration, etc.) on an interface containing default methods instead of on an abstract base class. This commit ensures that all non-repeatable, class-level test annotations in the Spring TestContext Framework can now be declared on test interfaces. The only test annotations that cannot be declared on interfaces are therefore @Sql and @SqlGroup. Issue: SPR-14184pull/1050/head
34 changed files with 973 additions and 84 deletions
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.Profile; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
import org.springframework.tests.sample.beans.Employee; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
public class ActiveProfilesInterfaceTests implements ActiveProfilesTestInterface { |
||||
|
||||
@Autowired |
||||
Employee employee; |
||||
|
||||
|
||||
@Test |
||||
public void profileFromTestInterface() { |
||||
assertNotNull(employee); |
||||
assertEquals("dev", employee.getName()); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
|
||||
@Bean |
||||
@Profile("dev") |
||||
Employee employee1() { |
||||
return new Employee("dev"); |
||||
} |
||||
|
||||
@Bean |
||||
@Profile("prod") |
||||
Employee employee2() { |
||||
return new Employee("prod"); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.springframework.test.context.ActiveProfiles; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@ActiveProfiles("dev") |
||||
interface ActiveProfilesTestInterface { |
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
public class BootstrapWithInterfaceTests implements BootstrapWithTestInterface { |
||||
|
||||
@Autowired |
||||
String foo; |
||||
|
||||
|
||||
@Test |
||||
public void injectedBean() { |
||||
assertEquals("foo", foo); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.test.context.BootstrapWith; |
||||
import org.springframework.test.context.ContextCustomizer; |
||||
import org.springframework.test.context.ContextCustomizerFactory; |
||||
import org.springframework.test.context.configuration.interfaces.BootstrapWithTestInterface.CustomTestContextBootstrapper; |
||||
import org.springframework.test.context.support.DefaultTestContextBootstrapper; |
||||
|
||||
import static java.util.Collections.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @author Phillip Webb |
||||
* @since 4.3 |
||||
*/ |
||||
@BootstrapWith(CustomTestContextBootstrapper.class) |
||||
interface BootstrapWithTestInterface { |
||||
|
||||
static class CustomTestContextBootstrapper extends DefaultTestContextBootstrapper { |
||||
|
||||
@Override |
||||
protected List<ContextCustomizerFactory> getContextCustomizerFactories() { |
||||
return singletonList( |
||||
(ContextCustomizerFactory) (testClass, configAttributes) -> (ContextCustomizer) (context, |
||||
mergedConfig) -> context.getBeanFactory().registerSingleton("foo", "foo")); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
import org.springframework.tests.sample.beans.Employee; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
public class ContextConfigurationInterfaceTests implements ContextConfigurationTestInterface { |
||||
|
||||
@Autowired |
||||
Employee employee; |
||||
|
||||
|
||||
@Test |
||||
public void profileFromTestInterface() { |
||||
assertNotNull(employee); |
||||
assertEquals("Dilbert", employee.getName()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.configuration.interfaces.ContextConfigurationTestInterface.Config; |
||||
import org.springframework.tests.sample.beans.Employee; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@ContextConfiguration(classes = Config.class) |
||||
interface ContextConfigurationTestInterface { |
||||
|
||||
static class Config { |
||||
|
||||
@Bean |
||||
Employee employee() { |
||||
return new Employee("Dilbert"); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
public class ContextHierarchyInterfaceTests implements ContextHierarchyTestInterface { |
||||
|
||||
@Autowired |
||||
String foo; |
||||
|
||||
@Autowired |
||||
String bar; |
||||
|
||||
@Autowired |
||||
String baz; |
||||
|
||||
@Autowired |
||||
ApplicationContext context; |
||||
|
||||
|
||||
@Test |
||||
public void loadContextHierarchy() { |
||||
assertNotNull("child ApplicationContext", context); |
||||
assertNotNull("parent ApplicationContext", context.getParent()); |
||||
assertNull("grandparent ApplicationContext", context.getParent().getParent()); |
||||
assertEquals("foo", foo); |
||||
assertEquals("bar", bar); |
||||
assertEquals("baz-child", baz); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.ContextHierarchy; |
||||
import org.springframework.test.context.hierarchies.standard.SingleTestClassWithTwoLevelContextHierarchyTests; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@ContextHierarchy({ |
||||
@ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyTests.ParentConfig.class), |
||||
@ContextConfiguration(classes = SingleTestClassWithTwoLevelContextHierarchyTests.ChildConfig.class) }) |
||||
interface ContextHierarchyTestInterface { |
||||
} |
||||
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger; |
||||
|
||||
import org.junit.AfterClass; |
||||
import org.junit.BeforeClass; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.junit.runners.JUnit4; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
||||
import static org.junit.Assert.*; |
||||
import static org.springframework.test.context.cache.ContextCacheTestUtils.*; |
||||
import static org.springframework.test.context.junit4.JUnitTestingUtils.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@RunWith(JUnit4.class) |
||||
public class DirtiesContextInterfaceTests { |
||||
|
||||
private static final AtomicInteger cacheHits = new AtomicInteger(0); |
||||
private static final AtomicInteger cacheMisses = new AtomicInteger(0); |
||||
|
||||
|
||||
@BeforeClass |
||||
public static void verifyInitialCacheState() { |
||||
resetContextCache(); |
||||
// Reset static counters in case tests are run multiple times in a test suite --
|
||||
// for example, via JUnit's @Suite.
|
||||
cacheHits.set(0); |
||||
cacheMisses.set(0); |
||||
assertContextCacheStatistics("BeforeClass", 0, cacheHits.get(), cacheMisses.get()); |
||||
} |
||||
|
||||
@AfterClass |
||||
public static void verifyFinalCacheState() { |
||||
assertContextCacheStatistics("AfterClass", 0, cacheHits.get(), cacheMisses.get()); |
||||
} |
||||
|
||||
@Test |
||||
public void verifyDirtiesContextBehavior() throws Exception { |
||||
runTestClassAndAssertStats(ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase.class, 1); |
||||
assertContextCacheStatistics("after class-level @DirtiesContext with clean test method and default class mode", |
||||
0, cacheHits.get(), cacheMisses.incrementAndGet()); |
||||
} |
||||
|
||||
private void runTestClassAndAssertStats(Class<?> testClass, int expectedTestCount) throws Exception { |
||||
runTestsAndAssertCounters(testClass, expectedTestCount, 0, expectedTestCount, 0, 0); |
||||
} |
||||
|
||||
|
||||
@RunWith(SpringRunner.class) |
||||
public static class ClassLevelDirtiesContextWithCleanMethodsAndDefaultModeTestCase |
||||
implements DirtiesContextTestInterface { |
||||
|
||||
@Autowired |
||||
ApplicationContext applicationContext; |
||||
|
||||
|
||||
@Test |
||||
public void verifyContextWasAutowired() { |
||||
assertNotNull("The application context should have been autowired.", this.applicationContext); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
/* no beans */ |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.springframework.test.annotation.DirtiesContext; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@DirtiesContext |
||||
interface DirtiesContextTestInterface { |
||||
} |
||||
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.test.context.jdbc.Sql; |
||||
import org.springframework.test.context.jdbc.SqlConfig; |
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
public class SqlConfigInterfaceTests extends AbstractTransactionalJUnit4SpringContextTests |
||||
implements SqlConfigTestInterface { |
||||
|
||||
@Test |
||||
@Sql(scripts = "/org/springframework/test/context/jdbc/schema.sql", //
|
||||
config = @SqlConfig(separator = ";")) |
||||
@Sql("/org/springframework/test/context/jdbc/data-add-users-with-custom-script-syntax.sql") |
||||
public void methodLevelScripts() { |
||||
assertNumUsers(3); |
||||
} |
||||
|
||||
protected void assertNumUsers(int expected) { |
||||
assertEquals("Number of rows in the 'user' table.", expected, countRowsInTable("user")); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.springframework.test.annotation.DirtiesContext; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.jdbc.EmptyDatabaseConfig; |
||||
import org.springframework.test.context.jdbc.SqlConfig; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@ContextConfiguration(classes = EmptyDatabaseConfig.class) |
||||
@DirtiesContext |
||||
@SqlConfig(commentPrefix = "`", blockCommentStartDelimiter = "#$", blockCommentEndDelimiter = "$#", separator = "@@") |
||||
interface SqlConfigTestInterface { |
||||
} |
||||
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
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.env.Environment; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
||||
import static org.hamcrest.CoreMatchers.*; |
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
public class TestPropertySourceInterfaceTests implements TestPropertySourceTestInterface { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
|
||||
@Test |
||||
public void propertiesAreAvailableInEnvironment() { |
||||
assertThat(property("foo"), is("bar")); |
||||
assertThat(property("enigma"), is("42")); |
||||
} |
||||
|
||||
private String property(String key) { |
||||
return env.getProperty(key); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
/* no user beans required for these tests */ |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.springframework.test.context.TestPropertySource; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@TestPropertySource(properties = { "foo = bar", "enigma: 42" }) |
||||
interface TestPropertySourceTestInterface { |
||||
} |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
import org.springframework.web.context.WebApplicationContext; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@RunWith(SpringRunner.class) |
||||
public class WebAppConfigurationInterfaceTests implements WebAppConfigurationTestInterface { |
||||
|
||||
@Autowired |
||||
WebApplicationContext wac; |
||||
|
||||
|
||||
@Test |
||||
public void wacLoaded() { |
||||
assertNotNull(wac); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* |
||||
* 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.configuration.interfaces; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.configuration.interfaces.WebAppConfigurationTestInterface.Config; |
||||
import org.springframework.test.context.web.WebAppConfiguration; |
||||
|
||||
/** |
||||
* @author Sam Brannen |
||||
* @since 4.3 |
||||
*/ |
||||
@WebAppConfiguration |
||||
@ContextConfiguration(classes = Config.class) |
||||
interface WebAppConfigurationTestInterface { |
||||
|
||||
@Configuration |
||||
static class Config { |
||||
/* no user beans required for these tests */ |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue