### Question:
FileSystemCallbackHandlerDao implements CallbackHandlerDao { @Override public void upsert(PersistentFileHandler handlerCallback) { removeWithUUID(handlerCallback.getHandler().getUUID()); final String fileName = fileName(handlerCallback.getHandler().getId()); final String absolutePath = getAbsolutePath(fileName); saveToFile(handlerCallback, fileName, absolutePath); }  @Override void upsert(PersistentFileHandler handlerCallback); @Override List<PersistentFileHandler> findAll(); @Override void remove(String handlerId);  }### Answer:
@Test public void upsert() throws IOException { final String handlersFolders = getHandlersFolder(); when(configuration.getHandlerDirectory()).thenReturn(handlersFolders); when(mapper.writeValueAsBytes(any())).thenReturn("{'test': 'test'}".getBytes()); final PersistentFileHandler persistentFileHandler = new PersistentFileHandler(new LibListCallbackHandler(null, DockerAction.LIB_LIST, "uuid", "test", "das"), 1L, "/opt/test"); fileSystemCallbackHandlerDao.upsert(persistentFileHandler); verify(configuration, times(2)).getHandlerDirectory(); verify(mapper).writeValueAsBytes(refEq(persistentFileHandler)); assertTrue(new File(handlersFolders + File.separator + "LibListCallbackHandler_uuid.json").exists()); verifyNoMoreInteractions(mapper, configuration, dao); }
@Test public void upsertTwoSimilarHandlers() throws IOException { final String handlersFolders = getHandlersFolder(); when(configuration.getHandlerDirectory()).thenReturn(handlersFolders); when(mapper.writeValueAsBytes(any())).thenReturn("{'test': 'test'}".getBytes()); final PersistentFileHandler persistentFileHandler1 = new PersistentFileHandler(new DockerWarmuper() .new DockerFileHandlerCallback("sameUUID"), 1L, "/opt/test"); final PersistentFileHandler persistentFileHandler2 = new PersistentFileHandler(new LibListCallbackHandler(null, DockerAction.LIB_LIST, "sameUUID", "test", "das1"), 1L, "/opt/test"); final PersistentFileHandler persistentFileHandler3 = new PersistentFileHandler(new LibListCallbackHandler(null, DockerAction.LIB_LIST, "anotherUUID", "test", "das2"), 1L, "/opt/test"); fileSystemCallbackHandlerDao.upsert(persistentFileHandler1); fileSystemCallbackHandlerDao.upsert(persistentFileHandler2); fileSystemCallbackHandlerDao.upsert(persistentFileHandler3); verify(configuration, times(6)).getHandlerDirectory(); verify(mapper).writeValueAsBytes(refEq(persistentFileHandler1)); verify(mapper).writeValueAsBytes(refEq(persistentFileHandler2)); verify(mapper).writeValueAsBytes(refEq(persistentFileHandler3)); assertTrue(new File(handlersFolders + File.separator + "LibListCallbackHandler_sameUUID.json").exists()); assertTrue(new File(handlersFolders + File.separator + "LibListCallbackHandler_anotherUUID.json").exists()); assertFalse(new File(handlersFolders + File.separator + "DockerFileHandlerCallback_sameUUID.json").exists()); verifyNoMoreInteractions(mapper, configuration, dao); }