Skip to content

Commit 772a74a

Browse files
committed
SPR-5682: fixing test breakage on CI server due to strange non-determinism in the order of bean names being returned in the key set of the map of beans matching the required type.
1 parent 8c5f78c commit 772a74a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

org.springframework.context/src/test/java/org/springframework/context/annotation/ConfigurationClassApplicationContextTests.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.springframework.context.annotation;
1818

1919
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.*;
2123
import static org.junit.Assert.assertNotNull;
2224
import static org.junit.Assert.assertThat;
2325
import static org.junit.Assert.fail;
@@ -127,18 +129,23 @@ public void getBeanByTypeRaisesNoSuchBeanDefinitionException() {
127129
}
128130
}
129131

132+
@SuppressWarnings("unchecked")
130133
@Test
131134
public void getBeanByTypeAmbiguityRaisesException() {
132135
ConfigurationClassApplicationContext context = new ConfigurationClassApplicationContext(TwoTestBeanConfig.class);
133136

134137
try {
135138
context.getBean(TestBean.class);
136139
} 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+
);
142149
}
143150
}
144151

0 commit comments

Comments
 (0)