From 8e6e6c22af875bbcd2a0adf6d7e661944392771d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 28 Apr 2014 21:31:38 +0200 Subject: [PATCH] Test for base package specified as config location Issue: SPR-11647 --- ...ationConfigWebApplicationContextTests.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java b/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java index e12d6b6e3d9..93e647e8231 100644 --- a/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.web.context.support; import org.junit.Test; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.context.annotation.AnnotationBeanNameGenerator; @@ -24,18 +25,17 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.hamcrest.CoreMatchers.*; - import static org.junit.Assert.*; /** * @author Chris Beams + * @author Juergen Hoeller */ public class AnnotationConfigWebApplicationContextTests { @Test public void registerSingleClass() { - AnnotationConfigWebApplicationContext ctx = - new AnnotationConfigWebApplicationContext(); + AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(Config.class); ctx.refresh(); @@ -45,8 +45,7 @@ public class AnnotationConfigWebApplicationContextTests { @Test public void configLocationWithSingleClass() { - AnnotationConfigWebApplicationContext ctx = - new AnnotationConfigWebApplicationContext(); + AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setConfigLocation(Config.class.getName()); ctx.refresh(); @@ -54,10 +53,19 @@ public class AnnotationConfigWebApplicationContextTests { assertNotNull(bean); } + @Test + public void configLocationWithBasePackage() { + AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); + ctx.setConfigLocation("org.springframework.web.context.support"); + ctx.refresh(); + + TestBean bean = ctx.getBean(TestBean.class); + assertNotNull(bean); + } + @Test public void withBeanNameGenerator() { - AnnotationConfigWebApplicationContext ctx = - new AnnotationConfigWebApplicationContext(); + AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.setBeanNameGenerator(new AnnotationBeanNameGenerator() { @Override public String generateBeanName(BeanDefinition definition, @@ -73,14 +81,15 @@ public class AnnotationConfigWebApplicationContextTests { @Configuration("myConfig") static class Config { + @Bean public TestBean myTestBean() { return new TestBean(); } } - static class NotConfigurationAnnotated { } - static class TestBean { } + static class TestBean { + } }