### Question:
StoreVersionCheck { public Result hasVersion( File neostoreFile, String expectedVersion ) { Optional<String> storeVersion; try { storeVersion = getVersion( neostoreFile ); } catch ( IOException e ) { return new Result( Outcome.missingStoreFile, null, neostoreFile.getName() ); } return storeVersion .map( v -> expectedVersion.equals( v ) ? new Result( Outcome.ok, null, neostoreFile.getName() ) : new Result( Outcome.unexpectedStoreVersion, v, neostoreFile.getName() ) ) .orElseGet( () -> new Result( Outcome.storeVersionNotFound, null, neostoreFile.getName() ) ); } StoreVersionCheck( PageCache pageCache ); Optional<String> getVersion( File neostoreFile ); Result hasVersion( File neostoreFile, String expectedVersion );  }### Answer:
@Test public void shouldFailIfFileDoesNotExist() { File missingFile = new File( directory.directory(), "missing-file" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); StoreVersionCheck.Result result = storeVersionCheck.hasVersion( missingFile, "version" ); assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.missingStoreFile, result.outcome ); assertNull( result.actualVersion ); }
@Test public void shouldReportShortFileDoesNotHaveSpecifiedVersion() throws IOException { File shortFile = fileContaining( fileSystemRule.get(), "nothing interesting" ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCacheRule.getPageCache( fileSystemRule.get() ) ); StoreVersionCheck.Result result = storeVersionCheck.hasVersion( shortFile, "version" ); assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.storeVersionNotFound, result.outcome ); assertNull( result.actualVersion ); }
@Test public void shouldReportFileWithIncorrectVersion() throws IOException { File neoStore = emptyFile( fileSystemRule.get() ); long v1 = MetaDataStore.versionStringToLong( "V1" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1 ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); StoreVersionCheck.Result result = storeVersionCheck.hasVersion( neoStore, "V2" ); assertFalse( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.unexpectedStoreVersion, result.outcome ); assertEquals( "V1", result.actualVersion ); }
@Test public void shouldReportFileWithCorrectVersion() throws IOException { File neoStore = emptyFile( fileSystemRule.get() ); long v1 = MetaDataStore.versionStringToLong( "V1" ); PageCache pageCache = pageCacheRule.getPageCache( fileSystemRule.get() ); MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1 ); StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache ); StoreVersionCheck.Result result = storeVersionCheck.hasVersion( neoStore, "V1" ); assertTrue( result.outcome.isSuccessful() ); assertEquals( StoreVersionCheck.Result.Outcome.ok, result.outcome ); assertNull( result.actualVersion ); }