@Test(groups = "roboguice", expectedExceptions = RuntimeException.class) public void testApplicationContextEvent(){ Context applicationContext = EasyMock.createMock(Application.class); for(Method method : eventOneMethods){ eventManager.registerObserver(applicationContext, tester, method, EventOne.class); } }
public void registerObserver(Context context, Object instance, Method method, Class event) { if (!isEnabled()) return; if( context instanceof Application ) throw new RuntimeException("You may not register event handlers on the Application context"); Map<Class<?>, Set<ObserverReference<?>>> methods = registrations.get(context); if (methods == null) { methods = new HashMap<Class<?>, Set<ObserverReference<?>>>(); registrations.put(context, methods); } Set<ObserverReference<?>> observers = methods.get(event); if (observers == null) { observers = new HashSet<ObserverReference<?>>(); methods.put(event, observers); } observers.add(new ObserverReference(instance, method)); }
EventManager { public void registerObserver(Context context, Object instance, Method method, Class event) { if (!isEnabled()) return; if( context instanceof Application ) throw new RuntimeException("You may not register event handlers on the Application context"); Map<Class<?>, Set<ObserverReference<?>>> methods = registrations.get(context); if (methods == null) { methods = new HashMap<Class<?>, Set<ObserverReference<?>>>(); registrations.put(context, methods); } Set<ObserverReference<?>> observers = methods.get(event); if (observers == null) { observers = new HashSet<ObserverReference<?>>(); methods.put(event, observers); } observers.add(new ObserverReference(instance, method)); } }
EventManager { public void registerObserver(Context context, Object instance, Method method, Class event) { if (!isEnabled()) return; if( context instanceof Application ) throw new RuntimeException("You may not register event handlers on the Application context"); Map<Class<?>, Set<ObserverReference<?>>> methods = registrations.get(context); if (methods == null) { methods = new HashMap<Class<?>, Set<ObserverReference<?>>>(); registrations.put(context, methods); } Set<ObserverReference<?>> observers = methods.get(event); if (observers == null) { observers = new HashSet<ObserverReference<?>>(); methods.put(event, observers); } observers.add(new ObserverReference(instance, method)); }  }
EventManager { public void registerObserver(Context context, Object instance, Method method, Class event) { if (!isEnabled()) return; if( context instanceof Application ) throw new RuntimeException("You may not register event handlers on the Application context"); Map<Class<?>, Set<ObserverReference<?>>> methods = registrations.get(context); if (methods == null) { methods = new HashMap<Class<?>, Set<ObserverReference<?>>>(); registrations.put(context, methods); } Set<ObserverReference<?>> observers = methods.get(event); if (observers == null) { observers = new HashSet<ObserverReference<?>>(); methods.put(event, observers); } observers.add(new ObserverReference(instance, method)); }  boolean isEnabled(); void registerObserver(Context context, Object instance, Method method, Class event); void unregisterObserver(Context context, Object instance, Class event); void clear( Context context ); void fire( Object event ); void fire(Context context, Object event); }
EventManager { public void registerObserver(Context context, Object instance, Method method, Class event) { if (!isEnabled()) return; if( context instanceof Application ) throw new RuntimeException("You may not register event handlers on the Application context"); Map<Class<?>, Set<ObserverReference<?>>> methods = registrations.get(context); if (methods == null) { methods = new HashMap<Class<?>, Set<ObserverReference<?>>>(); registrations.put(context, methods); } Set<ObserverReference<?>> observers = methods.get(event); if (observers == null) { observers = new HashSet<ObserverReference<?>>(); methods.put(event, observers); } observers.add(new ObserverReference(instance, method)); }  boolean isEnabled(); void registerObserver(Context context, Object instance, Method method, Class event); void unregisterObserver(Context context, Object instance, Class event); void clear( Context context ); void fire( Object event ); void fire(Context context, Object event);  }