src/test/java/au/id/djc/stringtemplate/AnnotationAttributeRendererGeneratorUnitTest.java (1269B) - raw
1 package au.id.djc.stringtemplate; 2 3 import static org.hamcrest.CoreMatchers.*; 4 import static org.junit.Assert.*; 5 6 import org.junit.Before; 7 import org.junit.Test; 8 import org.springframework.context.support.StaticApplicationContext; 9 10 public class AnnotationAttributeRendererGeneratorUnitTest { 11 12 private StaticApplicationContext context; 13 14 @Before 15 public void setUp() { 16 context = new StaticApplicationContext(); 17 context.registerSingleton("dummyBean", Object.class); 18 } 19 20 @Test 21 public void shouldRegisterNothingForNoAnnotatedBeans() { 22 context.registerSingleton("generator", AnnotationAttributeRendererGenerator.class); 23 context.refresh(); 24 assertThat(context.getBeansOfType(AttributeRenderer.class).size(), equalTo(0)); 25 } 26 27 public static class Annotated { 28 @AttributeRendererMethod 29 public String render(String s) { return s; } 30 } 31 32 @Test 33 public void shouldRegisterGeneratedBean() { 34 context.registerSingleton("annotated", Annotated.class); 35 context.registerSingleton("generator", AnnotationAttributeRendererGenerator.class); 36 context.refresh(); 37 assertThat(context.getBeansOfType(AttributeRenderer.class).size(), equalTo(1)); 38 } 39 40 }