### Question:
PostgresEmbeddedDatabaseController implements EmbeddedDatabaseController { public boolean stopBuiltInDB() throws SigarException, IOException { String dbPidFile = serverHome + "/hqdb/data/postmaster.pid"; log.debug("Checking if HQ built-in database is running using pidfile: " + dbPidFile); long dbPid = processManager.getPidFromPidFile(dbPidFile); if (dbPid == -1) { log.info("HQ built-in database not running"); return true; } log.info("Stopping HQ built-in database..."); if (OperatingSystem.isWin32(osInfo.getName())) { processManager.executeProcess(new String[] { serverHome + "/bin/db-stop.bat" }, serverHome, false, PostgresEmbeddedDatabaseController.DB_PROCESS_TIMEOUT); } else { processManager.executeProcess(new String[] { serverHome + "/bin/db-stop.sh" }, serverHome, false, PostgresEmbeddedDatabaseController.DB_PROCESS_TIMEOUT); } log.info("Triggered stop script for HQ built in database."); return true; } @Autowired  PostgresEmbeddedDatabaseController(
                                              @Value("#{ systemProperties['server.home'] }") String serverHome,
                                              ProcessManager processManager, OperatingSystem osInfo); boolean startBuiltInDB(); boolean stopBuiltInDB(); long getDBPort(); boolean shouldUse();  }### Answer:
@Test public void testStopBuiltInDB() throws Exception { EasyMock.expect(processManager.getPidFromPidFile(serverHome + "/hqdb/data/postmaster.pid")) .andReturn(123l); EasyMock.expect(osInfo.getName()).andReturn("Mac OS X"); EasyMock.expect( processManager.executeProcess(EasyMock.aryEq(new String[] { serverHome + "/bin/db-stop.sh" }), EasyMock.eq(serverHome), EasyMock.eq(false), EasyMock .eq(PostgresEmbeddedDatabaseController.DB_PROCESS_TIMEOUT))).andReturn(0); replay(); boolean dbStopped = embeddedDBController.stopBuiltInDB(); verify(); assertTrue(dbStopped); }
@Test public void testStopDBNotRunning() throws Exception { EasyMock.expect(processManager.getPidFromPidFile(serverHome + "/hqdb/data/postmaster.pid")) .andReturn(-1l); replay(); boolean dbStopped = embeddedDBController.stopBuiltInDB(); verify(); assertTrue(dbStopped); }
@Test public void testStopOnWindows() throws Exception { EasyMock.expect(processManager.getPidFromPidFile(serverHome + "/hqdb/data/postmaster.pid")) .andReturn(1l); EasyMock.expect(osInfo.getName()).andReturn("Win32"); EasyMock.expect( processManager.executeProcess(EasyMock.aryEq(new String[] { serverHome + "/bin/db-stop.bat" }), EasyMock.eq(serverHome), EasyMock.eq(false), EasyMock .eq(PostgresEmbeddedDatabaseController.DB_PROCESS_TIMEOUT))).andReturn(0); replay(); boolean dbStopped = embeddedDBController.stopBuiltInDB(); verify(); assertTrue(dbStopped); }