LocalStorageServiceFactoryImpl implements StorageServiceFactory { @Override public void removeStorageService(String instanceId, String bagName) throws JasDBStorageException { String storageServiceKey = instanceId + "_" + bagName; StorageService storageService = storageServices.get(storageServiceKey); if(storageService != null) { storageService.remove(); storageServices.remove(storageServiceKey); metadataStore.removeBag(instanceId, bagName); } else { throw new JasDBStorageException("Unable to remove bag, bag does not exist"); } }  @PostConstruct void initializeServices(); @Override StorageService getStorageService(String instanceId, String bagName); @Override StorageService getOrCreateStorageService(String instanceId, String bagName); @Override void removeStorageService(String instanceId, String bagName); @Override void removeAllStorageService(String instanceId); @Override void shutdownServiceFactory();  }
@Test public void testRemoveStorageService() throws Exception { when(metadataStore.containsBag(TEST_INSTANCE, TEST_BAG_NAME)).thenReturn(true); when(metadataStore.containsInstance(TEST_INSTANCE)).thenReturn(true); when(metadataStore.getInstance(TEST_INSTANCE)).thenReturn(new InstanceMeta(TEST_INSTANCE, jasdbHomeFolder)); StorageService storageService = storageServiceFactory.getOrCreateStorageService(TEST_INSTANCE, TEST_BAG_NAME); assertNotNull(storageService); assertThat(storageService, is(storageService)); verify(storageService, times(1)).openService(eq(configuration)); storageServiceFactory.removeStorageService(TEST_INSTANCE, TEST_BAG_NAME); verify(storageService, times(1)).remove(); verify(metadataStore, times(1)).removeBag(TEST_INSTANCE, TEST_BAG_NAME); when(metadataStore.containsBag(TEST_INSTANCE, TEST_BAG_NAME)).thenReturn(false); storageService = storageServiceFactory.getStorageService(TEST_INSTANCE, TEST_BAG_NAME); assertNull(storageService); }