本文整理匯總了Java中org.springframework.context.support.ClassPathXmlApplicationContext.getBeansOfType方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassPathXmlApplicationContext.getBeansOfType方法的具體用法?Java ClassPathXmlApplicationContext.getBeansOfType怎麽用?Java ClassPathXmlApplicationContext.getBeansOfType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.context.support.ClassPathXmlApplicationContext
的用法示例。
在下文中一共展示了ClassPathXmlApplicationContext.getBeansOfType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testPostProcessAfterInitialization
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void testPostProcessAfterInitialization() throws IOException, NoSuchMethodException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
TestSteps steps = context.getBean(TestSteps.class);
Class<?> wrapped = AopUtils.getTargetClass(steps);
Method method = wrapped.getMethod("anotherStep", String.class);
Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
Collection<StepImplementation> givens = givenBeanIndex.values();
List<StepImplementation> matches = Lists.newArrayList();
for (StepImplementation given : givens) {
Method givenMethod = given.getMethod();
if (givenMethod.equals(method)) {
matches.add(given);
}
}
int count = matches.size();
assertEquals(count, 1, "wrong number of GivenStep objects registered for TestSteps.anotherStep()");
StepImplementation match = matches.get(0);
Pattern pattern = match.getPattern();
Matcher matcher = pattern.matcher("another \"(.+)\" here");
assertTrue(matcher.find(), "expected Pattern to match Gherkin regular expression");
assertEquals(matcher.groupCount(), 1, "wrong number of parameters captured for TestSteps.anotherStep()");
}
示例2: testMultipleGivenRegex
import org.springframework.context.support.ClassPathXmlApplicationContext; //導入方法依賴的package包/類
@Test
public void testMultipleGivenRegex() throws NoSuchMethodException {
MultipleGivenBean source = new MultipleGivenBean();
ClassPathXmlApplicationContext context = getContext(source);
process(context, source);
MultipleGivenBean steps = context.getBean(MultipleGivenBean.class);
Class<?> wrapped = AopUtils.getTargetClass(steps);
Method method = wrapped.getMethod("doSomething");
Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
Collection<StepImplementation> givens = givenBeanIndex.values();
Set<String> matches = Sets.newHashSetWithExpectedSize(2);
for (StepImplementation given : givens) {
Method givenMethod = given.getMethod();
if (givenMethod.equals(method)) {
Pattern pattern = given.getPattern();
String regex = pattern.pattern();
matches.add(regex);
}
}
int count = matches.size();
assertEquals(count, 2, "wrong number of GivenStep objects registered for MultipleGivenBean.getMartinis()");
Set<String> expected = Sets.newHashSet(
"this is regular expression one", "this is regular expression two");
assertEquals(matches, expected, "Steps contain wrong regex Pattern objects");
}