SensorIndexingConfigServiceImpl implements SensorIndexingConfigService { @Override public boolean delete(String name) throws RestException { try { client.delete().forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/" + name); } catch (KeeperException.NoNodeException e) { return false; } catch (Exception e) { throw new RestException(e); } return true; } @Autowired  SensorIndexingConfigServiceImpl(ObjectMapper objectMapper, CuratorFramework client, ConfigurationsCache cache); @Override Map<String, Object> save(String name, Map<String, Object> sensorIndexingConfig); @Override Map<String, Object> findOne(String name); @Override Map<String, Map<String, Object>> getAll(); @Override List<String> getAllTypes(); @Override Iterable<String> getAllIndices(String writerName); @Override boolean delete(String name);  }
@Test public void deleteShouldProperlyCatchNoNodeExceptionAndReturnFalse() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro")).thenThrow(KeeperException.NoNodeException.class); assertFalse(sensorIndexingConfigService.delete("bro")); }
@Test public void deleteShouldProperlyCatchNonNoNodeExceptionAndThrowRestException() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); when(builder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro")).thenThrow(Exception.class); assertThrows(RestException.class, () -> sensorIndexingConfigService.delete("bro")); }
@Test public void deleteShouldReturnTrueWhenClientSuccessfullyCallsDelete() throws Exception { DeleteBuilder builder = mock(DeleteBuilder.class); when(curatorFramework.delete()).thenReturn(builder); assertTrue(sensorIndexingConfigService.delete("bro")); verify(curatorFramework).delete(); }