コード例 #1
0
  @Test
  public void testIfAnyPassItPasses() throws Exception {
    final IProjectAuthorizer failsAuth = context.mock(IProjectAuthorizer.class, "failsAuth");
    final IProjectAuthorizer passesAuth = context.mock(IProjectAuthorizer.class, "passesAuth");

    checking(
        new Expectations() {
          {
            allowing(failsAuth).userIsAuthorizedForProject(USERNAME, PROJECT);
            will(returnValue(null));
            allowing(passesAuth).userIsAuthorizedForProject(USERNAME, PROJECT);
            will(returnValue(AuthorizationLevel.AUTH_LEVEL_READ_ONLY));
          }
        });

    PassIfAnyInCollectionPassAuthorizor auth = new PassIfAnyInCollectionPassAuthorizor();
    ArrayList<IProjectAuthorizer> authList = new ArrayList<IProjectAuthorizer>();
    authList.add(failsAuth);
    authList.add(passesAuth);
    authList.add(failsAuth);
    auth.setProjectAuthorizers(authList);
    assertEquals(
        AuthorizationLevel.AUTH_LEVEL_READ_ONLY,
        auth.userIsAuthorizedForProject(USERNAME, PROJECT));
  }
コード例 #2
0
  @Test
  public void testIfNonePassItFails() throws Exception {
    final IProjectAuthorizer failsAuth = context.mock(IProjectAuthorizer.class, "failsAuth");

    checking(
        new Expectations() {
          {
            allowing(failsAuth).userIsAuthorizedForProject(USERNAME, PROJECT);
            will(returnValue(null));
          }
        });

    PassIfAnyInCollectionPassAuthorizor auth = new PassIfAnyInCollectionPassAuthorizor();
    ArrayList<IProjectAuthorizer> authList = new ArrayList<IProjectAuthorizer>();
    authList.add(failsAuth);
    authList.add(failsAuth);
    auth.setProjectAuthorizers(authList);
    assertNull(auth.userIsAuthorizedForProject(USERNAME, PROJECT));
  }