@Test public void testValidAddressSocketChannel() throws Exception { val testPort = 2; val testAddress = "192.168.0.1"; val inetSocketAddress = new InetSocketAddress(testAddress, testPort); val expectedResult = testAddress + ":" + String.valueOf(testPort); when(socketChannel.remoteAddress()).thenReturn(inetSocketAddress); val result = subject.extractRemoteAddressAndPort(socketChannel); assertTrue(result.equals(expectedResult)); }
@Nullable public String extractRemoteAddressAndPort(Channel channel) { if (channel instanceof ServerSocketChannel) { val inetSocketAddress = ((ServerSocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else if (channel instanceof SocketChannel) { val inetSocketAddress = ((SocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else { return null; } }
SocketAddressHelper { @Nullable public String extractRemoteAddressAndPort(Channel channel) { if (channel instanceof ServerSocketChannel) { val inetSocketAddress = ((ServerSocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else if (channel instanceof SocketChannel) { val inetSocketAddress = ((SocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else { return null; } } }
SocketAddressHelper { @Nullable public String extractRemoteAddressAndPort(Channel channel) { if (channel instanceof ServerSocketChannel) { val inetSocketAddress = ((ServerSocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else if (channel instanceof SocketChannel) { val inetSocketAddress = ((SocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else { return null; } }  }
SocketAddressHelper { @Nullable public String extractRemoteAddressAndPort(Channel channel) { if (channel instanceof ServerSocketChannel) { val inetSocketAddress = ((ServerSocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else if (channel instanceof SocketChannel) { val inetSocketAddress = ((SocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else { return null; } }  @Nullable String extractRemoteAddressAndPort(Channel channel); }
SocketAddressHelper { @Nullable public String extractRemoteAddressAndPort(Channel channel) { if (channel instanceof ServerSocketChannel) { val inetSocketAddress = ((ServerSocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else if (channel instanceof SocketChannel) { val inetSocketAddress = ((SocketChannel) channel).remoteAddress(); return computeAddressAndPort(inetSocketAddress); } else { return null; } }  @Nullable String extractRemoteAddressAndPort(Channel channel);  }