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

Fix issue #128 #171

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/main/java/scm/address/logic/commands/ImportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ private List<JsonAdaptedPerson> getPersonsFromCsv(String filePath) throws IOExce
String headers = br.readLine();
while ((line = br.readLine()) != null) {
String[] info = line.split(splitBy);

if (info.length < 4) {
throw new IOException("Incorrect Data Format!");
}

String name = info[0];
String phone = info[1];
String email = info[2];
Expand Down
3 changes: 3 additions & 0 deletions src/test/data/ImportCommandTest/datasample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name,Email,Address
Alan Turing,something@some.com,"21st street"
Alan Burning,somethin2g@some.com,"22nd street"
11 changes: 11 additions & 0 deletions src/test/java/scm/address/logic/commands/ImportCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ImportCommandTest {
private static final String UNKNOWN_FILE_NAME = "./src/test/data/ImportCommandTest/abcdefgh_abcdefgh.json";
private static final String ADDRESS_BOOK_PATH = "./src/test/data/ImportCommandTest/addressbook.json";
private static final String TEST_CSV_FILE_PATH = "./src/test/data/ImportCommandTest/contacts.csv";
private static final String INVALID_DATA_CSV_FILE_PATH = "./src/test/data/ImportCommandTest/datasample.csv";
private static final String UNKNOWN_FILE_EXTENSION = "./src/test/data/ImportCommandTest/contacts.xyz";
private static final String NO_FILE_EXTENSION = "./src/test/data/ImportCommandTest/contacts";
private static final String UNKNOWN_CSV_FILE = "./src/test/data/ImportCommandTest/abcdefg.csv";
Expand Down Expand Up @@ -135,6 +136,16 @@ public void retrievePersonsFromFile_invalidCsvFile_failure() {
assertThrows(CommandException.class, () -> importCommand.execute(testModel));
}

@Test
public void retrievePersonsFromFile_invalidDataCsvFile_failure() {
HashSet<File> curHashSet = new HashSet<>();
curHashSet.add(new File(INVALID_DATA_CSV_FILE_PATH));

Model testModel = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalScheduleList());
ImportCommand importCommand = new ImportCommand(curHashSet);
assertThrows(CommandException.class, () -> importCommand.execute(testModel));
}

@Test
public void execute_importingFromUnknownFileFormat_failure() {
HashSet<File> curHashSet = new HashSet<>();
Expand Down
Loading