### Question:
ChannelzProtoUtil { static Address toAddress(SocketAddress address) { Preconditions.checkNotNull(address); Address.Builder builder = Address.newBuilder(); if (address instanceof InetSocketAddress) { InetSocketAddress inetAddress = (InetSocketAddress) address; builder.setTcpipAddress( TcpIpAddress .newBuilder() .setIpAddress( ByteString.copyFrom(inetAddress.getAddress().getAddress())) .setPort(inetAddress.getPort()) .build()); } else if (address.getClass().getName().endsWith("io.netty.channel.unix.DomainSocketAddress")) { builder.setUdsAddress( UdsAddress .newBuilder() .setFilename(address.toString()) .build()); } else { builder.setOtherAddress(OtherAddress.newBuilder().setName(address.toString()).build()); } return builder.build(); } private  ChannelzProtoUtil();  static final String SO_LINGER; static final String SO_TIMEOUT; static final String TCP_INFO; }### Answer:
@Test public void toAddress_inet() throws Exception { InetSocketAddress inet4 = new InetSocketAddress(Inet4Address.getByName("10.0.0.1"), 1000); assertEquals( Address.newBuilder().setTcpipAddress( TcpIpAddress .newBuilder() .setIpAddress(ByteString.copyFrom(inet4.getAddress().getAddress())) .setPort(1000)) .build(), ChannelzProtoUtil.toAddress(inet4)); }
@Test public void toAddress_uds() throws Exception { String path = "/tmp/foo"; DomainSocketAddress uds = new DomainSocketAddress(path); assertEquals( Address.newBuilder().setUdsAddress( UdsAddress .newBuilder() .setFilename(path)) .build(), ChannelzProtoUtil.toAddress(uds)); }
@Test public void toAddress_other() throws Exception { final String name = "my name"; SocketAddress other = new SocketAddress() { @Override public String toString() { return name; } }; assertEquals( Address.newBuilder().setOtherAddress( OtherAddress .newBuilder() .setName(name)) .build(), ChannelzProtoUtil.toAddress(other)); }