Created
April 16, 2012 17:53
-
-
Save cbeams/2400318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2002-2012 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. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package org.springframework.spr9051; | |
import org.junit.Test; | |
import org.springframework.beans.factory.InitializingBean; | |
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
public class Spr9051Tests { | |
@Test | |
public void liteMode() { | |
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); | |
ctx.register(LiteConfig.class); | |
ctx.refresh(); | |
assertThat(ctx.getBean(Foo.class).isInitialized(), is(true)); | |
} | |
@Test | |
public void fullMode() { | |
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); | |
ctx.register(FullConfig.class); | |
ctx.refresh(); | |
assertThat(ctx.getBean(Foo.class).isInitialized(), is(true)); | |
} | |
} | |
class LiteConfig { | |
@Bean | |
public Foo foo() { | |
return new SimpleFoo(); | |
} | |
} | |
@Configuration | |
class FullConfig { | |
@Bean | |
public Foo foo() { | |
return new SimpleFoo(); | |
} | |
} | |
interface Foo { | |
boolean isInitialized(); | |
} | |
class SimpleFoo implements Foo, InitializingBean { | |
private boolean isInitialized = false; | |
public void afterPropertiesSet() throws Exception { | |
this.isInitialized = true; | |
} | |
public boolean isInitialized() { | |
return isInitialized; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment