Skip to content

Commit d36f9ce

Browse files
author
Dave Syer
committed
Add tests for switching message sources in tests
See gh-1075
1 parent 8d6f003 commit d36f9ce

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.autoconfigure;
18+
19+
import java.util.Locale;
20+
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.autoconfigure.MessageSourceAutoConfigurationIntegrationTests.Config;
25+
import org.springframework.boot.test.IntegrationTest;
26+
import org.springframework.boot.test.SpringApplicationConfiguration;
27+
import org.springframework.context.ApplicationContext;
28+
import org.springframework.context.annotation.Configuration;
29+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
/**
34+
* Tests for {@link MessageSourceAutoConfiguration}.
35+
*
36+
* @author Dave Syer
37+
*/
38+
@SpringApplicationConfiguration(classes = { Config.class,
39+
MessageSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
40+
@RunWith(SpringJUnit4ClassRunner.class)
41+
@IntegrationTest("spring.messages.basename:test/messages")
42+
public class MessageSourceAutoConfigurationIntegrationTests {
43+
44+
@Autowired
45+
private ApplicationContext context;
46+
47+
@Test
48+
public void testMessageSourceFromPropertySourceAnnotation() throws Exception {
49+
assertEquals("bar",
50+
this.context.getMessage("foo", null, "Foo message", Locale.UK));
51+
}
52+
53+
@Configuration
54+
protected static class Config {
55+
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.autoconfigure;
18+
19+
import java.util.Locale;
20+
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.autoconfigure.MessageSourceAutoConfigurationProfileTests.Config;
25+
import org.springframework.boot.test.SpringApplicationConfiguration;
26+
import org.springframework.context.ApplicationContext;
27+
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.test.context.ActiveProfiles;
29+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30+
31+
import static org.junit.Assert.assertEquals;
32+
33+
/**
34+
* Tests for {@link MessageSourceAutoConfiguration}.
35+
*
36+
* @author Dave Syer
37+
*/
38+
@SpringApplicationConfiguration(classes = { Config.class,
39+
MessageSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
40+
@RunWith(SpringJUnit4ClassRunner.class)
41+
@ActiveProfiles("switch-messages")
42+
public class MessageSourceAutoConfigurationProfileTests {
43+
44+
@Autowired
45+
private ApplicationContext context;
46+
47+
@Test
48+
public void testMessageSourceFromPropertySourceAnnotation() throws Exception {
49+
assertEquals("bar",
50+
this.context.getMessage("foo", null, "Foo message", Locale.UK));
51+
}
52+
53+
@Configuration
54+
protected static class Config {
55+
56+
}
57+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.messages.basename:test/messages

0 commit comments

Comments
 (0)