### Question:
ScopeService { public String deleteScope(String scopeName) throws OAuthException { String responseMsg = ""; Scope foundScope = DBManagerFactory.getInstance().findScope(scopeName); if (foundScope == null) { log.error("scope does not exist"); throw new OAuthException(SCOPE_NOT_EXIST, HttpResponseStatus.BAD_REQUEST); } else { List<ApplicationInfo> registeredApps = getClientAppsByScope(scopeName); if (registeredApps.size() > 0) { responseMsg = SCOPE_USED_BY_APP_MESSAGE; } else { boolean ok = DBManagerFactory.getInstance().deleteScope(scopeName); if (ok) { responseMsg = SCOPE_DELETED_OK_MESSAGE; } else { responseMsg = SCOPE_DELETED_NOK_MESSAGE; } } } return responseMsg; }  String registerScope(HttpRequest req); String getScopes(HttpRequest req); String getValidScope(String scope, String clientId); String getValidScopeByScope(String scope, String storedScope); boolean scopeAllowed(String scope, String allowedScopes); int getExpiresIn(String tokenGrantType, String scope); String updateScope(HttpRequest req, String scopeName); String deleteScope(String scopeName); String getScopeByName(String scopeName);  }### Answer:
@Test public void when_db_delete_scope_return_false_return_delete_NOK_message() throws Exception { String scope = "scope"; willReturn(mock(Scope.class)).given(DBManagerFactory.dbManager).findScope(scope); willReturn(false).given(DBManagerFactory.dbManager).deleteScope(scope); String message = service.deleteScope(scope); assertEquals(message, ScopeService.SCOPE_DELETED_NOK_MESSAGE); }
@Test public void when_db_delete_scope_return_true_return_delete_OK_message() throws Exception { String scope = "scope"; willReturn(mock(Scope.class)).given(DBManagerFactory.dbManager).findScope(scope); willReturn(true).given(DBManagerFactory.dbManager).deleteScope(scope); String message = service.deleteScope(scope); assertEquals(message, ScopeService.SCOPE_DELETED_OK_MESSAGE); }
@Test public void when_scope_not_found_throw_exception() throws Exception { String scope = "scope"; willReturn(null).given(DBManagerFactory.dbManager).findScope(scope); OAuthException exception = null; try { service.deleteScope(scope); } catch(OAuthException e) { exception = e; } assertEquals(exception.getHttpStatus(), HttpResponseStatus.BAD_REQUEST); assertEquals(exception.getMessage(), ScopeService.SCOPE_NOT_EXIST); }