### Question:
GeoGigDataStoreFactory implements DataStoreFactorySpi { @Override public GeoGigDataStore createDataStore(Map<String, Serializable> params) throws IOException { @Nullable final String lookUpClass = (String) RESOLVER_CLASS_NAME.lookUp(params); RepositoryLookup resolver = resolver(lookUpClass); final String repositoryLocation = (String) REPOSITORY.lookUp(params); @Nullable final String defaultNamespace = (String) DEFAULT_NAMESPACE.lookUp(params); @Nullable final String branch = (String) BRANCH.lookUp(params); @Nullable final String head = (String) HEAD.lookUp(params); @Nullable final String effectiveHead = (head == null) ? branch : head; @Nullable final Boolean create = (Boolean) CREATE.lookUp(params); final File repositoryDirectory = resolver.resolve(repositoryLocation); if (create != null && create.booleanValue()) { if (!repositoryDirectory.exists()) { return createNewDataStore(params); } } GeoGIG geogig; try { geogig = new GeoGIG(repositoryDirectory); } catch (RuntimeException e) { throw new IOException(e.getMessage(), e); } Repository repository = geogig.getRepository(); if (null == repository) { if (create != null && create.booleanValue()) { return createNewDataStore(params); } throw new IOException(String.format("Directory is not a geogig repository: '%s'", repositoryDirectory.getAbsolutePath())); } GeoGigDataStore store = new GeoGigDataStore(geogig); if (defaultNamespace != null) { store.setNamespaceURI(defaultNamespace); } if (effectiveHead != null) { store.setHead(effectiveHead); } return store; }  @Override String getDisplayName(); @Override String getDescription(); @Override Param[] getParametersInfo(); @Override boolean canProcess(Map<String, Serializable> params); @Override boolean isAvailable(); @Override Map<Key, ?> getImplementationHints(); @Override GeoGigDataStore createDataStore(Map<String, Serializable> params); @Override GeoGigDataStore createNewDataStore(Map<String, Serializable> params); static final String DISPLAY_NAME; static final Param RESOLVER_CLASS_NAME; static final Param REPOSITORY; static final Param BRANCH; static final Param HEAD; static final Param DEFAULT_NAMESPACE; static final Param CREATE; }### Answer:
@Test public void testCreateDataStoreNonExistentDirectory() { Map<String, Serializable> params; File root = repositoryTempFolder.getRoot(); params = ImmutableMap .of(REPOSITORY.key, (Serializable) (root.getName() + "/shouldntExist")); try { factory.createDataStore(params); fail("Expectd IOE on non existing directory"); } catch (IOException e) { assertTrue(true); } }
@Test public void testCreateDataStoreNotARepositoryDir() { Map<String, Serializable> params; File f = repositoryTempFolder.newFolder("someDir"); params = ImmutableMap.of(REPOSITORY.key, (Serializable) f); try { factory.createDataStore(params); fail("Expectd IOE on non existing repository"); } catch (IOException e) { assertTrue(e.getMessage(), e.getMessage().contains("not a geogig repository")); } }
@Test public void testCreateDataStore() throws IOException { Map<String, Serializable> params; params = ImmutableMap.of(REPOSITORY.key, (Serializable) repoDirectory.getAbsolutePath()); GeoGigDataStore store = factory.createDataStore(params); assertNotNull(store); }