### Question:
ScopeService { protected List<ApplicationInfo> getClientAppsByScope(String scopeName) { List<ApplicationInfo> scopeApps = new ArrayList<ApplicationInfo>(); List<ApplicationInfo> allApps = DBManagerFactory.getInstance().getAllApplications(); for (ApplicationInfo app : allApps) { if (app.getScope()!=null && app.getScope().contains(scopeName)) { scopeApps.add(app); break; } } return scopeApps; }  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_application_uses_scope_add_it_to_result() throws Exception { String scope = "scope"; List<ApplicationInfo> apps = new ArrayList<ApplicationInfo>(); ApplicationInfo app = mock(ApplicationInfo.class); willReturn("someScope" + " " + scope).given(app).getScope(); apps.add(app); willReturn(apps).given(DBManagerFactory.dbManager).getAllApplications(); List<ApplicationInfo> scopeApps = service.getClientAppsByScope(scope); assertTrue(scopeApps.size() == 1); }
@Test public void when_no_application_uses_scope_return_empty_list() throws Exception { String scope = "scope"; List<ApplicationInfo> apps = new ArrayList<ApplicationInfo>(); ApplicationInfo app = mock(ApplicationInfo.class); willReturn("someScope").given(app).getScope(); apps.add(app); willReturn(apps).given(DBManagerFactory.dbManager).getAllApplications(); List<ApplicationInfo> scopeApps = service.getClientAppsByScope(scope); assertTrue(scopeApps.size() == 0); }