ClientTest.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:java-beetle 作者:
private List<Connection> mockedConnectionsForClient(Client client, int numConnections) throws IOException {
    final ConnectionFactory mockFactory = mock(ConnectionFactory.class);
    final OngoingStubbing<Connection> newConnectionStub = when(mockFactory.newConnection());
    List<Connection> conns = new ArrayList<Connection>(numConnections);
    // TODO OMG this is ugly. there's got to be a better way.
    OngoingStubbing<Connection> connectionOngoingStubbing = null;
    for (int i = 0; i < numConnections; i++) {
        final Connection mockConnection = mock(Connection.class);
        if (i == 0) {
            connectionOngoingStubbing = newConnectionStub.thenReturn(mockConnection);
        } else {
            connectionOngoingStubbing.thenReturn(mockConnection);
        }
        final Channel mockChannel = mock(Channel.class);
        when(mockConnection.createChannel()).thenReturn(mockChannel);
        conns.add(mockConnection);
    }
    client.setConnectionFactory(mockFactory);
    return conns;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号