Skip to content

Commit

Permalink
i_900 fix junit for testing problem visibility by group
Browse files Browse the repository at this point in the history
Fix ambiguity with using 'null' as argument to Problem.canView(obj).
Add unit tests for test testing problem visibility for a List<> of groups.
  • Loading branch information
johnbrvc committed Jan 10, 2024
1 parent 58902ac commit a360c33
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Binary file modified projects/EWTeam/lib/pc2.jar
Binary file not shown.
Binary file modified projects/WTI-API/WebContent/WEB-INF/lib/pc2.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions src/edu/csus/ecs/pc2/core/model/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ public void addGroup(Group group){
*/
public boolean canView (Group group){
boolean view = (groups.size() == 0);
if (group != null) {
if (!view && group != null) {
for (Iterator<Group> iterator = groups.iterator(); iterator.hasNext();) {
Group g2 = iterator.next();
if (group.getDisplayName().equals(g2.getDisplayName())) {
Expand All @@ -1965,7 +1965,9 @@ public boolean canView (Group group){
* @return true if any group can see the problem, false otherwise
*/
public boolean canView(List<Group> wantedGroups) {
boolean view = (wantedGroups == null);
// If no specific groups are assigned to this problem or we're not interested
// in specific groups, then the problem is viewable.
boolean view = (groups.size() == 0 || wantedGroups == null);

if(!view) {
for(Group group : wantedGroups) {
Expand Down
13 changes: 12 additions & 1 deletion test/edu/csus/ecs/pc2/core/model/ProblemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package edu.csus.ecs.pc2.core.model;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import edu.csus.ecs.pc2.core.Constants;
import edu.csus.ecs.pc2.core.model.Problem.VALIDATOR_TYPE;
Expand Down Expand Up @@ -323,11 +325,20 @@ public void testAddGroup() throws Exception {

Group group1 = groups[0];

ArrayList<Group> arrayOfGroup1 = new ArrayList<Group>();
arrayOfGroup1.add(group1);
ArrayList<Group> arrayOfGroup2 = new ArrayList<Group>();
arrayOfGroup2.add(groups[1]);

assertTrue (lastProblem.isAllView());
lastProblem.addGroup(group1);

assertTrue (lastProblem.canView(group1));
assertFalse (lastProblem.canView(null));
assertFalse (lastProblem.canView((Group)null));
// a null wanted group list means "any group"
assertTrue (lastProblem.canView((List<Group>)null));
assertTrue (lastProblem.canView(arrayOfGroup1));
assertFalse (lastProblem.canView(arrayOfGroup2));
assertFalse (lastProblem.canView(groups[1]));

lastProblem.clearGroups();
Expand Down

0 comments on commit a360c33

Please sign in to comment.