### Question:
ScopeService { public String getValidScope(String scope, String clientId) { ClientCredentials creds = DBManagerFactory.getInstance().findClientCredentials(clientId); if(creds == null) { return null; } return getValidScopeByScope(scope, creds.getScope()); }  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_scope_is_null_get_client_app_scope() throws Exception { String clientId = "826064099791766"; MockDBManagerFactory.install(); ClientCredentials creds = mock(ClientCredentials.class); willReturn("basic").given(creds).getScope(); willReturn(creds).given(DBManagerFactory.getInstance()).findClientCredentials(clientId); String scope = service.getValidScope(null, clientId); assertEquals(scope, "basic"); }
@Test public void when_scope_is_valid_check_client_app_scope_contains_it() throws Exception { String clientId = "826064099791766"; MockDBManagerFactory.install(); ClientCredentials creds = mock(ClientCredentials.class); willReturn("extended basic").given(creds).getScope(); willReturn(creds).given(DBManagerFactory.getInstance()).findClientCredentials(clientId); String scope = service.getValidScope("basic", clientId); assertEquals(scope, "basic"); }
@Test public void when_scope_is_not_contained_in_client_app_scope_return_null() throws Exception { String clientId = "826064099791766"; MockDBManagerFactory.install(); ClientCredentials creds = mock(ClientCredentials.class); willReturn("basic").given(creds).getScope(); willReturn(creds).given(DBManagerFactory.getInstance()).findClientCredentials(clientId); String scope = service.getValidScope("extended", clientId); assertNull(scope); }