MvcGraph { Graph prepareInternalGraph(Graph graph, MvcComponent rootComponent) { try { graph.setRootComponent(rootComponent); graph.getRootComponent().register(new Object() { @Provides public UiThreadRunner uiThreadRunner() { return uiThreadRunner; } }); } catch (Graph.IllegalRootComponentException e) { throw new MvcGraphException(e.getMessage(), e); } catch (PokeException e) { throw new MvcGraphException(e.getMessage(), e); } graph.registerDisposeListener(new Provider.DisposeListener() { @Override public <T> void onDisposed(Provider<T> provider, T instance) { if (instance != null && instance instanceof Bean) { Bean bean = (Bean) instance; bean.onDestroy(); logger.trace("---Bean destroyed - '{}'.", provider.type().getSimpleName()); } } }); return graph; }  void registerMonitor(final Graph.Monitor monitor); void unregisterMonitor(final Graph.Monitor monitor); void clearMonitors(); T reference(Class<T> type, Annotation qualifier); void dereference(T instance, Class<T> type, Annotation qualifier); void use(final Class<T> type, final Consumer<T> consumer); void use(final Class<T> type, final Annotation qualifier, final Consumer<T> consumer); void inject(final Object target); void release(final Object target); void setRootComponent(final MvcComponent component); MvcComponent getRootComponent(); void registerDereferencedListener(
            final Provider.DereferenceListener onProviderFreedListener); void unregisterDereferencedListener(
            final Provider.DereferenceListener onProviderFreedListener); void clearDereferencedListeners();  }
@Test public void should_throw_IllegalRootComponentException_on_graph_preparation_with_attached_component() throws Component.MultiParentException, ProviderConflictException { MvcComponent parent = new MvcComponent(""); MvcComponent child = new MvcComponent(""); parent.attach(child); boolean caught = false; try { graph.prepareInternalGraph(new Graph(), child); } catch (MvcGraphException e) { if (e.getCause() instanceof Graph.IllegalRootComponentException) { caught = true; } } Assert.assertTrue(caught); }
@Test public void should_throw_ProviderConflictException_on_graph_preparation_by_duplicate_registration() throws Component.MultiParentException, ProviderConflictException, ProvideException { MvcComponent component = new MvcComponent(""); component.register(new Object() { @Provides public UiThreadRunner uiThreadRunner() { return mock(UiThreadRunner.class); } }); boolean caught = false; try { graph.prepareInternalGraph(new Graph(), component); } catch (MvcGraphException e) { if (e.getCause() instanceof ProviderConflictException) { caught = true; } } Assert.assertTrue(caught); }