Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for remaining Teammate associated classes #283

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
086d625
Add test for AddTeammateParticipationCommandTest
Nov 5, 2020
9c6b950
Add test for AddTeammateParticipationCommand Parser Test
Nov 5, 2020
c0280f5
Add test for DeleteTeammateParticipationCommand and parser
Nov 5, 2020
ca8cbbb
Add tests for DeleteTeammateCommandTest
Nov 5, 2020
fd762d7
Save changes to checkout master
Nov 5, 2020
5d5afc0
Merge branch 'master' into tests-regarding-teammates-branch
Nov 5, 2020
8ff0f88
Add testcases for EditTeammateCommandTest
Nov 5, 2020
160b6ba
Add half of the testcases for EditTeammateCommandParser
Nov 5, 2020
25516b9
Add rest of the testcases for EditTeammateCommandParser
Nov 6, 2020
5fa8a2b
Fix checkstyle
Nov 6, 2020
d0ecce5
Fix checkstyle again
Nov 6, 2020
f0813ef
Fix error in testcase, only shows up on github
Nov 6, 2020
ee68f18
Fix error in testcase, only shows up on github, attempt 2
Nov 6, 2020
542684e
Fix checkstyle
Nov 6, 2020
e12ea1d
Fix github tests, attempt #3
Nov 6, 2020
67cdf15
Fix checkstyle
Nov 6, 2020
d041654
Fix github tests, attempt #4
Nov 6, 2020
899ac6b
Fix github tests, attempt #5
Nov 6, 2020
49c0a0e
Fix github tests, attempt #6
Nov 6, 2020
7b39265
Fix github tests, attempt #7
Nov 6, 2020
6ab4557
Fix checkstyle
Nov 6, 2020
14db564
Fix github tests, attempt #8
Nov 6, 2020
0c316a0
Fix github tests, attempt #9
Nov 6, 2020
98fd8d1
Fix github tests, attempt #10
Nov 6, 2020
c53e454
Fix github tests, attempt #10
Nov 6, 2020
9f59c5b
Fix github tests, attempt #12
Nov 6, 2020
81b4e2a
Fix checkstyle
Nov 6, 2020
bf66bc1
Merge branch 'master' into tests-regarding-teammates-branch
Nov 6, 2020
0d24f7f
Fix github tests, attempt #13
Nov 6, 2020
97ed72e
Merge branch 'master' into tests-regarding-teammates-branch
Nov 6, 2020
ddde04d
Merge remote-tracking branch 'origin/tests-regarding-teammates-branch…
Nov 6, 2020
a4db538
Fix github tests, attempt #14
Nov 6, 2020
1a0eff1
Fix github tests, attempt #15
Nov 6, 2020
baa0d97
Fix github tests, attempt #16
Nov 6, 2020
db08c82
Fix github tests, attempt #17
Nov 6, 2020
8fca42d
Fix checkstyle
Nov 6, 2020
1a092fd
Fix github tests, attempt #18
Nov 6, 2020
6e3c4c8
Fix checkstyle
Nov 6, 2020
402ebd1
Fix github tests, attempt #19
Nov 6, 2020
09e5da2
Fix github tests, attempt #20
Nov 6, 2020
93150c4
Fix github tests, attempt #20
Nov 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.address.commons.core.index;


import seedu.address.model.person.GitUserName;

/**
Expand Down Expand Up @@ -34,6 +33,7 @@ public String getGitUserName() {
* @return boolean to indicate validity of gitusername
*/
public boolean isValidGitUserIndex(String gitUserName) {
assert (gitUserName != null);
String trimmedGitUserName = gitUserName.trim();
return GitUserName.isValidGitUserName(trimmedGitUserName);
}
Expand All @@ -44,5 +44,4 @@ public boolean equals(Object other) {
|| (other instanceof GitUserIndex // instanceof handles nulls
&& uniqueGitUserIndex.equals(((GitUserIndex) other).uniqueGitUserIndex)); // state check
}

}
1 change: 0 additions & 1 deletion src/main/java/seedu/address/commons/core/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ private Index(int zeroBasedIndex) {
if (zeroBasedIndex < 0) {
throw new IndexOutOfBoundsException();
}

this.zeroBasedIndex = zeroBasedIndex;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.address.logic.commands.project;

import static java.util.Objects.isNull;
import static java.util.Objects.requireNonNull;

import java.util.logging.Level;
Expand All @@ -9,7 +8,6 @@
import seedu.address.commons.core.index.GitUserIndex;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.project.Project;
Expand All @@ -21,25 +19,20 @@ public class AddTeammateParticipationCommand extends Command {

public static final String COMMAND_WORD = "addpart";
public static final String MESSAGE_ADD_TEAMMATE_PARTICIPATION_SUCCESS = "New Teammate added: %1$s";
public static final String MESSAGE_TEAMMATE_NOT_FOUND = "Teammate not found";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds teammate to this project"
+ "Parameters: Git UserName (must be a single word)\n "
+ "Example: " + COMMAND_WORD + " LucasTai98 ";

private static final Logger logger = Logger.getLogger("AddTeammateParticipationCommandLogger");
private final Person toAdd;
private final GitUserIndex gitUserIndex;

/**
* Creates an new teammate that is associated with the project
* Adds an existing teammate to a project,
*/
public AddTeammateParticipationCommand(GitUserIndex index) throws ParseException {
public AddTeammateParticipationCommand(GitUserIndex index) {
requireNonNull(index);
toAdd = Person.getPersonFromList(index);
if (isNull(toAdd)) {
logger.log(Level.INFO, "Teammate gitusername incorrect");
throw new ParseException(MESSAGE_TEAMMATE_NOT_FOUND);
}
gitUserIndex = index;
}

/**
Expand All @@ -52,6 +45,7 @@ public AddTeammateParticipationCommand(GitUserIndex index) throws ParseException
public CommandResult execute(Model model) {
requireNonNull(model);
Project project = model.getProjectToBeDisplayedOnDashboard().get();
Person toAdd = Person.getPersonFromList(gitUserIndex);
toAdd.addProject(project);
project.addParticipation(toAdd);
model.addParticipation(project.getParticipation(toAdd.getGitUserNameString()));
Expand All @@ -60,4 +54,10 @@ public CommandResult execute(Model model) {
toAdd.getGitUserNameString()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddTeammateParticipationCommand) // instanceof handles nulls
&& gitUserIndex.equals(((AddTeammateParticipationCommand) other).gitUserIndex); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ public CommandResult execute(Model model) throws CommandException {
return new CommandResult(String.format(MESSAGE_DELETE_TEAMMATE_PARTICIPATION_SUCCESS,
personToDeleteParticipation));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteTeammateParticipationCommand) // instanceof handles nulls
&& gitUserIndex.equals(((DeleteTeammateParticipationCommand) other).gitUserIndex); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public EditTeammateDescriptor() {}
*/
public EditTeammateDescriptor(EditTeammateDescriptor toCopy) {
setTeammateName(toCopy.name);
setGitUserName(toCopy.gitUserName);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.address.logic.commands.project.AddTeammateParticipationCommand;
import seedu.address.logic.parser.exceptions.ParseException;

public class AddTeammateParticipationParser implements Parser<AddTeammateParticipationCommand> {
public class AddTeammateParticipationCommandParser implements Parser<AddTeammateParticipationCommand> {


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.address.logic.commands.project.DeleteTeammateParticipationCommand;
import seedu.address.logic.parser.exceptions.ParseException;

public class DeleteTeammateParticipationParser implements Parser<DeleteTeammateParticipationCommand> {
public class DeleteTeammateParticipationCommandParser implements Parser<DeleteTeammateParticipationCommand> {

/**
* Parses {@code userInput} into a command and returns it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ public Command parseCommand(String userInput, Status status) throws ParseExcepti

case AddTeammateParticipationCommand.COMMAND_WORD:
if (status != Status.PROJECT_LIST) {
return new AddTeammateParticipationParser().parse(arguments);
return new AddTeammateParticipationCommandParser().parse(arguments);
} else {
throw new InvalidScopeException(Status.PROJECT, status);
}

case DeleteTeammateParticipationCommand.COMMAND_WORD:
if (status != Status.PROJECT_LIST) {
return new DeleteTeammateParticipationParser().parse(arguments);
return new DeleteTeammateParticipationCommandParser().parse(arguments);
} else {
throw new InvalidScopeException(Status.PROJECT, status);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ public boolean equals(Object obj) {

// state check
ModelManager other = (ModelManager) obj;
return mainCatalogue.equals(other.mainCatalogue)
&& userPrefs.equals(other.userPrefs)
&& filteredProjects.equals(other.filteredProjects);
return userPrefs.equals(other.userPrefs)
&& filteredProjects.equals(other.filteredProjects);
//&& filteredTasks.equals(other.filteredTasks)
//&& filteredTeammates.equals(other.filteredTeammates);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ private CommandResult executeCommand(String commandText) throws CommandException
try {
CommandResult commandResult = logic.execute(commandText);
logger.info("Result: " + commandResult.getFeedbackToUser());
resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser());
fillInnerParts();
resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser());

if (commandResult.isShowHelp()) {
handleHelp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class TeammateTestUtil {
public static final String VALID_TEAMMATE_GIT_USERNAME_A = "Sparrow32";
public static final String VALID_TEAMMATE_GIT_USERNAME_B = "Tatey";
public static final String VALID_TEAMMATE_GIT_USERNAME_C = "Modi";
public static final String INVALID_TEAMMATE_GIT_USERNAME = "$";

public static final String VALID_TEAMMATE_PHONE_A = "92883923";
public static final String VALID_TEAMMATE_PHONE_B = "92824833";
Expand Down Expand Up @@ -58,6 +59,6 @@ public class TeammateTestUtil {
+ "May Theresa";
public static final String INVALID_TEAMMATE_PHONE_DESC_A = " " + PREFIX_TEAMMATE_PHONE + "3818djfjjd";
public static final String INVALID_TEAMMATE_EMAIL_DESC_A = " " + PREFIX_TEAMMATE_EMAIL + "hey @";
public static final String INVALID_TEAMMATE_ADDRESS_DESC_A = " " + PREFIX_TEAMMATE_ADDRESS + " the Platform ";
public static final String INVALID_TEAMMATE_ADDRESS_DESC_A = " " + PREFIX_TEAMMATE_ADDRESS + " ";

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.commands.project;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static seedu.address.testutil.TypicalPersons.DESC_A;
Expand Down Expand Up @@ -66,7 +65,7 @@ public void execute_equals() {
assertEquals(addTeammateCommand1Copy, addTeammateCommand1);

// different types -> returns false
assertFalse(addTeammateCommand1.equals("this test will return false"));
assertNotEquals(addTeammateCommand1, "this test will return false");

// null -> returns false
assertNotEquals(addTeammateCommand1, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package seedu.address.logic.commands.project;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.TeammateTestUtil.VALID_TEAMMATE_GIT_USERNAME_A;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalGitIndexes.GIT_USERINDEX_FIRST_TEAMMATE;
import static seedu.address.testutil.TypicalGitIndexes.GIT_USERINDEX_INVALID_TEAMMATE;
import static seedu.address.testutil.TypicalGitIndexes.GIT_USERINDEX_SECOND_TEAMMATE;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PROJECT;
import static seedu.address.testutil.TypicalPersons.DESC_A;
import static seedu.address.testutil.TypicalProjects.getTypicalMainCatalogue;

import org.junit.jupiter.api.Test;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.project.Project;
import seedu.address.model.project.exceptions.DuplicateParticipationException;

public class AddTeammateParticipationCommandTest {

@Test
public void execute_validGitUserIndex_success() {
Model model = new ModelManager(getTypicalMainCatalogue(), new UserPrefs());
Project project = model.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased());
model.enter(project);

Model expectedModel = new ModelManager(getTypicalMainCatalogue(), new UserPrefs());
expectedModel.enter(project);
Project expectedProject = expectedModel.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased());
expectedProject.addParticipation(DESC_A);
expectedModel.addParticipation(expectedProject.getParticipation(DESC_A.getGitUserNameString()));

String expectedMessage =
String.format(AddTeammateParticipationCommand.MESSAGE_ADD_TEAMMATE_PARTICIPATION_SUCCESS,
VALID_TEAMMATE_GIT_USERNAME_A);
AddTeammateParticipationCommand addTeammateParticipationCommand =
new AddTeammateParticipationCommand(GIT_USERINDEX_FIRST_TEAMMATE);

assertCommandSuccess(addTeammateParticipationCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_validGitUserDuplicateParticipation_throwsCommandException() {
Model model = new ModelManager(getTypicalMainCatalogue(), new UserPrefs());
Project project = model.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased());
model.enter(project);
project.addParticipation(DESC_A);
model.addParticipation(project.getParticipation(DESC_A.getGitUserNameString()));

AddTeammateParticipationCommand addTeammateParticipationCommand =
new AddTeammateParticipationCommand(GIT_USERINDEX_FIRST_TEAMMATE);

assertThrows(DuplicateParticipationException.class, () -> addTeammateParticipationCommand.execute(model));
}

@Test
public void execute_invalidGitUserIndex_success() {
Model model = new ModelManager(getTypicalMainCatalogue(), new UserPrefs());
Project project = model.getFilteredProjectList().get(INDEX_FIRST_PROJECT.getZeroBased());
model.enter(project);

AddTeammateParticipationCommand addTeammateParticipationCommand =
new AddTeammateParticipationCommand(GIT_USERINDEX_INVALID_TEAMMATE);

assertThrows(NullPointerException.class, () -> addTeammateParticipationCommand.execute(model));
}

@Test
public void equals() {
AddTeammateParticipationCommand addFirst = new AddTeammateParticipationCommand(GIT_USERINDEX_FIRST_TEAMMATE);
AddTeammateParticipationCommand addSecond = new AddTeammateParticipationCommand(GIT_USERINDEX_FIRST_TEAMMATE);
AddTeammateParticipationCommand addThird = new AddTeammateParticipationCommand(GIT_USERINDEX_SECOND_TEAMMATE);

// same object -> returns true
assertTrue(addFirst.equals(addFirst));

// same values -> returns true
assertTrue(addFirst.equals(addSecond));

// different types -> returns false
assertFalse(addFirst.equals(1));

// null -> returns false
assertFalse(addFirst.equals(null));

// different gitUserName -> returns false
assertFalse(addFirst.equals(addThird));
}
}