### Question:
BufferMgr { public void saveAs(BufferFile outFile, boolean associateWithNewFile, TaskMonitor monitor) throws IOException, CancelledException { synchronized (snapshotLock) { synchronized (this) { if (corruptedState) { throw new IOException("Corrupted BufferMgr state"); } if (outFile.getIndexCount() != 0) { throw new IllegalArgumentException("Empty buffer file must be provided"); } if (lockCount != 0) { throw new IOException("Attempted saveAs while buffers are locked"); } if (monitor == null) { monitor = TaskMonitorAdapter.DUMMY_MONITOR; } int indexCnt = indexProvider.getIndexCount(); monitor.initialize(indexCnt); boolean success = false; try { doSave(outFile, monitor); monitor.setCancelEnabled(false); monitor.setMessage("Completing file save..."); outFile.setReadOnly(); success = true; } finally { if (!success) { outFile.delete(); } monitor.setCancelEnabled(true); } if (associateWithNewFile) { setSourceFile(outFile); } } } } BufferMgr();  BufferMgr(int requestedBufferSize, long approxCacheSize, int maxUndos);  BufferMgr(BufferFile sourceFile);  BufferMgr(BufferFile sourceFile, long approxCacheSize, int maxUndos); private  BufferMgr(BufferFile sourceFile, int requestedbufferSize, long approxCacheSize,
			int maxUndos); void enablePreCache(); void setCorruptedState(); boolean isCorrupted(); synchronized int getLockCount(); int getBufferSize(); BufferFile getSourceFile(); void dispose(); void dispose(boolean keepRecoveryData); void setMaxUndos(int maxUndos); void clearCheckpoints(); int getMaxUndos(); synchronized DataBuffer getBuffer(int id); DataBuffer createBuffer(); void releaseBuffer(DataBuffer buf); void deleteBuffer(int id); boolean atCheckpoint(); boolean checkpoint(); synchronized boolean isChanged(); boolean hasUndoCheckpoints(); boolean hasRedoCheckpoints(); int getAvailableUndoCount(); int getAvailableRedoCount(); boolean undo(boolean redoable); boolean redo(); boolean canSave(); synchronized boolean modifiedSinceSnapshot(); boolean takeRecoverySnapshot(DBChangeSet changeSet, TaskMonitor monitor); LocalBufferFile getRecoveryChangeSetFile(); void clearRecoveryFiles(); boolean recover(TaskMonitor monitor); static boolean canRecover(BufferFileManager bfMgr); void save(String comment, DBChangeSet changeSet, TaskMonitor monitor); void saveAs(BufferFile outFile, boolean associateWithNewFile, TaskMonitor monitor); long getCacheHits(); long getCacheMisses(); int getLowBufferCount(); void resetCacheStatistics(); String getStatusInfo(); int getAllocatedBufferCount(); int getFreeBufferCount(); static void cleanupOldCacheFiles(); static final String ALWAYS_PRECACHE_PROPERTY; static final int DEFAULT_BUFFER_SIZE; static final int DEFAULT_CHECKPOINT_COUNT; static final int DEFAULT_CACHE_SIZE; }### Answer:
@Test public void testSaveAs() throws Exception { initNewFile(); assertTrue(!mgr.isChanged()); DataBuffer buf = mgr.createBuffer(); int id = buf.getId(); buf.put(0, fillPattern1); mgr.releaseBuffer(buf); assertTrue(mgr.isChanged()); File f = new File(testDir, "test.bf"); LocalBufferFile bf = new LocalBufferFile(f, bufferSize); mgr.saveAs(bf, true, null); assertTrue(!mgr.isChanged()); mgr.dispose(); bf = new LocalBufferFile(f, true); mgr = new BufferMgr(bf); buf = mgr.getBuffer(id); assertTrue(Arrays.equals(fillPattern1, buf.get(0, fillPattern1.length))); mgr.releaseBuffer(buf); }