JsonHeroReferenceScanner implements HeroReferenceScanner { @Override public Identifier getCasteType(CharacterReference reference) { if (castesByFile.containsKey(reference)) { return castesByFile.get(reference); } try { scan(reference); return castesByFile.get(reference); } catch (IOException e) { return NULL_CASTE_TYPE; } } JsonHeroReferenceScanner(HeroTypes heroTypes, IRepositoryFileResolver repositoryFileResolver); @Override HeroType getCharacterType(CharacterReference reference); @Override SplatType getTemplateType(CharacterReference reference); @Override Identifier getCasteType(CharacterReference reference);  }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void closesFileAfterScanning() throws Exception { File testFile = folder.newFile(); InputOutput.writeStringToFile(testFile, "{repositoryId: x, printName: y}"); HeroTypes types = mock(HeroTypes.class); when(types.findById(anyString())).thenReturn(new DummyMundaneHeroType()); IRepositoryFileResolver resolver = prepareResolverToReturnFile(testFile); CharacterReference reference = new CharacterReference(new SimpleRepositoryId("x"), "y"); new JsonHeroReferenceScanner(types, resolver).getCasteType(reference); testFile.delete(); assertThat(testFile.exists(), is(false)); }