### Question:
StorageEngineFactory { public StorageEngine buildStorageEngine(String engineType) throws StorageEngineException { StorageEngine engine; if (SOLR_ENGINE_TYPE.equals(engineType)) { engine = new SolrStorageEngine(config.getSolr()); } else { engine = constructEngineFromConfiguration(config.getAdditionalEngines().get(engineType)); } return engine; } StorageEngineFactory(StorageConfiguration config); StorageEngine buildStorageEngine(String engineType);  }### Answer:
@Test public void buildStorageEngine_nullEngineType() throws Exception { final String engineType = null; StorageConfiguration config = mock(StorageConfiguration.class); final Map<String, StorageEngineConfiguration> additionalConfig = new HashMap<>(); when(config.getAdditionalEngines()).thenReturn(additionalConfig); StorageEngineFactory factory = new StorageEngineFactory(config); StorageEngine engine = factory.buildStorageEngine(engineType); assertNull(engine); }
@Test public void buildStorageEngine_withUnrecognisedEngineType() throws Exception { final String engineType = "blah"; StorageConfiguration config = mock(StorageConfiguration.class); final Map<String, StorageEngineConfiguration> additionalConfig = new HashMap<>(); when(config.getAdditionalEngines()).thenReturn(additionalConfig); StorageEngineFactory factory = new StorageEngineFactory(config); StorageEngine engine = factory.buildStorageEngine(engineType); assertNull(engine); verify(config).getAdditionalEngines(); }
@Test public void buildStorageEngine_forSolr() throws Exception { final String engineType = StorageEngineFactory.SOLR_ENGINE_TYPE; SolrConfiguration solrConfig = mock(SolrConfiguration.class); when(solrConfig.getBaseUrl()).thenReturn("http: StorageConfiguration config = mock(StorageConfiguration.class); when(config.getSolr()).thenReturn(solrConfig); StorageEngineFactory factory = new StorageEngineFactory(config); StorageEngine engine = factory.buildStorageEngine(engineType); assertNotNull(engine); assertTrue(engine instanceof SolrStorageEngine); verify(config).getSolr(); }
@Test public void buildStorageEngine_forNonSolr() throws Exception { final String engineType = "test"; final String testEngineClass = "uk.co.flax.biosolr.ontology.storage.TestStorageEngine"; StorageConfiguration config = mock(StorageConfiguration.class); Map<String, StorageEngineConfiguration> engineMap = new HashMap<>(); StorageEngineConfiguration engineConfig = mock(StorageEngineConfiguration.class); when(engineConfig.getEngineClass()).thenReturn(testEngineClass); when(engineConfig.getConfiguration()).thenReturn(new HashMap<String, Object>()); engineMap.put(engineType, engineConfig); when(config.getAdditionalEngines()).thenReturn(engineMap); StorageEngineFactory factory = new StorageEngineFactory(config); StorageEngine engine = factory.buildStorageEngine(engineType); assertNotNull(engine); assertTrue(engine instanceof TestStorageEngine); verify(config).getAdditionalEngines(); verify(engineConfig).getEngineClass(); verify(engineConfig).getConfiguration(); }