forked from AY2324S2-CS2103T-T14-1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 AY2324S2-CS2103T-T14-1#102 from howen02/branch-fin…
…d-free Branch find free
- Loading branch information
Showing
7 changed files
with
190 additions
and
1 deletion.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/seedu/address/logic/commands/FindFreePersonCommand.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,48 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.PersonHasNoTaskPredicate; | ||
|
||
/** | ||
* Finds and lists all persons in address book who does not have an active task. | ||
*/ | ||
public class FindFreePersonCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "findfree"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all persons without an active task"; | ||
private final PersonHasNoTaskPredicate predicate = new PersonHasNoTaskPredicate(); | ||
|
||
public FindFreePersonCommand() { | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(new PersonHasNoTaskPredicate()); | ||
return new CommandResult( | ||
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
return other instanceof FindFreePersonCommand; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("predicate", predicate) | ||
.toString(); | ||
} | ||
} |
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
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
34 changes: 34 additions & 0 deletions
34
src/main/java/seedu/address/model/person/PersonHasNoTaskPredicate.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,34 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Name} has no active task. | ||
*/ | ||
public class PersonHasNoTaskPredicate implements Predicate<Person> { | ||
public PersonHasNoTaskPredicate() { | ||
} | ||
|
||
@Override | ||
public boolean test(Person person) { | ||
return person.isBusy(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// Check for identity | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// Check for correct type | ||
return other instanceof PersonHasNoTaskPredicate; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this).add("a", "a").toString(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/seedu/address/logic/commands/FindFreePersonCommandTest.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,52 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalAddressBook.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.PersonHasNoTaskPredicate; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) and unit tests for FindFreePersonCommand. | ||
*/ | ||
public class FindFreePersonCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private CommandHistory commandHistory = new CommandHistory(); | ||
|
||
@Test | ||
public void execute_multiplePersonsFoundWithNoTasks_multiplePersonFound() { | ||
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 4); | ||
FindFreePersonCommand command = new FindFreePersonCommand(); | ||
expectedModel.updateFilteredPersonList(new PersonHasNoTaskPredicate()); | ||
assertCommandSuccess(command, model, commandHistory, expectedMessage, expectedModel); | ||
assertEquals(expectedModel.getFilteredPersonList(), model.getFilteredPersonList()); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
FindFreePersonCommand findFirstCommand = new FindFreePersonCommand(); | ||
FindFreePersonCommand findSecondCommand = new FindFreePersonCommand(); | ||
|
||
// same object -> returns true | ||
assertTrue(findFirstCommand.equals(findFirstCommand)); | ||
|
||
// different types -> returns false | ||
assertFalse(findFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(findFirstCommand.equals(null)); | ||
|
||
// same type -> returns true | ||
assertTrue(findFirstCommand.equals(findSecondCommand)); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/test/java/seedu/address/model/person/PersonHasNoTaskPredicateTest.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,44 @@ | ||
package seedu.address.model.person; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.testutil.PersonBuilder; | ||
|
||
class PersonHasNoTaskPredicateTest { | ||
|
||
@Test | ||
public void equals() { | ||
PersonHasNoTaskPredicate firstPredicate = new PersonHasNoTaskPredicate(); | ||
PersonHasNoTaskPredicate secondPredicate = new PersonHasNoTaskPredicate(); | ||
|
||
// same object -> returns true | ||
assertTrue(firstPredicate.equals(firstPredicate)); | ||
|
||
// different types -> returns false | ||
assertFalse(firstPredicate.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(firstPredicate.equals(null)); | ||
|
||
// same class -> returns true, since there's no state to differ | ||
assertTrue(firstPredicate.equals(secondPredicate)); | ||
} | ||
|
||
@Test | ||
public void test_personIsNotBusy_returnsFalse() { | ||
// Person is not busy | ||
PersonHasNoTaskPredicate predicate = new PersonHasNoTaskPredicate(); | ||
assertFalse(predicate.test(new PersonBuilder().build())); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
PersonHasNoTaskPredicate predicate = new PersonHasNoTaskPredicate(); | ||
|
||
String expected = "PersonHasNoTaskPredicate"; | ||
assertTrue(predicate.toString().contains(expected)); | ||
} | ||
} |