@Before public void setUp() throws Exception { Toothpick.setConfiguration(Configuration.forProduction().disableReflection()); Toothpick.openScope(ROOT_SCOPE); scopeNames.clear(); }
@Test public void createScope_shouldReturnAnScopeWithAParent_whenThisScopeByThisKeyWasCreatedWithAParent() throws Exception { //GIVEN Toothpick.setConfiguration(Configuration.forProduction()); ScopeNode scopeParent = (ScopeNode) Toothpick.openScope("foo"); //WHEN ScopeNode scope = (ScopeNode) Toothpick.openScope("bar"); scopeParent.addChild(scope); //THEN assertThat(scope, notNullValue()); assertThat(scope.getParentScope(), sameInstance(scopeParent)); }
@AfterClass public static void staticTearDown() throws Exception { Toothpick.setConfiguration(Configuration.forProduction().disableReflection()); }
@Before public void setUp() throws Exception { Toothpick.setConfiguration(Configuration.forProduction().disableReflection()); }
@Test public void destroyScope_shouldClearThisScope_WhenThisScopesWasCreated() throws Exception { //GIVEN Toothpick.setConfiguration(Configuration.forProduction()); Scope scope = Toothpick.openScope("foo"); //WHEN Toothpick.closeScope("foo"); Scope scopeAfterReset = Toothpick.openScope("foo"); //THEN assertThat(scopeAfterReset, not(sameInstance(scope))); }
@Test public void reset_shouldClear_WhenSomeScopesWereCreated() throws Exception { //GIVEN Toothpick.setConfiguration(Configuration.forProduction()); Scope scope0 = Toothpick.openScope("foo"); Scope scope1 = Toothpick.openScope("bar"); //WHEN Toothpick.reset(); Scope scope0AfterReset = Toothpick.openScope("foo"); Scope scope1AfterReset = Toothpick.openScope("bar"); //THEN assertThat(scope0AfterReset, not(sameInstance(scope0))); assertThat(scope1AfterReset, not(sameInstance(scope1))); }
@Test public void getOrCreateScope_shouldReturnANewScopeScope_WhenOneWasNotCreatedWithSameKey() throws Exception { //GIVEN Toothpick.setConfiguration(Configuration.forProduction()); ScopeNode scopeParent = (ScopeNode) Toothpick.openScope("bar"); //WHEN ScopeNode scope = (ScopeNode) Toothpick.openScope("foo"); scopeParent.addChild(scope); ScopeNode scope2 = (ScopeNode) Toothpick.openScope("foo"); //THEN assertThat(scope, notNullValue()); assertThat(scope2, sameInstance(scope)); assertThat(scope.getParentScope(), sameInstance(scopeParent)); }
@Test public void testGetMemberInjector_shouldReturnNull_whenThereAreNoRegistries() throws Exception { //GIVEN Toothpick.setConfiguration(Configuration.forProduction().disableReflection()); MemberInjectorRegistryLocator.setRootRegistry(null); //WHEN MemberInjector<Foo> memberInjector = MemberInjectorRegistryLocator.getMemberInjector(Foo.class); //THEN assertThat(memberInjector, nullValue()); }
@BeforeClass public static void setUp() throws Exception { MemberInjectorRegistryLocator.setRootRegistry(new toothpick.test.MemberInjectorRegistry()); FactoryRegistryLocator.setRootRegistry(new toothpick.test.FactoryRegistry()); Toothpick.setConfiguration(Configuration.forProduction().disableReflection()); }
@Override public void onCreate() { super.onCreate(); // com.example.smoothie.MemberInjectorRegistry and com.example.smoothie.FactoryRegistry are classes generated by this project // Your project will have these classes in your package (or the one you specify). // Please note that the fully qualified name should be used instead of an import. // (see https://github.com/stephanenicolas/toothpick/wiki/Factory-and-Member-Injector-registries) // If you're not using the reflection free configuration, the next 3 lines can be omitted Toothpick.setConfiguration(Configuration.forProduction().disableReflection()); MemberInjectorRegistryLocator.setRootRegistry(new com.example.smoothie.MemberInjectorRegistry()); FactoryRegistryLocator.setRootRegistry(new com.example.smoothie.FactoryRegistry()); Scope appScope = Toothpick.openScope(this); initToothpick(appScope); }