SfcGeniusDpnIfWriter { public CompletableFuture<Optional<BigInteger>> removeInterfaceFromDpn(BigInteger dpnId, String interfaceName) { Set<String> interfaces = dpnInterfaces.computeIfPresent(dpnId, (key, value) -> { value.remove(interfaceName); return value.isEmpty() ? null : value; }); return interfaces == null ? CompletableFuture.completedFuture(Optional.of(dpnId)) : CompletableFuture.completedFuture(Optional.empty()); } SfcGeniusDpnIfWriter(Map<BigInteger, Set<String>> dpnInterfaces); CompletableFuture<Optional<BigInteger>> addInterface(BigInteger dpnId, String interfaceName); CompletableFuture<Optional<BigInteger>> removeInterfaceFromDpn(BigInteger dpnId, String interfaceName);  }
@Test public void removeInterfaceFromDpnLastOfDpn() throws Exception { int oldSize = dpnInterfaces.size(); Optional<BigInteger> oldDpnId = sfcGeniusDpnIfWriter.removeInterfaceFromDpn(dpnIdWithOneInterface, existingInterface).get(); assertThat(dpnInterfaces.size(), is(oldSize - 1)); assertThat(oldDpnId.isPresent(), is(true)); assertThat(oldDpnId.get(), is(dpnIdWithOneInterface)); }
@Test public void removeInterfaceFromDpnNotLastOfDpn() throws Exception { int oldSize = dpnInterfaces.size(); Optional<BigInteger> oldDpnId = sfcGeniusDpnIfWriter.removeInterfaceFromDpn(dpnIdWithTwoInterfaces, existingInterface).get(); assertThat(dpnInterfaces.size(), is(oldSize)); assertThat(dpnInterfaces.get(dpnIdWithTwoInterfaces).contains(existingInterface), is(false)); assertThat(oldDpnId.isPresent(), is(false)); }