|
26 | 26 | import org.junit.Rule;
|
27 | 27 | import org.junit.Test;
|
28 | 28 | import org.junit.rules.ExpectedException;
|
| 29 | +import org.springframework.beans.DirectFieldAccessor; |
29 | 30 | import org.springframework.boot.SpringApplication;
|
30 | 31 | import org.springframework.boot.builder.SpringApplicationBuilder;
|
31 | 32 | import org.springframework.context.annotation.Configuration;
|
32 | 33 | import org.springframework.mock.web.MockServletContext;
|
33 | 34 | import org.springframework.web.context.WebApplicationContext;
|
34 | 35 |
|
35 | 36 | import static org.hamcrest.Matchers.equalTo;
|
| 37 | +import static org.hamcrest.Matchers.is; |
36 | 38 | import static org.junit.Assert.assertThat;
|
37 | 39 |
|
38 | 40 | /**
|
39 | 41 | * Tests for {@link SpringBootServletInitializerTests}.
|
40 | 42 | *
|
41 | 43 | * @author Phillip Webb
|
| 44 | + * @author Andy Wilkinson |
42 | 45 | */
|
43 | 46 | public class SpringBootServletInitializerTests {
|
44 | 47 |
|
@@ -72,6 +75,17 @@ public void withConfiguredSource() throws Exception {
|
72 | 75 | equalToSet(Config.class, ErrorPageFilter.class));
|
73 | 76 | }
|
74 | 77 |
|
| 78 | + @SuppressWarnings("rawtypes") |
| 79 | + @Test |
| 80 | + public void mainClassHasSensibleDefault() throws Exception { |
| 81 | + new WithConfigurationAnnotation() |
| 82 | + .createRootApplicationContext(this.servletContext); |
| 83 | + Class mainApplicationClass = (Class<?>) new DirectFieldAccessor(this.application) |
| 84 | + .getPropertyValue("mainApplicationClass"); |
| 85 | + assertThat(mainApplicationClass, |
| 86 | + is(equalTo((Class) WithConfigurationAnnotation.class))); |
| 87 | + } |
| 88 | + |
75 | 89 | private Matcher<? super Set<Object>> equalToSet(Object... items) {
|
76 | 90 | Set<Object> set = new LinkedHashSet<Object>();
|
77 | 91 | Collections.addAll(set, items);
|
|
0 commit comments