### Question:
WikiDeletedListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { String wikiId = ((WikiDeletedEvent) event).getWikiId(); File directory = this.store.getWikiDir(wikiId); if (directory.exists() && directory.isDirectory()) { try { FileUtils.deleteDirectory(directory); } catch (IOException e) { this.logger.error("Failed to delete storage for the wiki [{}]", wikiId, e); } } } WikiDeletedListener(); @Override void onEvent(Event event, Object source, Object data); static final String NAME; }### Answer:
@Test public void onEvent() throws IOException { WikiDeletedEvent wikiDeletedEvent = mock(WikiDeletedEvent.class); String wikiId = "foo"; when(wikiDeletedEvent.getWikiId()).thenReturn(wikiId); File fooWikiTestDir = Files.createTempDirectory("fooWikiTestDir").toFile(); when(filesystemStoreTools.getWikiDir(wikiId)).thenReturn(fooWikiTestDir); assertTrue(fooWikiTestDir.exists()); wikiDeletedListener.onEvent(wikiDeletedEvent, null, null); assertFalse(fooWikiTestDir.exists()); File barWikiTestFile = Files.createTempFile("wikitest", "tempfile").toFile(); when(filesystemStoreTools.getWikiDir(wikiId)).thenReturn(barWikiTestFile); assertTrue(barWikiTestFile.exists()); wikiDeletedListener.onEvent(wikiDeletedEvent, null, null); assertTrue(barWikiTestFile.exists()); }