|
17 | 17 | package org.springframework.context.annotation;
|
18 | 18 |
|
19 | 19 | import static java.lang.String.format;
|
20 |
| -import static org.hamcrest.CoreMatchers.equalTo; |
| 20 | + |
| 21 | +import static org.hamcrest.CoreMatchers.*; |
| 22 | +import static org.junit.matchers.JUnitMatchers.*; |
21 | 23 | import static org.junit.Assert.assertNotNull;
|
22 | 24 | import static org.junit.Assert.assertThat;
|
23 | 25 | import static org.junit.Assert.fail;
|
@@ -127,18 +129,23 @@ public void getBeanByTypeRaisesNoSuchBeanDefinitionException() {
|
127 | 129 | }
|
128 | 130 | }
|
129 | 131 |
|
| 132 | + @SuppressWarnings("unchecked") |
130 | 133 | @Test
|
131 | 134 | public void getBeanByTypeAmbiguityRaisesException() {
|
132 | 135 | ConfigurationClassApplicationContext context = new ConfigurationClassApplicationContext(TwoTestBeanConfig.class);
|
133 | 136 |
|
134 | 137 | try {
|
135 | 138 | context.getBean(TestBean.class);
|
136 | 139 | } catch (RuntimeException ex) {
|
137 |
| - assertThat(ex.getMessage(), equalTo( |
138 |
| - "No unique bean of type [" + TestBean.class.getName() + "] is defined: " + |
139 |
| - "2 matching bean definitions found (tb1,tb2). Consider qualifying with " + |
140 |
| - "getBean(Class<T> beanType, String beanName) or declaring one bean definition as " + |
141 |
| - "@" + Primary.class.getSimpleName())); |
| 140 | + assertThat(ex.getMessage(), |
| 141 | + allOf( |
| 142 | + containsString("No unique bean of type [" + TestBean.class.getName() + "] is defined"), |
| 143 | + containsString("2 matching bean definitions found"), |
| 144 | + containsString("tb1"), |
| 145 | + containsString("tb2"), |
| 146 | + containsString("Consider qualifying with") |
| 147 | + ) |
| 148 | + ); |
142 | 149 | }
|
143 | 150 | }
|
144 | 151 |
|
|
0 commit comments