diff --git a/src/main/java/seedu/address/logic/commands/AddTeamCommand.java b/src/main/java/seedu/address/logic/commands/AddTeamCommand.java new file mode 100644 index 00000000000..173c347f4d4 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/AddTeamCommand.java @@ -0,0 +1,158 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAM_SIZE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.ModuleMessages; +import seedu.address.model.Model; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.ModuleTutorialPair; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; + +/** + * A class that handles the /add_team command execution. + */ +public class AddTeamCommand extends Command { + public static final String MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE = "Added %1$s to %2$s %3$s"; + public static final String MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE = "Added %1$s of size %2$s to %3$s %4$s"; + public static final String MESSAGE_DUPLICATE_TEAM = "%1$s already added to %2$s %3$s!"; + public static final String COMMAND_WORD = "/add_team"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Create a team with a name and an optional size, assigned to a particular tutorial class\n" + + "Parameters: " + PREFIX_MODULECODE + "MODULE_CODE " + + PREFIX_TUTORIALCLASS + "TUTORIAL_CLASS " + PREFIX_NAME + "TEAM_NAME " + PREFIX_TEAM_SIZE + "TEAM_SIZE\n" + + "Example: " + COMMAND_WORD + " " + PREFIX_MODULECODE + "CS2103T " + + PREFIX_TUTORIALCLASS + "T09 " + PREFIX_NAME + "Team 1 " + PREFIX_TEAM_SIZE + "5"; + + private final ModuleCode module; + private final TutorialClass tutorialClass; + private final String teamName; + private final int teamSize; + + /** + * Constructs an AddTeamCommand to add the specified {@code TutorialTeam} to the + * specified {@code TutorialClass}, without the specified team size. + * @param module The module code of the tutorial class to be added. + * @param tutorialClass The tutorial class to be added. + * @param teamName The name of the team to be added. + */ + public AddTeamCommand(ModuleCode module, TutorialClass tutorialClass, String teamName) { + requireAllNonNull(module); + this.module = module; + this.tutorialClass = tutorialClass; + this.teamName = teamName; + this.teamSize = Integer.MAX_VALUE; + } + + /** + * Constructs an AddTeamCommand to add the specified {@code TutorialTeam} to the + * specified {@code TutorialClass}, with the specified team size. + * @param module The module code of the tutorial class to be added. + * @param tutorialClass The tutorial class to be added. + * @param teamName The name of the team to be added. + * @param teamSize The size of the team to be added. + */ + public AddTeamCommand(ModuleCode module, TutorialClass tutorialClass, String teamName, int teamSize) { + requireAllNonNull(module); + this.module = module; + this.tutorialClass = tutorialClass; + this.teamName = teamName; + this.teamSize = teamSize; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleCode module = moduleAndTutorialClass.getModule(); + TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); + + TutorialTeam newTeam = new TutorialTeam(teamName, teamSize); + + if (tutorialClass.hasTeam(newTeam)) { + throw new CommandException(String.format(MESSAGE_DUPLICATE_TEAM, teamName, module, tutorialClass)); + } else { + tutorialClass.addTeam(newTeam); + } + + if (teamSize != Integer.MAX_VALUE) { + return new CommandResult(generateSuccessMessage(module, tutorialClass, teamName, teamSize)); + } else { + return new CommandResult(generateSuccessMessage(module, tutorialClass, teamName)); + } + } + + protected ModuleTutorialPair getModuleAndTutorialClass(Model model) throws CommandException { + requireNonNull(model); + ModuleCode module = getModule(); + TutorialClass tutorialClass = getTutorialClass(); + ModuleCode existingModule = model.findModuleFromList(module); + TutorialClass existingTutorialClass = model.findTutorialClassFromList(tutorialClass, existingModule); + if (existingModule == null) { + throw new CommandException(String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, module)); + } + if (existingTutorialClass == null) { + throw new CommandException( + String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); + } + return new ModuleTutorialPair(existingModule, existingTutorialClass); + } + + protected ModuleCode getModule() { + return module; + } + + protected TutorialClass getTutorialClass() { + return tutorialClass; + } + + /** + * Generates a command execution success message based on whether the tutorial + * team is added successfully and if the team size is not specified. + * @param module The module code of the tutorial class. + * @param tutorialString The tutorial class. + * @param teamName The name of the team. + * @return The success message. + */ + private String generateSuccessMessage(ModuleCode module, TutorialClass tutorialString, String teamName) { + return String.format(MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE, teamName, module, + tutorialString); + } + + /** + * Generates a command execution success message based on whether the tutorial + * team is added successfully and if the team size is specified. + * @param module The module code of the tutorial class. + * @param tutorialString The tutorial class. + * @param teamName The name of the team. + * @param teamSize The size of the team. + * @return The success message. + */ + private String generateSuccessMessage(ModuleCode module, TutorialClass tutorialString, String teamName, + int teamSize) { + return String.format(MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE, teamName, teamSize, module, tutorialString); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof AddTeamCommand)) { + return false; + } + + AddTeamCommand e = (AddTeamCommand) other; + return module.equals(e.module) && tutorialClass.equals(e.tutorialClass) && teamName.equals(e.teamName) + && teamSize == e.teamSize; + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddTeamCommandParser.java b/src/main/java/seedu/address/logic/parser/AddTeamCommandParser.java new file mode 100644 index 00000000000..5adc660f6d6 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AddTeamCommandParser.java @@ -0,0 +1,70 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAM_SIZE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; + +import java.util.stream.Stream; + +import seedu.address.logic.commands.AddTeamCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; + +/** + * Parses input arguments and creates a new {@code AddClassCommandParser} object + */ +public class AddTeamCommandParser implements Parser { + /** + * Parses the given {@code String} of arguments in the context of the + * {@code AddClassCommandParser} + * and returns a {@code AddClassCommandParser} object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public AddTeamCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS, + PREFIX_NAME, PREFIX_TEAM_SIZE); + + if (!arePrefixesPresent(argMultimap, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS, PREFIX_NAME) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTeamCommand.MESSAGE_USAGE)); + } + + boolean isTeamSizePresent = argMultimap.getValue(PREFIX_TEAM_SIZE).isPresent(); + String moduleCode = argMultimap.getValue(PREFIX_MODULECODE).orElse(""); + String tutorialClass = argMultimap.getValue(PREFIX_TUTORIALCLASS).orElse(""); + String teamName = argMultimap.getValue(PREFIX_NAME).orElse(""); + if (!(ModuleCode.isValidModuleCode(moduleCode))) { + throw new ParseException(ModuleCode.MESSAGE_CONSTRAINTS); + } + if (!(TutorialClass.isValidTutorialClass(tutorialClass))) { + throw new ParseException(TutorialClass.MESSAGE_CONSTRAINTS); + } + + if (!TutorialTeam.isValidTeamName(teamName)) { + throw new ParseException(TutorialTeam.MESSAGE_NAME_CONSTRAINTS); + } + if (isTeamSizePresent) { + int teamSize = Integer.parseInt(argMultimap.getValue(PREFIX_TEAM_SIZE).get()); + if (teamSize <= 0) { + throw new ParseException(TutorialTeam.MESSAGE_SIZE_CONSTRAINTS); + } + return new AddTeamCommand(new ModuleCode(moduleCode), new TutorialClass(tutorialClass), teamName, teamSize); + } else { + return new AddTeamCommand(new ModuleCode(moduleCode), new TutorialClass(tutorialClass), teamName); + } + } + + /** + * Returns true if all the prefixes are present in the given + * {@code ArgumentMultimap}. + */ + private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { + return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 74c53b0cf1c..b644f029c2d 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -10,6 +10,7 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.logic.commands.AddClassCommand; import seedu.address.logic.commands.AddStudentCommand; +import seedu.address.logic.commands.AddTeamCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.DeleteClassCommand; @@ -98,6 +99,9 @@ public Command parseCommand(String userInput) throws ParseException { case AddStudentToClassCommand.COMMAND_WORD: return new AddStudentToClassCommandParser().parse(arguments); + case AddTeamCommand.COMMAND_WORD: + return new AddTeamCommandParser().parse(arguments); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index e1e70e3ffd9..dda54cd045b 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -1,7 +1,8 @@ package seedu.address.logic.parser; /** - * Contains Command Line Interface (CLI) syntax definitions common to multiple commands + * Contains Command Line Interface (CLI) syntax definitions common to multiple + * commands */ public class CliSyntax { @@ -14,4 +15,5 @@ public class CliSyntax { public static final Prefix PREFIX_TUTORIALCLASS = new Prefix("tutorial/"); public static final Prefix PREFIX_TAG = new Prefix("tag/"); public static final Prefix PREFIX_DESCRIPTION = new Prefix("description/"); + public static final Prefix PREFIX_TEAM_SIZE = new Prefix("size/"); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b032a21c75f..12010548824 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -17,16 +17,19 @@ import seedu.address.model.tag.Tag; /** - * Contains utility methods used for parsing strings in the various *Parser classes. + * Contains utility methods used for parsing strings in the various *Parser + * classes. */ public class ParserUtil { public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer."; /** - * Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be + * Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading + * and trailing whitespaces will be * trimmed. - * @throws ParseException if the specified index is invalid (not non-zero unsigned integer). + * @throws ParseException if the specified index is invalid (not non-zero + * unsigned integer). */ public static Index parseIndex(String oneBasedIndex) throws ParseException { String trimmedIndex = oneBasedIndex.trim(); @@ -39,7 +42,6 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException { /** * Parses a {@code String name} into a {@code Name}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code name} is invalid. */ public static Name parseName(String name) throws ParseException { @@ -54,7 +56,6 @@ public static Name parseName(String name) throws ParseException { /** * Parses a {@code String email} into an {@code Email}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code email} is invalid. */ public static Email parseEmail(String email) throws ParseException { @@ -69,7 +70,6 @@ public static Email parseEmail(String email) throws ParseException { /** * Parses a {@code String studentId} into a {@code StudentId}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code studentId} is invalid. */ public static StudentId parseStudentId(String studentId) throws ParseException { @@ -84,7 +84,6 @@ public static StudentId parseStudentId(String studentId) throws ParseException { /** * Parses a {@code String moduleCode} into an {@code ModuleCode}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code moduleCode} is invalid. */ public static ModuleCode parseModuleCode(String moduleCode) throws ParseException { @@ -96,11 +95,9 @@ public static ModuleCode parseModuleCode(String moduleCode) throws ParseExceptio return new ModuleCode(trimmedModuleCode); } - /** * Parses a {@code String tutorial} into an {@code TutorialClass}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code tutorial} is invalid. */ public static TutorialClass parseTutorialClass(String tutorial) throws ParseException { @@ -115,7 +112,6 @@ public static TutorialClass parseTutorialClass(String tutorial) throws ParseExce /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. - * * @throws ParseException if the given {@code tag} is invalid. */ public static Tag parseTag(String tag) throws ParseException { diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index 4d24e3b6f44..ad99f458234 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -25,6 +25,7 @@ public class TutorialClass { public final String tutorialName; private final ArrayList students; + private final ArrayList teams; /** * Constructs a {@code TutorialClass} with default values. @@ -34,6 +35,7 @@ public class TutorialClass { public TutorialClass() { this.tutorialName = ""; this.students = new ArrayList<>(); + this.teams = new ArrayList<>(); } /** @@ -46,18 +48,35 @@ public TutorialClass(String tutorialClass) { checkArgument(isValidTutorialClass(tutorialClass), MESSAGE_CONSTRAINTS); this.tutorialName = tutorialClass; this.students = new ArrayList<>(); + this.teams = new ArrayList<>(); } /** * A constructor for TutorialClass. Creates a tutorial class with students. * @param tutorialClass to be added - * @param students in the tutorial class + * @param students in the tutorial class */ public TutorialClass(String tutorialClass, ArrayList students) { requireAllNonNull(tutorialClass); checkArgument(isValidTutorialClass(tutorialClass), MESSAGE_CONSTRAINTS); this.tutorialName = tutorialClass; this.students = students; + this.teams = new ArrayList<>(); + } + + /** + * A constructor for TutorialClass. Creates a tutorial class with students and + * teams. + * @param tutorialClass to be added + * @param students in the tutorial class + * @param teams in the tutorial class + */ + public TutorialClass(String tutorialClass, ArrayList students, ArrayList teams) { + requireAllNonNull(tutorialClass); + checkArgument(isValidTutorialClass(tutorialClass), MESSAGE_CONSTRAINTS); + this.tutorialName = tutorialClass; + this.students = students; + this.teams = teams; } /** @@ -93,6 +112,7 @@ public ArrayList getStudents() { /** * Adds a student to the tutorial class. + * @param student */ public void addStudent(Person student) { students.add(student); @@ -100,7 +120,7 @@ public void addStudent(Person student) { /** * Removes a student from the tutorial class if it exists. - * + * @param student * @return true if the student was removed */ public boolean deleteStudent(Person student) { @@ -116,6 +136,30 @@ public boolean hasStudent(Person student) { return students.contains(student); } + /** + * Retrieves the list of teams in the tutorial class. + * @return The list of teams in the tutorial class. + */ + public ArrayList getTeams() { + return this.teams; + } + + /** + * Adds a team to the tutorial class. + * @param team + */ + public void addTeam(TutorialTeam team) { + teams.add(team); + } + + /** + * Checks if the team is in the tutorial class. + * @param team + */ + public boolean hasTeam(TutorialTeam team) { + return teams.contains(team); + } + @Override public String toString() { return tutorialName; diff --git a/src/main/java/seedu/address/model/module/TutorialTeam.java b/src/main/java/seedu/address/model/module/TutorialTeam.java new file mode 100644 index 00000000000..1bee5db01c8 --- /dev/null +++ b/src/main/java/seedu/address/model/module/TutorialTeam.java @@ -0,0 +1,190 @@ +package seedu.address.model.module; + +import static seedu.address.commons.util.AppUtil.checkArgument; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.ArrayList; + +import seedu.address.model.person.Person; + +/** + * Represents a Module's tutorial team. + * Guarantees: immutable; is valid as declared in + * {@link #isValidTeamName(String)} + */ +public class TutorialTeam { + + public static final String MESSAGE_CONSTRAINTS = "Please enter a valid tutorial team name " + + "eg. Team 1, and it should not be blank"; + public static final String MESSAGE_NAME_CONSTRAINTS = "Team names should only contain alphanumeric " + + "characters and spaces, and it should not be blank"; + public static final String MESSAGE_SIZE_CONSTRAINTS = "Team size should be a positive integer"; + + public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String teamName; + public final int teamSize; + private final ArrayList students; + + /** + * Constructs a {@code TutorialTeam} with default values. + * Initializes the {@code value} field to an empty string, creates an empty + * list for {@code students} and sets the {@code teamSize} to the maximum. + */ + public TutorialTeam() { + this.teamName = ""; + this.students = new ArrayList<>(); + this.teamSize = Integer.MAX_VALUE; + } + + /** + * A constructor for TutorialTeam. Creates a tutorial team of a certain size + * with no students. + * @param tutorialTeam + * @param teamSize + */ + public TutorialTeam(String tutorialTeam, int teamSize) { + requireAllNonNull(tutorialTeam, teamSize); + checkArgument(isValidTeamName(tutorialTeam), MESSAGE_NAME_CONSTRAINTS); + checkArgument(isValidSize(teamSize), MESSAGE_SIZE_CONSTRAINTS); + this.teamName = tutorialTeam; + this.students = new ArrayList<>(); + this.teamSize = teamSize; + } + + /** + * A constructor for TutorialTeam. Creates a tutorial team with students. + * @param tutorialClass to be added + * @param students in the tutorial class + */ + public TutorialTeam(String tutorialTeam, ArrayList students) { + requireAllNonNull(tutorialTeam); + checkArgument(isValidTeamName(tutorialTeam), MESSAGE_NAME_CONSTRAINTS); + this.teamName = tutorialTeam; + this.students = students; + this.teamSize = Integer.MAX_VALUE; + } + + /** + * A constructor for TutorialTeam. Creates a tutorial team with students and + * team size. + * @param tutorialClass to be added + * @param students in the tutorial class + * @param teamSize of the tutorial team + */ + public TutorialTeam(String tutorialTeam, ArrayList students, int teamSize) { + requireAllNonNull(tutorialTeam); + checkArgument(isValidTeamName(tutorialTeam), MESSAGE_NAME_CONSTRAINTS); + checkArgument(isValidSize(teamSize), MESSAGE_SIZE_CONSTRAINTS); + this.teamName = tutorialTeam; + this.students = students; + this.teamSize = teamSize; + } + + /** + * Returns true if a given string is a valid tutorial team name. + * @param test + */ + public static boolean isValidTeamName(String test) { + return test.matches(VALIDATION_REGEX); + } + + /** + * Returns true if a given integer is a valid team size. + * @param test + */ + public static boolean isValidSize(int test) { + return test > 0; + } + + /** + * Set students to the tutorial team. + * @param students + */ + public void setStudents(ArrayList students) { + this.students.addAll(students); + } + + /** + * Retrieves the tutorial team. + * @return The tutorial team. + */ + public TutorialTeam getTutorialTeam() { + return this; + } + + /** + * Retrieves the team name. + * @return The team name. + */ + public String getTeamName() { + return teamName; + } + + /** + * Retrieves the team size. + * @return The team size. + */ + public int getTeamSize() { + return teamSize; + } + + /** + * Retrieves the list of students in the tutorial team. + * @return The list of students in the tutorial team. + */ + public ArrayList getStudents() { + return this.students; + } + + /** + * Adds a student to the tutorial team. + * @param student + */ + public void addStudent(Person student) { + students.add(student); + } + + /** + * Removes a student from the tutorial class if it exists. + * @param student + * @return true if the student was removed + */ + public boolean deleteStudent(Person student) { + return students.remove(student); + } + + /** + * Checks if the student is in the tutorial team. + * @param student + * @return true if the student is in the tutorial class + */ + public boolean hasStudent(Person student) { + return students.contains(student); + } + + @Override + public String toString() { + return teamName; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof TutorialTeam)) { + return false; + } + + TutorialTeam otherTutorialTeam = (TutorialTeam) other; + return teamName.equals(otherTutorialTeam.teamName); + } + + @Override + public int hashCode() { + return teamName.hashCode(); + } +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java b/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java index ea2e6d597cc..adaf8763c6e 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedTutorialClass.java @@ -9,6 +9,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; import seedu.address.model.person.Person; /** @@ -18,6 +19,7 @@ public class JsonAdaptedTutorialClass { private final String tutorialName; private final List students; + private final List teams; /** * Constructs a {@code JsonAdaptedTutorialClass} with the given @@ -25,8 +27,10 @@ public class JsonAdaptedTutorialClass { */ @JsonCreator public JsonAdaptedTutorialClass(@JsonProperty("tutorialName") String tutorialName, + @JsonProperty("teams") List teams, @JsonProperty("students") List students) { this.tutorialName = tutorialName; + this.teams = teams != null ? new ArrayList<>(teams) : new ArrayList<>(); this.students = students != null ? new ArrayList<>(students) : new ArrayList<>(); } @@ -35,6 +39,7 @@ public JsonAdaptedTutorialClass(@JsonProperty("tutorialName") String tutorialNam */ public JsonAdaptedTutorialClass(TutorialClass source) { this.tutorialName = source.tutorialName; + this.teams = source.getTeams().stream().map(JsonAdaptedTutorialTeam::new).collect(Collectors.toList()); this.students = source.getStudents().stream().map(JsonAdaptedPerson::new).collect(Collectors.toList()); } @@ -42,6 +47,10 @@ public String getTutorialName() { return tutorialName; } + public List getTeams() { + return new ArrayList<>(teams); + } + public List getStudents() { return new ArrayList<>(students); } @@ -59,7 +68,11 @@ public TutorialClass toModelType() throws IllegalValueException { for (JsonAdaptedPerson student : this.students) { students.add(student.toModelType()); } - return new TutorialClass(tutorialName, students); + ArrayList teams = new ArrayList<>(); + for (JsonAdaptedTutorialTeam team : this.teams) { + teams.add(team.toModelType()); + } + return new TutorialClass(tutorialName, students, teams); } catch (IllegalValueException e) { throw new IllegalValueException(TutorialClass.MESSAGE_CONSTRAINTS); } @@ -76,6 +89,7 @@ public boolean equals(Object other) { } JsonAdaptedTutorialClass otherTutorialClass = (JsonAdaptedTutorialClass) other; - return tutorialName.equals(otherTutorialClass.tutorialName) && students.equals(otherTutorialClass.students); + return tutorialName.equals(otherTutorialClass.tutorialName) && students.equals(otherTutorialClass.students) + && teams.equals(otherTutorialClass.teams); } } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTutorialTeam.java b/src/main/java/seedu/address/storage/JsonAdaptedTutorialTeam.java new file mode 100644 index 00000000000..8e132df59c3 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedTutorialTeam.java @@ -0,0 +1,90 @@ +package seedu.address.storage; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.module.TutorialTeam; +import seedu.address.model.person.Person; + +/** + * Jackson-friendly version of {@link TutorialTeam}. + */ +public class JsonAdaptedTutorialTeam { + + private final String teamName; + private final int teamSize; + private final List students; + + /** + * Constructs a {@code JsonAdaptedTutorialTeam} with the given + * {@code teamName}. + */ + @JsonCreator + public JsonAdaptedTutorialTeam(@JsonProperty("teamName") String teamName, + @JsonProperty("teamSize") int teamSize, + @JsonProperty("students") List students) { + this.teamName = teamName; + this.students = students != null ? new ArrayList<>(students) : new ArrayList<>(); + this.teamSize = teamSize; + } + + /** + * Converts a given {@code TutorialTeam} into this class for Jackson use. + */ + public JsonAdaptedTutorialTeam(TutorialTeam source) { + this.teamName = source.teamName; + this.teamSize = source.teamSize; + this.students = source.getStudents().stream().map(JsonAdaptedPerson::new).collect(Collectors.toList()); + } + + public String getTeamName() { + return teamName; + } + + public int getTeamSize() { + return teamSize; + } + + public List getStudents() { + return new ArrayList<>(students); + } + + /** + * Converts this Jackson-friendly adapted tutorial team object into the model's + * {@code TutorialTeam} object. + * + * @throws IllegalValueException if there were any data constraints violated in + * the adapted tutorial team. + */ + public TutorialTeam toModelType() throws IllegalValueException { + try { + ArrayList students = new ArrayList<>(); + for (JsonAdaptedPerson student : this.students) { + students.add(student.toModelType()); + } + return new TutorialTeam(teamName, students, teamSize); + } catch (IllegalValueException e) { + throw new IllegalValueException(TutorialTeam.MESSAGE_CONSTRAINTS); + } + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof JsonAdaptedTutorialTeam)) { + return false; + } + + JsonAdaptedTutorialTeam otherTutorialTeam = (JsonAdaptedTutorialTeam) other; + return teamName.equals(otherTutorialTeam.teamName) && students.equals(otherTutorialTeam.students) + && teamSize == otherTutorialTeam.teamSize; + } +} diff --git a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java index 6ad3bc2d907..39507dbcdf3 100644 --- a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandIntegrationTest.java @@ -26,7 +26,7 @@ /** * Contains integration tests (interaction with the Model) for - * {@code AddCommand}. + * {@code AddStudentToClassCommand}. */ public class AddStudentToClassCommandIntegrationTest { diff --git a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java index 99b26f87727..813f091a6b3 100644 --- a/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddStudentToClassCommandTest.java @@ -38,7 +38,7 @@ /** * Contains integration tests (interaction with the Model) and unit tests for - * {@code DeleteCommand}. + * {@code AddStudentToClassCommand}. */ public class AddStudentToClassCommandTest { diff --git a/src/test/java/seedu/address/logic/commands/AddTeamCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddTeamCommandIntegrationTest.java new file mode 100644 index 00000000000..8edf10cf5b0 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AddTeamCommandIntegrationTest.java @@ -0,0 +1,85 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_SIZE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import seedu.address.logic.messages.ModuleMessages; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.TutorialClass; + +/** + * Contains integration tests (interaction with the Model) for + * {@code AddTeamCommand}. + */ +public class AddTeamCommandIntegrationTest { + + private Model model; + private ModuleCode testModule; + private TutorialClass testTutorial; + + @BeforeEach + public void setUp() { + model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + ModuleCode newModule = new ModuleCode(VALID_MODULE_AMY); + model.addModule(newModule); + this.testModule = newModule; + TutorialClass newTutorialClass = new TutorialClass(VALID_TUTORIAL_AMY); + newModule.addTutorialClass(newTutorialClass); + this.testTutorial = newTutorialClass; + } + + @Test + public void execute_addTeamWithNoSize_success() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + assertCommandSuccess(new AddTeamCommand(testModule, testTutorial, VALID_TEAM_NAME_AMY), + model, + String.format(AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE, VALID_TEAM_NAME_AMY, + testModule, testTutorial), + expectedModel); + } + + @Test + public void execute_addTeamWithSize_success() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + assertCommandSuccess(new AddTeamCommand(testModule, testTutorial, VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE), + model, + String.format(AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE, VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE, + testModule, testTutorial), + expectedModel); + } + + @Test + public void execute_addTeamToInvalidModule_throwsCommandException() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + ModuleCode invalidModule = new ModuleCode(VALID_MODULE_BOB); + assertCommandFailure(new AddTeamCommand(invalidModule, testTutorial, VALID_TEAM_NAME_AMY), + expectedModel, + String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, invalidModule)); + } + + @Test + public void execute_addTeamToInvalidTutorial_throwsCommandException() { + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + + TutorialClass invalidTutorial = new TutorialClass(VALID_TUTORIAL_BOB); + assertCommandFailure(new AddTeamCommand(testModule, invalidTutorial, VALID_TEAM_NAME_AMY), + expectedModel, + String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, invalidTutorial, testModule)); + } +} diff --git a/src/test/java/seedu/address/logic/commands/AddTeamCommandTest.java b/src/test/java/seedu/address/logic/commands/AddTeamCommandTest.java new file mode 100644 index 00000000000..35c2ac09086 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AddTeamCommandTest.java @@ -0,0 +1,94 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE; +import static seedu.address.logic.commands.AddTeamCommand.MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE; +import static seedu.address.logic.commands.AddTeamCommand.MESSAGE_DUPLICATE_TEAM; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_SIZE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.BeforeEach; +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.module.ModuleCode; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; + +/** + * Contains integration tests (interaction with the Model) and unit tests for + * {@code AddTeamCommand}. + */ +public class AddTeamCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private TutorialClass tutorialClass; + + @BeforeEach + public void setUp() { + model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + ModuleCode module = new ModuleCode(VALID_MODULE_AMY); + model.addModule(module); + TutorialClass tutorialClass = new TutorialClass(VALID_TUTORIAL_AMY); + module.addTutorialClass(tutorialClass); + this.tutorialClass = tutorialClass; + } + + @Test + public void execute_addTeamWithSizesuccess() { + assertCommandSuccess(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE), model, + String.format(MESSAGE_ADD_TEAM_SUCCESS_WITH_SIZE, VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE, + VALID_MODULE_AMY, VALID_TUTORIAL_AMY), + model); + } + + @Test + public void execute_addTeamWithoutSizesuccess() { + + assertCommandSuccess(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY), model, + String.format(MESSAGE_ADD_TEAM_SUCCESS_WITHOUT_SIZE, VALID_TEAM_NAME_AMY, VALID_MODULE_AMY, + VALID_TUTORIAL_AMY), + model); + } + + @Test + public void execute_duplicateTeam_fail() { + TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + tutorialClass.addTeam(team); + + assertCommandFailure(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY), model, + String.format(MESSAGE_DUPLICATE_TEAM, VALID_TEAM_NAME_AMY, VALID_MODULE_AMY, VALID_TUTORIAL_AMY)); + } + + @Test + public void equals() { + final AddTeamCommand standardCommand = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + + // same values -> returns true + AddTeamCommand commandWithSameValues = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + assertTrue(standardCommand.equals(commandWithSameValues)); + + // same object -> returns true + assertTrue(standardCommand.equals(standardCommand)); + + // null -> returns false + assertFalse(standardCommand.equals(null)); + + // different team name -> returns false + assertFalse(standardCommand.equals(new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_BOB, VALID_TEAM_SIZE))); + } +} diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 1113a6212ae..5599bf61c76 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -8,6 +8,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAM_SIZE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; import static seedu.address.testutil.Assert.assertThrows; @@ -61,6 +62,15 @@ public class CommandTestUtil { public static final String INVALID_PERSON_EMAIL = "test@example.com"; public static final String INVALID_PERSON_STUDENT_ID = "A2222222A"; + // Team related constants + public static final String VALID_TEAM_NAME_AMY = "Team 1"; + public static final String VALID_TEAM_NAME_BOB = "Team 2"; + public static final int VALID_TEAM_SIZE = 5; + public static final String TEAM_NAME_DESC_AMY = " " + PREFIX_NAME + VALID_TEAM_NAME_AMY; + public static final String TEAM_SIZE_DESC = " " + PREFIX_TEAM_SIZE + VALID_TEAM_SIZE; + public static final String INVALID_TEAM_NAME = "Team 1!"; + public static final int INVALID_TEAM_SIZE = -1; + // '&' not allowed in names public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; diff --git a/src/test/java/seedu/address/logic/parser/AddTeamCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddTeamCommandParserTest.java new file mode 100644 index 00000000000..201c1608e88 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/AddTeamCommandParserTest.java @@ -0,0 +1,59 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.MODULE_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.TEAM_NAME_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.TEAM_SIZE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.TUTORIAL_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_SIZE; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.AddTeamCommand; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; + +/** + * Contains unit tests for AddTeamCommandParser. + */ +public class AddTeamCommandParserTest { + private final AddTeamCommandParser parser = new AddTeamCommandParser(); + + @Test + public void parse_teamWithNoSize_success() { + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY + TEAM_NAME_DESC_AMY; + AddTeamCommand expectedCommand = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_teamWithSize_success() { + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY + TEAM_NAME_DESC_AMY + TEAM_SIZE_DESC; + AddTeamCommand expectedCommand = new AddTeamCommand(new ModuleCode(VALID_MODULE_AMY), + new TutorialClass(VALID_TUTORIAL_AMY), VALID_TEAM_NAME_AMY, VALID_TEAM_SIZE); + assertParseSuccess(parser, userInput, expectedCommand); + } + + @Test + public void parse_teamWithInvalidName_failure() { + String expectedMessage = TutorialTeam.MESSAGE_NAME_CONSTRAINTS; + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY + " " + PREFIX_NAME + " "; + assertParseFailure(parser, userInput, expectedMessage); + } + + @Test + public void parse_teamWithNoName_failure() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTeamCommand.MESSAGE_USAGE); + String userInput = MODULE_DESC_AMY + TUTORIAL_DESC_AMY; + assertParseFailure(parser, userInput, expectedMessage); + } + +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index adbb70cc3f7..53cea1c0c0b 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -160,7 +160,7 @@ public void parseCommand_addStudentToClass() throws Exception { public void parseCommand_unrecognisedInput_throwsParseException() { assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), ( - ) -> parser.parseCommand("")); + ) -> parser.parseCommand("")); } @Test diff --git a/src/test/java/seedu/address/model/module/TutorialTeamTest.java b/src/test/java/seedu/address/model/module/TutorialTeamTest.java new file mode 100644 index 00000000000..17fd04baa38 --- /dev/null +++ b/src/test/java/seedu/address/model/module/TutorialTeamTest.java @@ -0,0 +1,106 @@ +package seedu.address.model.module; + +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.model.module.TutorialTeam.isValidSize; +import static seedu.address.model.module.TutorialTeam.isValidTeamName; +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +/** + * Contains unit tests for the TutorialTeam class. + */ +public class TutorialTeamTest { + + public static final String VALID_TEAM_NAME_1 = "Team 1"; + public static final String VALID_TEAM_NAME_2 = "Team 2"; + public static final String INVALID_TEAM_NAME = "Team 3!!!!"; + public static final int VALID_TEAM_SIZE = 5; + public static final int INVALID_TEAM_SIZE = -1; + + + /** + * Test cases to check the equality of two TutorialTeam objects + */ + @Test + public void equals() { + TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_1, VALID_TEAM_SIZE); + + // same object -> returns true + assertTrue(team.equals(team)); + + // same values -> returns true + TutorialTeam teamCopy = new TutorialTeam(VALID_TEAM_NAME_1, VALID_TEAM_SIZE); + assertTrue(team.equals(teamCopy)); + + // different types -> returns false + assertFalse(team.equals(1)); + + // null -> returns false + assertFalse(team.equals(null)); + + // different remark -> returns false + TutorialTeam differentTeam = new TutorialTeam(VALID_TEAM_NAME_2, VALID_TEAM_SIZE); + assertFalse(team.equals(differentTeam)); + } + + /** + * Tests isValidTeamName with a valid team name. + */ + @Test + void isValidModuleCode_success() { + assertTrue(isValidTeamName(VALID_TEAM_NAME_1)); + } + + /** + * Tests isValidTeamName with an invalid team name. + */ + @Test + void isValidTeamName_failure() { + assertFalse(isValidTeamName(INVALID_TEAM_NAME)); + } + + /** + * Tests isValidSize with a valid team size. + */ + @Test + void isValidSize_success() { + assertTrue(isValidSize(VALID_TEAM_SIZE)); + } + + /** + * Tests isValidSize with an invalid team size. + */ + @Test + void isValidSize_failure() { + assertFalse(isValidSize(INVALID_TEAM_SIZE)); + } + + /** + * Tests the constructor of TutorialTeam with a valid team name and team size. + */ + @Test + void constructor_validTeamNameAndSize_success() { + TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_1, VALID_TEAM_SIZE); + assertEquals(VALID_TEAM_NAME_1, team.getTeamName()); + assertEquals(VALID_TEAM_SIZE, team.getTeamSize()); + } + + /** + * Tests the constructor of TutorialTeam with an invalid team name. + */ + @Test + void constructor_invalidTeamName_failure() { + assertThrows(IllegalArgumentException.class, () -> new TutorialTeam(INVALID_TEAM_NAME, VALID_TEAM_SIZE)); + } + + /** + * Tests the constructor of TutorialTeam with an invalid team size. + */ + @Test + void constructor_invalidTeamSize_failure() { + assertThrows(IllegalArgumentException.class, () -> new TutorialTeam(VALID_TEAM_NAME_1, INVALID_TEAM_SIZE)); + } +} diff --git a/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java b/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java index 950583ef283..9f5680e1ad6 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedTutorialClassTest.java @@ -21,6 +21,8 @@ class JsonAdaptedTutorialClassTest { Arrays.asList(new PersonBuilder().build(), new PersonBuilder().build())).stream() .map(JsonAdaptedPerson::new) .collect(Collectors.toList()); + private static final List VALID_TEAMS_LIST = new ArrayList<>( + Arrays.asList(new JsonAdaptedTutorialTeam("Team 1", 1, VALID_STUDENTS_LIST))); @Test void toModelType_success() throws Exception { @@ -32,7 +34,7 @@ void toModelType_success() throws Exception { @Test void toModelType_invalidTutorialName_throwsIllegalValueException() { JsonAdaptedTutorialClass jsonTutorialClass = new JsonAdaptedTutorialClass(INVALID_TUTORIAL_NAME, - VALID_STUDENTS_LIST); + VALID_TEAMS_LIST, VALID_STUDENTS_LIST); String expectedMessage = TutorialClass.MESSAGE_CONSTRAINTS; assertThrows(IllegalArgumentException.class, expectedMessage, jsonTutorialClass::toModelType); } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedTutorialTeamTest.java b/src/test/java/seedu/address/storage/JsonAdaptedTutorialTeamTest.java new file mode 100644 index 00000000000..c5a642c91e9 --- /dev/null +++ b/src/test/java/seedu/address/storage/JsonAdaptedTutorialTeamTest.java @@ -0,0 +1,50 @@ +package seedu.address.storage; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static seedu.address.testutil.Assert.assertThrows; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.module.TutorialTeam; +import seedu.address.testutil.PersonBuilder; + +class JsonAdaptedTutorialTeamTest { + + private static final String VALID_TEAM_NAME = "Team 1"; + private static final String INVALID_TEAM_NAME = ""; + private static final int VALID_TEAM_SIZE = 10; + private static final int INVALID_TEAM_SIZE = -1; + private static final List VALID_STUDENTS_LIST = new ArrayList<>( + Arrays.asList(new PersonBuilder().build(), new PersonBuilder().build())).stream() + .map(JsonAdaptedPerson::new) + .collect(Collectors.toList()); + + @Test + void toModelType_success() throws Exception { + TutorialTeam tutorialTeam = new TutorialTeam(VALID_TEAM_NAME, VALID_TEAM_SIZE); + JsonAdaptedTutorialTeam jsonTutorialTeam = new JsonAdaptedTutorialTeam(tutorialTeam); + assertEquals(tutorialTeam, jsonTutorialTeam.toModelType()); + } + + @Test + void toModelType_invalidTeamName_throwsIllegalValueException() { + JsonAdaptedTutorialTeam jsonTutorialTeam = new JsonAdaptedTutorialTeam(INVALID_TEAM_NAME, VALID_TEAM_SIZE, + VALID_STUDENTS_LIST); + String expectedMessage = TutorialTeam.MESSAGE_NAME_CONSTRAINTS; + assertThrows(IllegalArgumentException.class, expectedMessage, jsonTutorialTeam::toModelType); + } + + @Test + void toModelType_invalidTeamSize_throwsIllegalValueException() { + JsonAdaptedTutorialTeam jsonTutorialTeam = new JsonAdaptedTutorialTeam(VALID_TEAM_NAME, INVALID_TEAM_SIZE, + VALID_STUDENTS_LIST); + String expectedMessage = TutorialTeam.MESSAGE_SIZE_CONSTRAINTS; + assertThrows(IllegalArgumentException.class, expectedMessage, jsonTutorialTeam::toModelType); + } + +}