@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -16,14 +16,15 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test case cornering the bug initially raised with SPR-8762, in which a
|
||||
* NullPointerException would be raised if a FactoryBean-returning @Bean method also
|
||||
@@ -33,47 +34,55 @@ import org.springframework.context.ApplicationContext;
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, Bar.class);
|
||||
assertNotNull(ctx.getBean(Bar.class).foo);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
class Config {
|
||||
@Bean
|
||||
public FactoryBean<Foo> fb(@Value("42") String answer) {
|
||||
return new FooFactoryBean();
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
}
|
||||
@Configuration
|
||||
static class Config {
|
||||
|
||||
class Bar {
|
||||
Foo foo;
|
||||
|
||||
@Autowired
|
||||
public Bar(Foo foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
class FooFactoryBean implements FactoryBean<Foo> {
|
||||
|
||||
@Override
|
||||
public Foo getObject() {
|
||||
return new Foo();
|
||||
@Bean
|
||||
public FactoryBean<Foo> fb(@Value("42") String answer) {
|
||||
return new FooFactoryBean();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Foo> getObjectType() {
|
||||
return Foo.class;
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
|
||||
static class Bar {
|
||||
|
||||
Foo foo;
|
||||
|
||||
@Autowired
|
||||
public Bar(Foo foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class FooFactoryBean implements FactoryBean<Foo> {
|
||||
|
||||
@Override
|
||||
public Foo getObject() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Foo> getObjectType() {
|
||||
return Foo.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -16,16 +16,19 @@
|
||||
|
||||
package org.springframework.context.groovy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.GenericGroovyApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Jeff Brown
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class GroovyApplicationContextTests extends TestCase {
|
||||
public class GroovyApplicationContextTests {
|
||||
|
||||
@Test
|
||||
public void testLoadingConfigFile() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
|
||||
"org/springframework/context/groovy/applicationContext.groovy");
|
||||
@@ -35,6 +38,7 @@ public class GroovyApplicationContextTests extends TestCase {
|
||||
assertEquals("Grails", framework);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadingMultipleConfigFiles() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
|
||||
"org/springframework/context/groovy/applicationContext2.groovy",
|
||||
@@ -49,6 +53,7 @@ public class GroovyApplicationContextTests extends TestCase {
|
||||
assertEquals("SpringSource", company);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadingMultipleConfigFilesWithRelativeClass() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
|
||||
ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy");
|
||||
|
||||
Reference in New Issue
Block a user