DBInstanceFactoryImpl implements DBInstanceFactory { @Override public DBInstance getInstance() throws ConfigurationException { return getInstance(JasDBMetadataStore.DEFAULT_INSTANCE); } @Autowired  DBInstanceFactoryImpl(MetadataStore metadataStore, StorageServiceFactory storageServiceFactory); @Override void addInstance(String instanceId); @Override void deleteInstance(String instanceId); @Override DBInstance getInstance(); @Override DBInstance getInstance(String instanceId); @Override boolean hasInstance(String instanceId); @Override List<DBInstance> listInstances(); @Override void shutdown();  }
@Test public void testGetInstance() throws JasDBStorageException { MetadataStore metadataStore = mock(MetadataStore.class); Instance defaultInstance = mock(Instance.class); Instance instance = mock(Instance.class); when(defaultInstance.getInstanceId()).thenReturn("default"); when(instance.getInstanceId()).thenReturn("instance"); when(instance.getPath()).thenReturn("/some/path"); when(metadataStore.getInstances()).thenReturn(Lists.newArrayList(defaultInstance, instance)); DBInstanceFactoryImpl instanceFactory = new DBInstanceFactoryImpl(metadataStore, storageServiceFactory); DBInstance loadedInstance = instanceFactory.getInstance("instance"); assertThat(loadedInstance, notNullValue()); assertThat(loadedInstance.getInstanceId(), is("instance")); assertThat(loadedInstance.getPath(), is("/some/path")); }
@Test public void testGetDefaultInstance() throws JasDBStorageException { MetadataStore metadataStore = mock(MetadataStore.class); Instance defaultInstance = mock(Instance.class); Instance instance = mock(Instance.class); when(instance.getInstanceId()).thenReturn("instance"); when(defaultInstance.getInstanceId()).thenReturn("default"); when(defaultInstance.getPath()).thenReturn("/some/path"); when(metadataStore.getInstances()).thenReturn(Lists.newArrayList(defaultInstance, instance)); DBInstanceFactoryImpl instanceFactory = new DBInstanceFactoryImpl(metadataStore, storageServiceFactory); DBInstance loadedInstance = instanceFactory.getInstance(); assertThat(loadedInstance, notNullValue()); assertThat(loadedInstance.getInstanceId(), is("default")); assertThat(loadedInstance.getPath(), is("/some/path")); }