GenericMgcpEndpoint implements MgcpEndpoint { @Override public MgcpConnection createConnection(int callId, boolean local) { MgcpConnection connection = local ? this.connectionProvider.provideLocal(callId) : this.connectionProvider.provideRemote(callId); registerConnection(callId, connection); if (!connection.isLocal()) { connection.observe(this); } return connection; } GenericMgcpEndpoint(EndpointIdentifier endpointId, MgcpConnectionProvider connectionProvider, MediaGroup mediaGroup); @Override EndpointIdentifier getEndpointId(); @Override MediaGroup getMediaGroup(); boolean hasConnections(); @Override MgcpConnection getConnection(int callId, int connectionId); @Override MgcpConnection createConnection(int callId, boolean local); @Override MgcpConnection deleteConnection(int callId, int connectionId); @Override List<MgcpConnection> deleteConnections(int callId); @Override List<MgcpConnection> deleteConnections(); boolean isActive(); @Override synchronized void requestNotification(NotificationRequest request); @Override void cancelSignal(String signal); @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 onEvent(Object originator, MgcpEvent event); @Override void observe(MgcpEndpointObserver observer); @Override void forget(MgcpEndpointObserver observer); @Override void notify(MgcpEndpoint endpoint, MgcpEndpointState state);  }
@Test public void testCreateConnection() { final int callId1 = 1; final int callId2 = 2; final int connectionId1 = 3; final int connectionId2 = 4; final MgcpConnectionProvider connectionProvider = mock(MgcpConnectionProvider.class); final MgcpLocalConnection connection1 = mock(MgcpLocalConnection.class); final MgcpRemoteConnection connection2 = mock(MgcpRemoteConnection.class); final MediaGroup mediaGroup = mock(MediaGroup.class); final EndpointIdentifier endpointId = new EndpointIdentifier("mobicents/endpoint/1", "127.0.0.1"); final GenericMgcpEndpoint endpoint = new GenericMgcpEndpoint(endpointId, connectionProvider, mediaGroup); when(connectionProvider.provideLocal(callId1)).thenReturn(connection1); when(connectionProvider.provideRemote(callId2)).thenReturn(connection2); when(connection1.getIdentifier()).thenReturn(connectionId1); when(connection1.getCallIdentifier()).thenReturn(callId1); when(connection2.getIdentifier()).thenReturn(connectionId2); when(connection2.getCallIdentifier()).thenReturn(callId2); final MgcpConnection created1 = endpoint.createConnection(callId1, true); final MgcpConnection created2 = endpoint.createConnection(callId2, false); assertTrue(endpoint.hasConnections()); assertEquals(connection1, created1); assertEquals(connection2, created2); }