[webbeans-commits] Webbeans SVN: r358 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Nov 24 04:54:56 EST 2008
Author: dallen6
Date: 2008-11-24 04:54:56 -0500 (Mon, 24 Nov 2008)
New Revision: 358
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
Log:
Fixed runtime problem with observer registrations.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 09:11:48 UTC (rev 357)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 09:54:56 UTC (rev 358)
@@ -19,7 +19,6 @@
import java.lang.annotation.Annotation;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -148,14 +147,8 @@
public <T> void removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
List<EventObserver<?>> observers = registeredObservers.get(eventType);
- for (Iterator<EventObserver<?>> i = observers.iterator(); i.hasNext();)
- {
- if (observer.equals(i.next().getObserver()))
- {
- i.remove();
- break;
- }
- }
+ EventObserver<T> eventObserver = new EventObserver<T>(observer, eventType, bindings);
+ observers.remove(eventObserver);
}
@Override
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-11-24 09:11:48 UTC (rev 357)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-11-24 09:54:56 UTC (rev 358)
@@ -24,7 +24,7 @@
* Tests for the EventManager implementation used by the Web Beans RI.
*
* @author David Allen
- *
+ *
*/
@SpecVersion("PDR")
public class EventManagerTest extends AbstractTest
@@ -37,7 +37,7 @@
}
private Synchronization registeredSynch;
-
+
/**
* Tests adding an observer to the event bus and verified that it can still
* be retrieved for a corresponding event.
@@ -49,11 +49,11 @@
Observer<DangerCall> observer = new AnObserver<DangerCall>();
eventManager.addObserver(observer, DangerCall.class);
DangerCall event = new DangerCall();
-
+
Set<Observer<DangerCall>> observerSet = eventManager.getObservers(event);
assert observerSet.size() == 1;
assert observerSet.iterator().next().equals(observer);
-
+
// Add another observer for the same event, but with an event binding
observer = new AnObserver<DangerCall>();
eventManager.addObserver(observer, DangerCall.class, new TameAnnotationLiteral());
@@ -62,12 +62,12 @@
observerSet = eventManager.getObservers(event, new TameAnnotationLiteral());
assert observerSet.size() == 2;
}
-
+
/**
* Tests the remove operation and verifies that the observer is no longer
* registered for events.
*/
- @Test(groups = {"observerMethod", "broken"})
+ @Test(groups = { "observerMethod" })
public void testRemoveObserver()
{
EventManager eventManager = new EventManager(manager);
@@ -77,114 +77,115 @@
// FIXME CopyOnWrite broke remove, have to check later
assert eventManager.getObservers(new DangerCall()).isEmpty();
}
-
+
/**
* Tests the deferred event feature associated with transactions.
*/
- @Test(groups = {"deferredEvent", "broken"})
+ @Test(groups = { "deferredEvent", "broken" })
public void testDeferEvent()
{
// Setup a transaction manager for this test and inject into the event bus
-// TransactionManager tm = new TransactionManager() {
-// public void begin() throws NotSupportedException, SystemException
-// {
-// }
-//
-// public void commit() throws RollbackException,
-// HeuristicMixedException, HeuristicRollbackException,
-// SecurityException, IllegalStateException, SystemException
-// {
-// }
-//
-// public int getStatus() throws SystemException
-// {
-// return 0;
-// }
-//
-// public Transaction getTransaction() throws SystemException
-// {
-// return new Transaction() {
-//
-// public void commit() throws RollbackException,
-// HeuristicMixedException, HeuristicRollbackException,
-// SecurityException, IllegalStateException, SystemException
-// {
-// }
-//
-// public boolean delistResource(XAResource arg0, int arg1)
-// throws IllegalStateException, SystemException
-// {
-// return false;
-// }
-//
-// public boolean enlistResource(XAResource arg0)
-// throws RollbackException, IllegalStateException,
-// SystemException
-// {
-// return false;
-// }
-//
-// public int getStatus() throws SystemException
-// {
-// return 0;
-// }
-//
-// public void registerSynchronization(Synchronization synchronization)
-// throws RollbackException, IllegalStateException,
-// SystemException
-// {
-// registeredSynch = synchronization;
-// }
-//
-// public void rollback() throws IllegalStateException,
-// SystemException
-// {
-// }
-//
-// public void setRollbackOnly() throws IllegalStateException,
-// SystemException
-// {
-// }
-//
-// };
-// }
-//
-// public void resume(Transaction arg0)
-// throws InvalidTransactionException, IllegalStateException,
-// SystemException
-// {
-// }
-//
-// public void rollback() throws IllegalStateException,
-// SecurityException, SystemException
-// {
-// }
-//
-// public void setRollbackOnly() throws IllegalStateException,
-// SystemException
-// {
-// }
-//
-// public void setTransactionTimeout(int arg0) throws SystemException
-// {
-// }
-//
-// public Transaction suspend() throws SystemException
-// {
-// return null;
-// }
-//
-// };
+ // TransactionManager tm = new TransactionManager() {
+ // public void begin() throws NotSupportedException, SystemException
+ // {
+ // }
+ //
+ // public void commit() throws RollbackException,
+ // HeuristicMixedException, HeuristicRollbackException,
+ // SecurityException, IllegalStateException, SystemException
+ // {
+ // }
+ //
+ // public int getStatus() throws SystemException
+ // {
+ // return 0;
+ // }
+ //
+ // public Transaction getTransaction() throws SystemException
+ // {
+ // return new Transaction() {
+ //
+ // public void commit() throws RollbackException,
+ // HeuristicMixedException, HeuristicRollbackException,
+ // SecurityException, IllegalStateException, SystemException
+ // {
+ // }
+ //
+ // public boolean delistResource(XAResource arg0, int arg1)
+ // throws IllegalStateException, SystemException
+ // {
+ // return false;
+ // }
+ //
+ // public boolean enlistResource(XAResource arg0)
+ // throws RollbackException, IllegalStateException,
+ // SystemException
+ // {
+ // return false;
+ // }
+ //
+ // public int getStatus() throws SystemException
+ // {
+ // return 0;
+ // }
+ //
+ // public void registerSynchronization(Synchronization synchronization)
+ // throws RollbackException, IllegalStateException,
+ // SystemException
+ // {
+ // registeredSynch = synchronization;
+ // }
+ //
+ // public void rollback() throws IllegalStateException,
+ // SystemException
+ // {
+ // }
+ //
+ // public void setRollbackOnly() throws IllegalStateException,
+ // SystemException
+ // {
+ // }
+ //
+ // };
+ // }
+ //
+ // public void resume(Transaction arg0)
+ // throws InvalidTransactionException, IllegalStateException,
+ // SystemException
+ // {
+ // }
+ //
+ // public void rollback() throws IllegalStateException,
+ // SecurityException, SystemException
+ // {
+ // }
+ //
+ // public void setRollbackOnly() throws IllegalStateException,
+ // SystemException
+ // {
+ // }
+ //
+ // public void setTransactionTimeout(int arg0) throws SystemException
+ // {
+ // }
+ //
+ // public Transaction suspend() throws SystemException
+ // {
+ // return null;
+ // }
+ //
+ // };
EventManager eventManager = new EventManager(manager);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
try
{
// eventManager.deferEvent(new DangerCall(), observer);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
}
assert this.registeredSynch != null;
- assert ((DeferredEventNotification)this.registeredSynch).getObserver().equals(observer);
+ assert ((DeferredEventNotification) this.registeredSynch).getObserver().equals(observer);
}
}
More information about the weld-commits
mailing list