TollboothRoadAdminClient implements RoadAdminClient { @Override public Optional<Road> getRoad(String name) throws IllegalArgumentException, ServiceException { checkNotBlank(name, "name"); Road road = store.get(name); if(road == null || road.isDeleted()) { return Optional.empty(); } return Optional.ofNullable(road); } @Autowired  TollboothRoadAdminClient(@Value("#{store}") Map<String, Road> store, PatchSetEmitter modificationEmitter); @Override SortedSet<String> listRoads(); @Override Optional<Road> getRoad(String name); @Override void createRoad(Road road); @Override void updateRoad(PatchSet patchSet);  }
@Test(expected = IllegalArgumentException.class) public void getRoad_fails_when_blank() throws Exception { client.getRoad(" "); }
@Test public void getRoad_returns_empty_optional_when_not_present() throws Exception { Optional<Road> road = client.getRoad("no_road"); assertFalse(road.isPresent()); }
@Test public void getRoad_returns_present_road() throws Exception { store.put(road1.getName(), road1); Optional<Road> road = client.getRoad(road1.getName()); assertTrue(road.isPresent()); assertThat(road.get(), is(road1)); }
@Test public void getRoad_returns_empty_optional_when_road_isDeleted() throws Exception { road1.setDeleted(true); store.put(road1.getName(), road1); Optional<Road> road = client.getRoad(road1.getName()); assertFalse(road.isPresent()); }