GlobalMgcpCallManager implements MgcpCallManager { @Override public boolean registerCall(MgcpCall call) { MgcpCall old = this.calls.putIfAbsent(call.getCallId(), call); boolean registered = (old == null); if (registered && log.isDebugEnabled()) { log.debug("Registered new call " + call.getCallIdHex() +". Call count: " + this.calls.size()); } return registered; } GlobalMgcpCallManager(); @Override MgcpCall getCall(int callId); @Override boolean registerCall(MgcpCall call); @Override MgcpCall unregisterCall(int callId); @Override Set<MgcpCall> unregisterCalls();  }
@Test public void testRegisterCall() { final MgcpCall call1 = mock(MgcpCall.class); final MgcpCall call2 = mock(MgcpCall.class); final MgcpCallManager callManager = new GlobalMgcpCallManager(); when(call1.getCallId()).thenReturn(1); when(call1.getCallIdHex()).thenReturn("1"); when(call2.getCallId()).thenReturn(2); when(call2.getCallIdHex()).thenReturn("2"); final boolean isRegistered = callManager.registerCall(call1); final MgcpCall registeredCall = callManager.getCall(call1.getCallId()); final MgcpCall nonRegisteredCall = callManager.getCall(call2.getCallId()); assertTrue(isRegistered); assertEquals(call1, registeredCall); assertNull(nonRegisteredCall); }
@Test public void testRegisterDuplicateCall() { final MgcpCall call = mock(MgcpCall.class); final MgcpCallManager callManager = new GlobalMgcpCallManager(); when(call.getCallId()).thenReturn(1); when(call.getCallIdHex()).thenReturn("1"); final boolean isRegistered1 = callManager.registerCall(call); final boolean isRegistered2 = callManager.registerCall(call); assertTrue(isRegistered1); assertFalse(isRegistered2); }