OnrampTemplate implements Onramp { @Override public List<String> getCidrBlocks() { return Optional .of(getRoad()) .map(Road::getAuthorisation) .map(Authorisation::getOnramp) .map(Authorisation.Onramp::getCidrBlocks) .filter(l -> l.size() > 0) .orElseGet(() -> singletonList("0.0.0.0/0")); } protected  OnrampTemplate(Road road); @Override Future<Boolean> sendEvent(JsonNode jsonEvent); @Override boolean isAvailable(); @Override List<String> getCidrBlocks();  }
@Test public void getCidrBlocks() { Road road = new Road(); Authorisation authorisation = new Authorisation(); Onramp onramp = new Onramp(); List<String> cidrBlocks = singletonList("cidrBlock"); onramp.setCidrBlocks(cidrBlocks); authorisation.setOnramp(onramp); road.setAuthorisation(authorisation); when(underTest.getRoad()).thenReturn(road); List<String> result = underTest.getCidrBlocks(); assertThat(result, is(cidrBlocks)); }