forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from avrilmohh/mark-assignment-tests
Create test cases for MarkAssignmentCommand
- Loading branch information
Showing
4 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/java/seedu/address/logic/commands/MarkAssignmentCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ASSIGNMENT; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_STUDENT; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.model.AddressBook; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.assignment.Assignment; | ||
import seedu.address.model.student.Student; | ||
import seedu.address.testutil.AssignmentBuilder; | ||
import seedu.address.testutil.StudentBuilder; | ||
|
||
|
||
public class MarkAssignmentCommandTest { | ||
|
||
private Model model = new ModelManager(new AddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_validStudentAndAssignmentIndex_markSuccessful() { | ||
Assignment assignment = new AssignmentBuilder() | ||
.withAssignmentName("Math Homework") | ||
.withMaxScore(100) | ||
.build(); | ||
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment); | ||
model.addStudent(student); | ||
MarkAssignmentCommand markAssignmentCommand = new MarkAssignmentCommand( | ||
INDEX_FIRST_STUDENT, INDEX_FIRST_ASSIGNMENT); | ||
String expectedMessage = String.format(MarkAssignmentCommand.MESSAGE_MARK_SUCCESS, | ||
"Math Homework", student.getName()); | ||
Model expectedModel = new ModelManager(new AddressBook(), model.getUserPrefs()); | ||
Assignment expectedAssignment = new AssignmentBuilder() | ||
.withAssignmentName("Math Homework") | ||
.withMaxScore(100) | ||
.withHasSubmitted(true) | ||
.build(); | ||
Student expectedStudent = new StudentBuilder().withAssignments(new ArrayList<>()).build() | ||
.addAssignment(expectedAssignment); | ||
expectedModel.addStudent(expectedStudent); | ||
assertCommandSuccess(markAssignmentCommand, model, expectedMessage, expectedModel); | ||
assertTrue(student.getAssignmentList().get(INDEX_FIRST_ASSIGNMENT.getZeroBased()).getHasSubmitted()); | ||
} | ||
|
||
@Test | ||
public void execute_invalidStudentIndex_markFailure() { | ||
Assignment assignment = new AssignmentBuilder() | ||
.withAssignmentName("Math Homework") | ||
.withMaxScore(100) | ||
.build(); | ||
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment); | ||
model.addStudent(student); | ||
MarkAssignmentCommand markAssignmentCommand = new MarkAssignmentCommand( | ||
Index.fromOneBased(2), | ||
INDEX_FIRST_ASSIGNMENT); | ||
String expectedMessage = Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX; | ||
assertCommandFailure(markAssignmentCommand, model, expectedMessage); | ||
} | ||
|
||
@Test | ||
public void execute_invalidAssignmentIndex_markFailure() { | ||
Assignment assignment = new AssignmentBuilder() | ||
.withAssignmentName("Math Homework") | ||
.withMaxScore(100) | ||
.build(); | ||
Student student = new StudentBuilder().withAssignments(new ArrayList<>()).build().addAssignment(assignment); | ||
model.addStudent(student); | ||
MarkAssignmentCommand markAssignmentCommand = new MarkAssignmentCommand( | ||
INDEX_FIRST_STUDENT, | ||
Index.fromOneBased(2)); | ||
String expectedMessage = Messages.MESSAGE_INVALID_ASSIGNMENT_INDEX; | ||
assertCommandFailure(markAssignmentCommand, model, expectedMessage); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/test/java/seedu/address/testutil/AssignmentBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package seedu.address.testutil; | ||
|
||
import seedu.address.model.assignment.Assignment; | ||
import seedu.address.model.assignment.AssignmentName; | ||
import seedu.address.model.student.Student; | ||
|
||
/** | ||
* A utility class to help build Assignment objects for testing purposes. | ||
*/ | ||
public class AssignmentBuilder { | ||
|
||
public static final Student DEFAULT_STUDENT = new StudentBuilder().build(); | ||
public static final String DEFAULT_ASSIGNMENT_NAME = "Math Homework"; | ||
public static final int DEFAULT_MAX_SCORE = 100; | ||
public static final int DEFAULT_SCORE = 0; | ||
public static final boolean DEFAULT_SUBMISSION_STATUS = false; | ||
|
||
private Student student; | ||
private AssignmentName assignmentName; | ||
private int maxScore; | ||
private int score; | ||
private boolean hasSubmitted; | ||
|
||
/** | ||
* Creates an AssignmentBuilder with default values for the Assignment. | ||
*/ | ||
public AssignmentBuilder() { | ||
student = DEFAULT_STUDENT; | ||
assignmentName = new AssignmentName(DEFAULT_ASSIGNMENT_NAME); | ||
maxScore = DEFAULT_MAX_SCORE; | ||
score = DEFAULT_SCORE; | ||
hasSubmitted = DEFAULT_SUBMISSION_STATUS; | ||
} | ||
|
||
/** | ||
* Creates an AssignmentBuilder with values copied from the specified Assignment. | ||
* | ||
* @param assignmentToCopy the Assignment to copy values from | ||
*/ | ||
public AssignmentBuilder(Assignment assignmentToCopy) { | ||
student = assignmentToCopy.getStudent(); | ||
assignmentName = new AssignmentName(assignmentToCopy.getName()); | ||
maxScore = assignmentToCopy.getMaxScore(); | ||
score = assignmentToCopy.getScore(); | ||
hasSubmitted = assignmentToCopy.getHasSubmitted(); | ||
} | ||
|
||
/** | ||
* Sets the {@code student} of the {@code Assignment} that we are building. | ||
*/ | ||
public AssignmentBuilder withStudent(Student student) { | ||
this.student = student; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the {@code AssignmentName} of the {@code Assignment} that we are building. | ||
*/ | ||
public AssignmentBuilder withAssignmentName(String assignmentName) { | ||
this.assignmentName = new AssignmentName(assignmentName); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the {@code maxScore} of the {@code Assignment} that we are building. | ||
*/ | ||
public AssignmentBuilder withMaxScore(int maxScore) { | ||
this.maxScore = maxScore; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the {@code score} of the {@code Assignment} that we are building. | ||
*/ | ||
public AssignmentBuilder withScore(int score) { | ||
this.score = score; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the {@code hasSubmitted} status of the {@code Assignment} that we are building. | ||
*/ | ||
public AssignmentBuilder withHasSubmitted(boolean hasSubmitted) { | ||
this.hasSubmitted = hasSubmitted; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds and returns an {@code Assignment}. | ||
*/ | ||
public Assignment build() { | ||
Assignment assignment = new Assignment(student, assignmentName, maxScore); | ||
assignment.setScore(this.score); | ||
assignment.setHasSubmitted(this.hasSubmitted); | ||
return assignment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters