I am writing automated tests for a web app and at one point I need to make sure that a user can only engage in activities allowed by a set permission. I have written all the standalone methods that perform the required tests and now I need to group all of them together and test. I came up with something that looks like this:
public boolean hasPermissions(String permissions, File file) {
if ("Read Only".equals(permissions)) {
return !canCreateNewFolder() && !canAddFiles() && !canAddLink() && canCopyMultipleItems() && !canMoveMultipleItems()
&& !canDeleteMultipleItems() && canDownloadMultipleItems() && canDownload(file) && canViewDetails(file)
&& !canEdit(file) && canCopy(file) && !canMove(file) && !canHide(file) && !canDelete(file);
} else if ("Read and Add Only".equals(permissions)) {
return canCreateNewFolder() && canAddFiles() && canAddLink() && canCopyMultipleItems() && !canMoveMultipleItems()
&& !canDeleteMultipleItems() && canDownloadMultipleItems() && canDownload(file) && canViewDetails(file)
&& !canEdit(file) && canCopy(file) && !canMove(file) && !canHide(file) && !canDelete(file);
} else if ("Full Access".equals(permissions)) {
return canCreateNewFolder() && canAddFiles() && canAddLink() && canCopyMultipleItems() && canMoveMultipleItems()
&& canDeleteMultipleItems() && canDownloadMultipleItems() && canDownload(file) && canViewDetails(file) && canEdit(file)
&& canCopy(file) && canMove(file) && canHide(file) && canDelete(file);
} else {
throw new UnsupportedOperationException("Unsupposrted permission");
}
}
While this solution works with no issues, it somehow doesn't look right.
So just wanted to ask for another opinion on this design.