TollboothRoadAdminClient implements RoadAdminClient { @Override public void createRoad(Road road) throws AlreadyExistsException, IllegalArgumentException, ServiceException { getRoad(road.getName()).ifPresent(r -> { throw new AlreadyExistsException(String.format(ROAD_ALREADY_EXISTS, r.getName())); }); modificationEmitter.emit(new PatchSet(road.getName(), singletonList(PatchOperation.add("", 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 public void createRoad() throws Exception { client.createRoad(road1); assertTrue(store.containsKey(road1.getName())); assertThat(store.get(road1.getName()), is(road1)); }
@Test(expected = AlreadyExistsException.class) public void createRoadThatAlreadyExist() throws Exception { client.createRoad(road1); client.createRoad(road1); }