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

Refactor code #108

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions src/main/java/seedu/address/commons/core/index/Index.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_PERSON_ID = "There is no person with id %1$d";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
Expand Down
19 changes: 0 additions & 19 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Set;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
Expand All @@ -29,24 +28,6 @@
*/
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
* trimmed.
*
* @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();
if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) {
throw new ParseException(MESSAGE_INVALID_INDEX);
}
return Index.fromOneBased(Integer.parseInt(trimmedIndex));
}

/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
* trimmed.
Expand Down
67 changes: 0 additions & 67 deletions src/test/java/seedu/address/commons/core/index/IndexTest.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Collections;
import java.util.List;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.NetConnect;
Expand Down Expand Up @@ -163,21 +162,6 @@ public static void assertCommandFailure(Command command, Model actualModel, Stri
assertEquals(expectedFilteredList, actualModel.getFilteredPersonList());
}

/**
* Updates {@code model}'s filtered list to show only the person at the given
* {@code targetIndex} in the
* {@code model}'s address book.
*/
public static void showPersonAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredPersonList().size());

Person person = model.getFilteredPersonList().get(targetIndex.getZeroBased());
final String[] splitName = person.getName().fullName.split("\\s+");
model.updateFilteredPersonList(new NameContainsKeywordsPredicate(Collections.singletonList(splitName[0])));

assertEquals(1, model.getFilteredPersonList().size());
}

/**
* Updates {@code model}'s filtered list to show only the person at the given
* {@code targetId} in the {@code model}'s netconnect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.junit.jupiter.api.Test;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
Expand Down Expand Up @@ -110,7 +109,6 @@ public void equals() {

@Test
public void toStringMethod() {
Index targetIndex = Index.fromOneBased(1);
Id targetId = ID_FIRST_PERSON;
DeleteCommand deleteCommand = new DeleteCommand(targetId);
String expected = DeleteCommand.class.getCanonicalName() + "{targetId=" + targetId + "}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtId;
import static seedu.address.testutil.TypicalIds.ID_FIRST_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalNetConnect;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -34,7 +34,7 @@ public void execute_listIsNotFiltered_showsSameList() {

@Test
public void execute_listIsFiltered_showsEverything() {
showPersonAtIndex(model, INDEX_FIRST_PERSON);
showPersonAtId(model, ID_FIRST_PERSON);
assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
}
}
22 changes: 0 additions & 22 deletions src/test/java/seedu/address/logic/parser/ParserUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.parser.ParserUtil.MESSAGE_INVALID_INDEX;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalIds.ID_FIRST_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -56,26 +54,6 @@ public class ParserUtilTest {

private static final String WHITESPACE = " \t\r\n";

@Test
public void parseIndex_invalidInput_throwsParseException() {
assertThrows(ParseException.class, () -> ParserUtil.parseIndex("10 a"));
}

@Test
public void parseIndex_outOfRangeInput_throwsParseException() {
assertThrows(ParseException.class, MESSAGE_INVALID_INDEX, ()
-> ParserUtil.parseIndex(Long.toString(Integer.MAX_VALUE + 1)));
}

@Test
public void parseIndex_validInput_success() throws Exception {
// No whitespaces
assertEquals(INDEX_FIRST_PERSON, ParserUtil.parseIndex("1"));

// Leading and trailing whitespaces
assertEquals(INDEX_FIRST_PERSON, ParserUtil.parseIndex(" 1 "));
}

@Test
public void parseId_invalidInput_throwsParseException() {
assertThrows(ParseException.class, () -> ParserUtil.parseId("0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@

import seedu.address.logic.Messages;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.model.person.Id;
import seedu.address.model.person.Remark;

public class RemarkCommandParserTest {
private final RemarkCommandParser parser = new RemarkCommandParser();

@Test
public void parse_validIndex_returnsDeleteCommand() {
public void parse_validId_returnsRemarkCommand() {
assertParseSuccess(parser, " i/1 r/remark",
new RemarkCommand(ID_FIRST_PERSON, new Remark("remark")));
}

@Test
public void parse_repeatedFields_throwsParserException() {
public void parse_invalidId_throwsParseException() {
assertParseFailure(parser, " i/0 r/remark",
String.format(Id.MESSAGE_CONSTRAINTS));
}

@Test
public void parse_repeatedFields_throwsParseException() {
// repeated id
assertParseFailure(parser, " i/1 i/2 r/remark",
String.format(Messages.getErrorMessageForDuplicatePrefixes(PREFIX_ID)));
Expand Down
25 changes: 0 additions & 25 deletions src/test/java/seedu/address/testutil/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import seedu.address.commons.core.index.Index;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* A utility class for test cases.
*/
Expand All @@ -31,25 +27,4 @@ public static Path getFilePathInSandboxFolder(String fileName) {
}
return SANDBOX_FOLDER.resolve(fileName);
}

/**
* Returns the middle index of the person in the {@code model}'s person list.
*/
public static Index getMidIndex(Model model) {
return Index.fromOneBased(model.getFilteredPersonList().size() / 2);
}

/**
* Returns the last index of the person in the {@code model}'s person list.
*/
public static Index getLastIndex(Model model) {
return Index.fromOneBased(model.getFilteredPersonList().size());
}

/**
* Returns the person in the {@code model}'s person list at {@code index}.
*/
public static Person getPerson(Model model, Index index) {
return model.getFilteredPersonList().get(index.getZeroBased());
}
}
11 changes: 0 additions & 11 deletions src/test/java/seedu/address/testutil/TypicalIndexes.java

This file was deleted.

Loading