GlobalMgcpCallManager implements MgcpCallManager { @Override public Set<MgcpCall> unregisterCalls() { Set<MgcpCall> values; if (this.calls.isEmpty()) { values = Collections.<MgcpCall> emptySet(); } else { values = new HashSet<>(this.calls.values()); this.calls.clear(); if (log.isDebugEnabled()) { log.debug("Unregistered "+ values.size() +" calls: " + Arrays.toString(getCallHexId(values))); } } return values; } GlobalMgcpCallManager(); @Override MgcpCall getCall(int callId); @Override boolean registerCall(MgcpCall call); @Override MgcpCall unregisterCall(int callId); @Override Set<MgcpCall> unregisterCalls();  }
@Test public void testUnregisterCalls() { final MgcpCall call1 = mock(MgcpCall.class); final MgcpCall call2 = mock(MgcpCall.class); final MgcpCall call3 = 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"); when(call3.getCallId()).thenReturn(3); when(call3.getCallIdHex()).thenReturn("3"); callManager.registerCall(call1); callManager.registerCall(call2); callManager.registerCall(call3); final Set<MgcpCall> unregistered = callManager.unregisterCalls(); final MgcpCall retrievedCall1 = callManager.getCall(call1.getCallId()); final MgcpCall retrievedCall2 = callManager.getCall(call2.getCallId()); final MgcpCall retrievedCall3 = callManager.getCall(call3.getCallId()); assertEquals(3, unregistered.size()); assertTrue(unregistered.contains(call1)); assertTrue(unregistered.contains(call2)); assertTrue(unregistered.contains(call3)); assertNull(retrievedCall1); assertNull(retrievedCall2); assertNull(retrievedCall3); }
@Test public void testUnregisterCallsFromEmptyCallManager() { final MgcpCallManager callManager = new GlobalMgcpCallManager(); final Set<MgcpCall> unregistered = callManager.unregisterCalls(); assertNotNull(unregistered); assertTrue(unregistered.isEmpty()); }