コード例 #1
0
 @Test
 public void subcomponentReleaseThenGc() {
   assertBindingCallCounts();
   component.childReleasableScope1Manager().releaseStrongReferences(); // release scope 3
   assertBindingCallCounts(); // no change to scoped bindings
   gcAndWaitUntilWeakReferencesCleared(
       ParentModule.class, ChildModule.class, ChildReleasableScope1.class); // GC
   childAsserts.expectedCallsForChildReleasableScope1Thing++; // expect scope 3 bindings again
   assertBindingCallCounts();
 }
コード例 #2
0
  @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()
  }
コード例 #3
0
 @Test
 public void releasableReferenceManagers() {
   ImmutableMap<Class<? extends Annotation>, ReleasableReferenceManager> managers =
       Maps.uniqueIndex(
           component.managers(),
           new Function<ReleasableReferenceManager, Class<? extends Annotation>>() {
             @Override
             public Class<? extends Annotation> apply(
                 ReleasableReferenceManager releasableReferenceManager) {
               return releasableReferenceManager.scope();
             }
           });
   assertThat(managers)
       .containsEntry(ParentReleasableScope1.class, component.parentReleasableScope1Manager());
   assertThat(managers)
       .containsEntry(ParentReleasableScope2.class, component.parentReleasableScope2Manager());
   assertThat(managers)
       .containsEntry(ChildReleasableScope1.class, component.childReleasableScope1Manager());
   assertThat(managers)
       .containsEntry(ChildReleasableScope2.class, component.childReleasableScope2Manager());
   // Should contain a manager for ChildReleasableScope3 even though
   // @ForReleasableReferences(Scope5.class) isn't needed.
   assertThat(managers).containsKey(ChildReleasableScope3.class);
 }