@Test
public void testClientAddress() throws Exception {

    QuorumPeer quorumPeer = new QuorumPeer();
    LocalPeerBean remotePeerBean = new LocalPeerBean(quorumPeer);
    /**
     * Case 1: When cnxnFactory is null
     */
    String result = remotePeerBean.getClientAddress();
    assertNotNull(result);
    assertEquals(0, result.length());
    /**
     * Case 2: When only client port is configured
     */
    ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
    int clientPort = PortAssignment.unique();
    InetSocketAddress address = new InetSocketAddress(clientPort);
    cnxnFactory.configure(address, 5, false);
    quorumPeer.setCnxnFactory(cnxnFactory);
    result = remotePeerBean.getClientAddress();
    String ipv4 = "0.0.0.0:" + clientPort;
    String ipv6 = "0:0:0:0:0:0:0:0:" + clientPort;
    assertTrue(result.equals(ipv4) || result.equals(ipv6));
    // cleanup
    cnxnFactory.shutdown();
    /**
     * Case 3: When both client port and client address is configured
     */
    clientPort = PortAssignment.unique();
    InetAddress clientIP = InetAddress.getLoopbackAddress();
    address = new InetSocketAddress(clientIP, clientPort);
    cnxnFactory = ServerCnxnFactory.createFactory();
    cnxnFactory.configure(address, 5, false);
    quorumPeer.setCnxnFactory(cnxnFactory);
    result = remotePeerBean.getClientAddress();
    String expectedResult = clientIP.getHostAddress() + ":" + clientPort;
    assertEquals(expectedResult, result);
    // cleanup
    cnxnFactory.shutdown();
}