### Question:
DiscoveryFactory implements Discovery { public static Discovery provider() { final NetworkStore networkStore = NetworkStore.getInstance(); final RuntimeContext runtimeContext = RuntimeContext.getInstance(); final Discovery discovery; if(runtimeContext.isDisablePeerDiscovery()) { final Set<NodeUri> knownNodes = runtimeContext.getPeers().stream() .map(NodeUri::create) .collect(Collectors.toUnmodifiableSet()); discovery = new DisabledAutoDiscovery(networkStore,knownNodes); } else { discovery = new AutoDiscovery(networkStore); } return discovery; } DiscoveryFactory(); protected  DiscoveryFactory(Discovery discovery); static Discovery provider(); @Override void onCreate(); @Override void onUpdate(NodeInfo nodeInfo); @Override void onDisconnect(URI nodeUri);  }### Answer:
@Test public void provideAutoDiscovery() { when(runtimeContext.isDisablePeerDiscovery()).thenReturn(false); Discovery discovery = DiscoveryFactory.provider(); assertThat(discovery).isNotNull().isExactlyInstanceOf(AutoDiscovery.class); verify(runtimeContext).isDisablePeerDiscovery(); }
@Test public void provideDisabledAutoDiscovery() { when(runtimeContext.isDisablePeerDiscovery()).thenReturn(true); Discovery discovery = DiscoveryFactory.provider(); assertThat(discovery).isNotNull().isExactlyInstanceOf(DisabledAutoDiscovery.class); verify(runtimeContext).isDisablePeerDiscovery(); verify(runtimeContext).getPeers(); }