当前位置: 首页>>代码示例>>Java>>正文


Java ClassPathXmlApplicationContext.getBeansOfType方法代码示例

本文整理汇总了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()");
}
 
开发者ID:qas-guru,项目名称:martini-core,代码行数:29,代码来源:StepsAnnotationProcessorTest.java

示例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");
}
 
开发者ID:qas-guru,项目名称:martini-core,代码行数:31,代码来源:StepsAnnotationProcessorTest.java


注:本文中的org.springframework.context.support.ClassPathXmlApplicationContext.getBeansOfType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。