### Question:
BtcNodesRepository { public List<PeerAddress> getPeerAddresses(@Nullable Socks5Proxy proxy, boolean isUseClearNodesWithProxies) { List<PeerAddress> result; if (proxy != null) { List<PeerAddress> onionHosts = getOnionHosts(); result = new ArrayList<>(onionHosts); if (isUseClearNodesWithProxies) { List<PeerAddress> torAddresses = getClearNodesBehindProxy(proxy); result.addAll(torAddresses); } } else { result = getClearNodes(); } return result; } BtcNodesRepository(List<BtcNodes.BtcNode> nodes);  BtcNodesRepository(BtcNodeConverter converter, List<BtcNodes.BtcNode> nodes); List<PeerAddress> getPeerAddresses(@Nullable Socks5Proxy proxy, boolean isUseClearNodesWithProxies);  }### Answer:
@Test public void testGetPeerAddressesWhenClearNodes() { BtcNode node = mock(BtcNode.class); when(node.hasClearNetAddress()).thenReturn(true); BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS); BtcNodesRepository repository = new BtcNodesRepository(converter, Collections.singletonList(node)); List<PeerAddress> peers = repository.getPeerAddresses(null, false); assertFalse(peers.isEmpty()); }
@Test public void testGetPeerAddressesWhenConverterReturnsNull() { BtcNodeConverter converter = mock(BtcNodeConverter.class); when(converter.convertClearNode(any())).thenReturn(null); BtcNode node = mock(BtcNode.class); when(node.hasClearNetAddress()).thenReturn(true); BtcNodesRepository repository = new BtcNodesRepository(converter, Collections.singletonList(node)); List<PeerAddress> peers = repository.getPeerAddresses(null, false); verify(converter).convertClearNode(any()); assertTrue(peers.isEmpty()); }
@Test public void testGetPeerAddressesWhenProxyAndClearNodes() { BtcNode node = mock(BtcNode.class); when(node.hasClearNetAddress()).thenReturn(true); BtcNode onionNode = mock(BtcNode.class); when(node.hasOnionAddress()).thenReturn(true); BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS); BtcNodesRepository repository = new BtcNodesRepository(converter, Lists.newArrayList(node, onionNode)); List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), true); assertEquals(2, peers.size()); }
@Test public void testGetPeerAddressesWhenOnionNodesOnly() { BtcNode node = mock(BtcNode.class); when(node.hasClearNetAddress()).thenReturn(true); BtcNode onionNode = mock(BtcNode.class); when(node.hasOnionAddress()).thenReturn(true); BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS); BtcNodesRepository repository = new BtcNodesRepository(converter, Lists.newArrayList(node, onionNode)); List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), false); assertEquals(1, peers.size()); }