當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。