@Test
  public void testHasPermissionProjectRoleNullUserHasNoPermission() {
    projectManagerMock.expectAndReturn(
        "getProjectObj",
        P.args(
            P.eq(
                new Long(
                    TestProjectShareTypePermissionChecker.PROJECT_ROLE_PERMISSION.getParam1()))),
        TestProjectShareTypePermissionChecker.MOCK_PROJECT);
    final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy();

    final PermissionManager permissionManager = (PermissionManager) permissionManagerMock.proxy();
    final ProjectRoleManager projectRoleManager =
        (ProjectRoleManager) projectRoleManagerMock.proxy();

    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(
            projectManager, permissionManager, projectRoleManager);
    assertFalse(
        checker.hasPermission(null, TestProjectShareTypePermissionChecker.PROJECT_ROLE_PERMISSION));

    projectManagerMock.verify();
    permissionManagerMock.verify();
    projectRoleManagerMock.verify();
  }
  @Test
  public void testHasPermissionProjectUserHasPermission() {
    projectManagerMock.expectAndReturn(
        "getProjectObj",
        P.args(
            P.eq(new Long(TestProjectShareTypePermissionChecker.PROJECT_PERMISSION.getParam1()))),
        TestProjectShareTypePermissionChecker.MOCK_PROJECT);
    final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy();

    permissionManagerMock.expectAndReturn(
        "hasPermission",
        P.args(
            P.eq(Permissions.BROWSE),
            P.eq(TestProjectShareTypePermissionChecker.MOCK_PROJECT),
            P.eq(user)),
        Boolean.TRUE);
    final PermissionManager permissionManager = (PermissionManager) permissionManagerMock.proxy();

    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(projectManager, permissionManager, null);
    assertTrue(
        checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_PERMISSION));

    projectManagerMock.verify();
    permissionManagerMock.verify();
  }
  @Test
  public void testHasPermissionNullPermission() {
    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(null, null, null);

    try {
      checker.hasPermission(user, null);
      fail("permission can not be null");
    } catch (final IllegalArgumentException e) {
      // expected
    }
  }
  @Test
  public void testHasPermissionInvalidPermission() {
    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(null, null, null);

    try {
      checker.hasPermission(user, TestProjectShareTypePermissionChecker.INVALID_PERM);
      fail("permission must be of type: " + ProjectShareType.TYPE);
    } catch (final IllegalArgumentException e) {
      // expected
    }
  }
  @Test
  public void testHasPermissionWithNullParam1() {
    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(null, null, null);

    try {
      final SharePermission perm = new SharePermissionImpl(ProjectShareType.TYPE, null, null);
      checker.hasPermission(user, perm);
      fail("permission.param1 can not be null");
    } catch (final IllegalArgumentException e) {
      // expected
    }
  }
  @Test
  public void testHasPermissionNoProject() {
    projectManagerMock.expectAndReturn(
        "getProjectObj",
        P.args(
            P.eq(new Long(TestProjectShareTypePermissionChecker.PROJECT_PERMISSION.getParam1()))),
        null);
    final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy();

    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(projectManager, null, null);
    assertFalse(
        checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_PERMISSION));

    projectManagerMock.verify();
  }