FileDbProvider implements SchematicDbProvider<FileDb> { @Override public FileDb getDB( String type, Document configuration ) { if (TYPE_MEM.equalsIgnoreCase(type)) { LOGGER.debug("Returning new in-memory schematic DB..."); return FileDb.inMemory(configuration.getBoolean(COMPRESS_FIELD, false)); } else if (TYPE_FILE.equalsIgnoreCase(type)) { boolean compress = configuration.getBoolean(COMPRESS_FIELD, true); String path = configuration.getString(PATH_FIELD, null); LOGGER.debug("Returning new disk schematic DB at {0}...", path); return FileDb.onDisk(compress, path); } return null; }  @Override FileDb getDB( String type, Document configuration ); static final String TYPE_MEM; static final String TYPE_FILE; static final String PATH_FIELD; static final String COMPRESS_FIELD; }
@Test public void shouldReturnDBBasedOnType() { Assert.assertNotNull(provider.getDB(FileDbProvider.TYPE_MEM, new BasicDocument())); Assert.assertNotNull(provider.getDB(FileDbProvider.TYPE_FILE, new BasicDocument(FileDbProvider.PATH_FIELD, "path"))); }
@Test(expected = NullPointerException.class) public void shouldFailIfPathNotProvided() throws Exception { provider.getDB(FileDbProvider.TYPE_FILE, new BasicDocument()); }