### Question:
OfficeServerScriptService implements ScriptService { public boolean stopServer() { if (!isMainXWiki()) { setErrorMessage(ERROR_FORBIDDEN); } else if (!this.docBridge.hasProgrammingRights()) { setErrorMessage(ERROR_PRIVILEGES); } else { try { this.officeServer.stop(); return true; } catch (OfficeServerException ex) { logger.error(ex.getMessage(), ex); setErrorMessage(ex.getMessage()); } } return false; }  boolean startServer(); boolean stopServer(); @Unstable boolean isConnected(); @Unstable String displayServerState(); @Deprecated String getServerState(); OfficeServerConfiguration getConfig(); String getLastErrorMessage(); static final String OFFICE_MANAGER_ERROR; }### Answer:
@Test public void stopServer() throws OfficeServerException { when(this.modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("xwiki")); when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true); assertTrue(this.officeServerScriptService.stopServer()); verify(this.officeServer).stop(); }
@Test public void stopServerForbidden() throws OfficeServerException { when(this.modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("subwiki")); when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true); assertFalse(this.officeServerScriptService.stopServer()); verify(this.officeServer, never()).stop(); verify(this.executionContext).setProperty(OfficeServerScriptService.OFFICE_MANAGER_ERROR, ERROR_FORBIDDEN); }
@Test public void stopServerPrivileges() throws OfficeServerException { when(this.modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("xwiki")); when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(false); assertFalse(this.officeServerScriptService.stopServer()); verify(this.officeServer, never()).stop(); verify(this.executionContext).setProperty(OfficeServerScriptService.OFFICE_MANAGER_ERROR, ERROR_PRIVILEGES); }
@Test public void stopServerError() throws OfficeServerException { when(this.modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("xwiki")); when(this.documentAccessBridge.hasProgrammingRights()).thenReturn(true); doThrow(new OfficeServerException("Error while stopping")).when(this.officeServer).stop(); assertFalse(this.officeServerScriptService.stopServer()); verify(this.officeServer).stop(); verify(this.executionContext).setProperty(OfficeServerScriptService.OFFICE_MANAGER_ERROR, "Error while stopping"); assertEquals("Error while stopping", logCapture.getMessage(0)); }