TollBoothHiveDestinationAdminClient implements HiveDestinationAdminClient { @Override public void createHiveDestination(String name, HiveDestination hiveDestination) throws UnknownRoadException, AlreadyExistsException { if (getHiveDestination(name).isPresent()) { throw new AlreadyExistsException(String.format("Hive destination for Road \"%s\" already exists.", name)); } List<PatchOperation> operations = new ArrayList<>(); if (!destinations(name).isPresent()) { operations.add(PatchOperation.add(DESTINATIONS, new HashMap<>())); } operations.add(PatchOperation.add(DESTINATIONS_HIVE, hiveDestination)); PatchSet patchSet = new PatchSet(name, operations); modificationEmitter.emit(patchSet); } @Autowired  TollBoothHiveDestinationAdminClient(
      @Value("#{store}") Map<String, Road> roads,
      PatchSetEmitter modificationEmitter); @Override Optional<HiveDestination> getHiveDestination(String name); @Override void createHiveDestination(String name, HiveDestination hiveDestination); @Override void deleteHiveDestination(String name); @Override void updateHiveDestination(String name, HiveDestination hiveDestination);  }
@Test public void createHiveDestination() throws Exception { road.setDestinations(destinations); store.put(NAME, road); underTest.createHiveDestination(NAME, hiveDestination); assertThat(store.get(NAME).getDestinations().get("hive"), is(hiveDestination)); }
@Test(expected = UnknownRoadException.class) public void createHiveDestination_UnknownRoad() throws Exception { underTest.createHiveDestination(NAME, hiveDestination); }
@Test public void createHiveDestination_DestinationsNull() throws Exception { store.put(NAME, road); underTest.createHiveDestination(NAME, hiveDestination); assertThat(store.get(NAME).getDestinations().get("hive"), is(hiveDestination)); }
@Test(expected = AlreadyExistsException.class) public void createHiveDestination_AlreadyExists() throws Exception { destinations.put("hive", hiveDestination); road.setDestinations(destinations); store.put(NAME, road); underTest.createHiveDestination(NAME, hiveDestination); }
@Test(expected = UnknownRoadException.class) public void createHiveDestination_deletedRoad() throws Exception { road.setDeleted(true); store.put(NAME, road); underTest.createHiveDestination(NAME, hiveDestination); }