Skip to content

Commit ece727b

Browse files
jhoellerunknown
authored andcommitted
Introduced NoUniqueBeanDefinitionException as a dedicated subclass of NoSuchBeanDefinitionException
Issue: SPR-10194
1 parent 0efdd3d commit ece727b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,8 +17,10 @@
1717
package org.springframework.context.annotation;
1818

1919
import java.util.Map;
20+
import java.util.regex.Pattern;
2021

2122
import org.junit.Test;
23+
2224
import org.springframework.beans.factory.FactoryBean;
2325
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2426
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,7 +29,7 @@
2729
import org.springframework.context.annotation6.ConfigForScanning;
2830
import org.springframework.context.annotation6.Jsr330NamedForScanning;
2931

30-
import static java.lang.String.*;
32+
import static java.lang.String.format;
3133
import static org.hamcrest.Matchers.*;
3234
import static org.junit.Assert.*;
3335
import static org.springframework.util.StringUtils.*;
@@ -120,13 +122,14 @@ public void getBeanByTypeRaisesNoSuchBeanDefinitionException() {
120122
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
121123

122124
// attempt to retrieve a bean that does not exist
123-
Class<?> targetType = java.util.regex.Pattern.class;
125+
Class<?> targetType = Pattern.class;
124126
try {
125127
Object bean = context.getBean(targetType);
126128
fail("should have thrown NoSuchBeanDefinitionException, instead got: " + bean);
127-
} catch (NoSuchBeanDefinitionException ex) {
129+
}
130+
catch (NoSuchBeanDefinitionException ex) {
128131
assertThat(ex.getMessage(), containsString(
129-
format("No unique bean of type [%s] is defined", targetType.getName())));
132+
format("No qualifying bean of type [%s] is defined", targetType.getName())));
130133
}
131134
}
132135

@@ -137,10 +140,11 @@ public void getBeanByTypeAmbiguityRaisesException() {
137140

138141
try {
139142
context.getBean(TestBean.class);
140-
} catch (RuntimeException ex) {
143+
}
144+
catch (NoSuchBeanDefinitionException ex) {
141145
assertThat(ex.getMessage(),
142146
allOf(
143-
containsString("No unique bean of type [" + TestBean.class.getName() + "] is defined"),
147+
containsString("No qualifying bean of type [" + TestBean.class.getName() + "] is defined"),
144148
containsString("tb1"),
145149
containsString("tb2")
146150
)

0 commit comments

Comments
 (0)