GlobalConfigServiceImpl implements GlobalConfigService { @Override public Map<String, Object> save(Map<String, Object> globalConfig) throws RestException { try { ConfigurationsUtils.writeGlobalConfigToZookeeper(globalConfig, client); } catch (Exception e) { throw new RestException(e); } return globalConfig; } @Autowired  GlobalConfigServiceImpl(CuratorFramework client, ConfigurationsCache cache); void setCache(ConfigurationsCache cache); @Override Map<String, Object> save(Map<String, Object> globalConfig); @Override Map<String, Object> get(); @Override boolean delete();  }
@Test public void saveShouldWrapExceptionInRestException() throws Exception { SetDataBuilder setDataBuilder = mock(SetDataBuilder.class); when(setDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot(), "{ }".getBytes( StandardCharsets.UTF_8))).thenThrow(Exception.class); when(curatorFramework.setData()).thenReturn(setDataBuilder); assertThrows(RestException.class, () -> globalConfigService.save(new HashMap<>())); }
@Test public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception { SetDataBuilder setDataBuilder = mock(SetDataBuilder.class); when(setDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot(), "{ }".getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat()); when(curatorFramework.setData()).thenReturn(setDataBuilder); assertEquals(new HashMap<>(), globalConfigService.save(new HashMap<>())); verify(setDataBuilder).forPath(eq(ConfigurationType.GLOBAL.getZookeeperRoot()), eq("{ }".getBytes(StandardCharsets.UTF_8))); }