1 16 17 package com.google.inject; 18 19 import junit.framework.TestCase; 20 21 24 public class PreloadingTest extends TestCase { 25 26 protected void tearDown() throws Exception { 27 Foo.count = 0; 28 Bar.count = 0; 29 } 30 31 public void testPreloadSome() throws CreationException { 32 BinderImpl builder = createBinder(Stage.DEVELOPMENT); 33 builder.createInjector(); 34 assertEquals(1, Foo.count); 35 assertEquals(0, Bar.count); 36 } 37 38 public void testPreloadAll() throws CreationException { 39 BinderImpl builder = createBinder(Stage.PRODUCTION); 40 builder.createInjector(); 41 assertEquals(1, Foo.count); 42 assertEquals(1, Bar.count); 43 } 44 45 private BinderImpl createBinder(Stage stage) { 46 BinderImpl builder = new BinderImpl(stage); 47 builder.bind(Foo.class).asEagerSingleton(); 48 builder.bind(Bar.class); 49 return builder; 50 } 51 52 static class Foo { 53 static int count = 0; 54 public Foo() { 55 count++; 56 } 57 } 58 59 @Singleton 60 static class Bar { 61 static int count = 0; 62 public Bar() { 63 count++; 64 } 65 } 66 } 67 | Popular Tags |