本文整理汇总了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");
}