@Override protected ImmutableMap<Class<?>, Thing> expectedThingMap() { ++expectedCallsForChildUnscopedThing; // unscoped Thing @Provides method is always called return new ImmutableMap.Builder<Class<?>, Thing>() .putAll(parentAsserts.expectedThingMap()) .put(ChildModule.class, thing(expectedCallsForChildUnscopedThing)) .put(ChildRegularScope.class, thing(expectedCallsForChildRegularScopeThing)) .put(ChildReleasableScope1.class, thing(expectedCallsForChildReleasableScope1Thing)) .put(ChildReleasableScope2.class, thing(expectedCallsForChildReleasableScope2Thing)) .build(); }
@Test public void twoInstancesOfSameSubcomponent() { // Two instances of the same subcomponent. ChildAsserts child2Asserts = parentAsserts.newChildAsserts(); childAsserts.assertBindingCallCounts(); child2Asserts.assertBindingCallCounts(); component.childReleasableScope1Manager().releaseStrongReferences(); // release scope 3 childAsserts.assertBindingCallCounts(); // no change to scoped bindings in child 1 child2Asserts.assertBindingCallCounts(); // no change to scoped bindings in child 2 gcAndWaitUntilWeakReferencesCleared( ParentModule.class, ChildModule.class, ChildReleasableScope1.class); // GC childAsserts.expectedCallsForChildReleasableScope1Thing++; // expect scope 3 bindings again childAsserts.assertBindingCallCounts(); // when calling child.things() child2Asserts.expectedCallsForChildReleasableScope1Thing++; // expect scope 3 bindings yet again child2Asserts.assertBindingCallCounts(); // when calling child2.things() }
@Before public void setUp() { component = DaggerReleasableReferencesComponents_Parent.create(); parentAsserts = new ParentAsserts(component); childAsserts = parentAsserts.newChildAsserts(); }
private void assertBindingCallCounts() { parentAsserts.assertBindingCallCounts(); childAsserts.assertBindingCallCounts(); }