ContextScope implements Scope { protected Map<Key<?>,Object> getScopedObjectMap(final Context origContext) { Context context = origContext; while( !(context instanceof RoboContext) && !(context instanceof Application) && context instanceof ContextWrapper ) context = ((ContextWrapper)context).getBaseContext(); if( context instanceof Application ) return applicationScopedObjects; if( !(context instanceof RoboContext) ) throw new IllegalArgumentException(String.format("%s does not appear to be a RoboGuice context (instanceof RoboContext)",origContext)); return ((RoboContext)context).getScopedObjectMap(); } ContextScope(Application application); void enter(Context context); void exit(Context context); Provider<T> scope(final Key<T> key, final Provider<T> unscoped); Stack<WeakReference<Context>> getContextStack();  }
@Test public void shouldHaveContextInScopeMapAfterOnCreate() throws Exception { final ActivityController<A> aController = Robolectric.buildActivity(A.class); final A a = aController.get(); assertThat(a.getScopedObjectMap().size(), equalTo(0)); aController.create(); boolean found=false; for( Object o : a.getScopedObjectMap().values() ) if( o==a ) found = true; assertTrue("Couldn't find context in scope map", found); }
@Test public void shouldHaveTwoItemsInScopeMapAfterOnCreate() throws Exception { final ActivityController<B> bController = Robolectric.buildActivity(B.class); final B b = bController.get(); assertThat(b.getScopedObjectMap().size(), equalTo(0)); bController.create(); boolean found=false; for( Object o : b.getScopedObjectMap().values() ) if( o==b ) found = true; assertTrue("Couldn't find context in scope map", found); assertTrue(b.getScopedObjectMap().containsKey(Key.get(C.class))); }