SpaceConfigStorageRegistryImpl implements SpaceConfigStorageRegistry { @Override public SpaceConfigStorageBatch getBatch(String spaceName) { Optional<SpaceConfigStorage> optional = Optional.ofNullable(get(spaceName)); if (optional.isPresent()) { return new SpaceStorageBatchImpl(optional.get()); } throw new IllegalArgumentException("Cannot find Space '" + spaceName + "'"); } SpaceConfigStorageRegistryImpl(); @Inject  SpaceConfigStorageRegistryImpl(final Instance<SpaceConfigStorage> spaceConfigStorages); @Override SpaceConfigStorage get(final String spaceName); @Override SpaceConfigStorageBatch getBatch(String spaceName); @Override void remove(String spaceName); @Override boolean exist(String spaceName);  }
@Test public void getBatchTest() { doReturn(mySpaceConfigStorage).when(spaceConfigStorages).get(); final SpaceInfo spaceInfo = mock(SpaceInfo.class); when(mySpaceConfigStorage.loadSpaceInfo()).thenReturn(spaceInfo); SpaceConfigStorageBatch batch = spy(spaceConfigStorageRegistry.getBatch(SPACE_NAME)); Assertions.assertThatThrownBy(() -> batch.run(null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'function' should be not null!"); Function<SpaceConfigStorageBatch.SpaceConfigStorageBatchContext, Void> function = (context) -> { context.saveSpaceInfo(); return null; }; batch.run(function); verify(mySpaceConfigStorage).saveSpaceInfo(any()); }