Skip to content

Commit 2b185fc

Browse files
Dave SyerPhillip Webb
authored andcommitted
Add tests for groovy config in @SpringApplicationConfiguration
1 parent ed3fc06 commit 2b185fc

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed

spring-boot/src/test/java/org/springframework/boot/test/ConfigFileApplicationContextInitializerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ConfigFileApplicationContextInitializerTests {
4040
private Environment environment;
4141

4242
@Test
43-
public void test() {
43+
public void initializerPopulatesEnvironment() {
4444
assertThat(this.environment.getProperty("foo"), equalTo("bucket"));
4545
}
4646

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2012-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.test;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
23+
24+
import static org.junit.Assert.assertNotNull;
25+
26+
/**
27+
* Tests for {@link SpringApplicationContextLoader} (detectDefaultConfigurationClasses).
28+
*
29+
* @author Dave Syer
30+
*/
31+
@RunWith(SpringJUnit4ClassRunner.class)
32+
@SpringApplicationConfiguration(locations = "classpath:test.groovy")
33+
public class SpringApplicationConfigurationGroovyConfigurationTests {
34+
35+
@Autowired
36+
private String foo;
37+
38+
@Test
39+
public void groovyConfigLoaded() {
40+
assertNotNull(this.foo);
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2012-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.test;
18+
19+
import org.junit.Ignore;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.SpringApplicationConfigurationMixedConfigurationTests.Config;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26+
27+
import static org.junit.Assert.assertNotNull;
28+
29+
/**
30+
* Tests for {@link SpringApplicationContextLoader}.
31+
*
32+
* @author Dave Syer
33+
*/
34+
@RunWith(SpringJUnit4ClassRunner.class)
35+
@SpringApplicationConfiguration(classes = Config.class, locations = "classpath:test.groovy")
36+
@Ignore("classes and locations together are not supported in Spring Test (for legacy reasons)")
37+
public class SpringApplicationConfigurationMixedConfigurationTests {
38+
39+
@Autowired
40+
private String foo;
41+
42+
@Autowired
43+
private Config config;
44+
45+
@Test
46+
public void mixedConfigClasses() {
47+
assertNotNull(this.foo);
48+
assertNotNull(this.config);
49+
}
50+
51+
@Configuration
52+
protected static class Config {
53+
54+
}
55+
56+
}

spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public class SpringApplicationIntegrationTestTests {
4646

4747
@Test
48-
public void nestedConfigClasses() {
48+
public void runAndTestHttpEndpoint() {
4949
String body = new RestTemplate().getForObject("http://localhost:8080/",
5050
String.class);
5151
assertEquals("Hello World", body);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
beans {
2+
foo String, "World"
3+
}

0 commit comments

Comments
 (0)