### Question:
JsonCharacterReferenceScanner implements CharacterReferenceScanner { @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; } } JsonCharacterReferenceScanner(CharacterTypes characterTypes, IRepositoryFileResolver repositoryFileResolver); @Override CharacterType getCharacterType(CharacterReference reference); @Override TemplateType getTemplateType(CharacterReference reference); @Override Identifier getCasteType(CharacterReference reference);  }### Answer:
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void closesFileAfterScanning() throws Exception { File testFile = folder.newFile(); FileUtils.writeStringToFile(testFile, "{repositoryId: x, printName: y}"); CharacterTypes types = mock(CharacterTypes.class); when(types.findById(anyString())).thenReturn(new DummyMundaneCharacterType()); IRepositoryFileResolver resolver = prepareResolverToReturnFile(testFile); CharacterReference reference = new CharacterReference(new SimpleRepositoryId("x"), "y"); new JsonCharacterReferenceScanner(types, resolver).getCasteType(reference); testFile.delete(); assertThat(testFile.exists(), is(false)); }