GlobalMgcpTransactionManager implements MgcpTransactionManager, MgcpMessageObserver { @Override public void observe(MgcpMessageObserver observer) { final boolean added = this.observers.add(observer); if(added && log.isTraceEnabled()) { if (log.isTraceEnabled()) { log.trace("Registered MgcpMessageObserver@" + observer.hashCode() + ". Count: " + this.observers.size()); } } } GlobalMgcpTransactionManager(MgcpTransactionManagerProvider provider); @Override void observe(MgcpMessageObserver observer); @Override void forget(MgcpMessageObserver observer); @Override void notify(Object originator, InetSocketAddress from, InetSocketAddress to, MgcpMessage message, MessageDirection direction); @Override void onMessage(InetSocketAddress from, InetSocketAddress to, MgcpMessage message, MessageDirection direction); @Override void process(InetSocketAddress from, InetSocketAddress to, MgcpRequest request, MgcpCommand command, MessageDirection direction); @Override void process(InetSocketAddress from, InetSocketAddress to, MgcpResponse response, MessageDirection direction);  }
@Test @SuppressWarnings("unchecked") public void testRegisterDuplicateObserver() { final MgcpMessageObserver observer = mock(MgcpMessageObserver.class); final MgcpTransactionManagerProvider provider = mock(MgcpTransactionManagerProvider.class); final GlobalMgcpTransactionManager transactionManager = new GlobalMgcpTransactionManager(provider); final Collection<MgcpMessageObserver> observers = (Collection<MgcpMessageObserver>) Whitebox.getInternalState(transactionManager, "observers"); transactionManager.observe(observer); transactionManager.observe(observer); assertEquals(1, observers.size()); }