Skip to content

Commit

Permalink
Merge f07a152 into 1022a14
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischenhui committed Nov 5, 2019
2 parents 1022a14 + f07a152 commit 159e5b4
Show file tree
Hide file tree
Showing 24 changed files with 934 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public class DeleteCommand extends CardCommand {
+ "where index is a positive integer within the list\n"
+ "Eg: " + COMMAND_WORD + " 1";

private static final String MESSAGE_DELETE_CARD_SUCCESS = "Deleted card: %1$s";
public static final String MESSAGE_DELETE_CARD_SUCCESS = "Deleted card: %1$s";

private final Index targetIndex;

/**
* Creates a DeleteCommand to delete the specified {@code Index}.
*/
public DeleteCommand(Index targetIndex) {
requireNonNull(targetIndex);
this.targetIndex = targetIndex;
}

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

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FILEPATH;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WORD;

Expand All @@ -24,13 +25,14 @@ public class ImportCommand extends WordBankCommand {
+ PREFIX_WORD + "sample "
+ PREFIX_FILEPATH + "~/downloads";

private static final String MESSAGE_IMPORT_CARD_SUCCESS = "Imported word bank: %1$s\n"
public static final String MESSAGE_IMPORT_CARD_SUCCESS = "Imported word bank: %1$s\n"
+ "Location : %2$s";

private String wordBankName;
private File directory;

public ImportCommand(String wordBankName, File directory) {
requireAllNonNull(wordBankName, directory);
this.wordBankName = wordBankName;
this.directory = directory;
}
Expand All @@ -49,7 +51,16 @@ public boolean equals(Object other) {
// instanceof handles nulls
|| (other instanceof seedu.address.logic.commands.wordbankcommands.ImportCommand
&& wordBankName
.equals(((seedu.address.logic.commands.wordbankcommands.ImportCommand) other).wordBankName));
.equals(((ImportCommand) other).getWordBankName())
&& directory
.equals((((ImportCommand) other).getDirectory())));
}

public String getWordBankName() {
return wordBankName;
}

public File getDirectory() {
return directory;
}
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public class ModelManager implements Model {
private boolean hasBank = false;

private WordBank currentWordBank = SampleDataUtil.getPokemonWordBank();

private final WordBankList wordBankList;

private WordBankStatistics wordBankStatistics;

private final WordBankStatisticsList wordBankStatisticsList;

private final GlobalStatistics globalStatistics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@JsonRootName(value = "wordBank")
class JsonSerializableWordBank {

public static final String MESSAGE_DUPLICATE_CARDS_IN_WORD_BANK = "Word bank contains duplicate card(s).";
private static final String MESSAGE_DUPLICATE_CARDS_IN_WORD_BANK = "Word bank contains duplicate card(s).";

private final List<JsonAdaptedCard> wordBank = new ArrayList<>();

Expand All @@ -38,7 +38,7 @@ public JsonSerializableWordBank(@JsonProperty("wordBank") List<JsonAdaptedCard>
*
* @param source future changes to this will not affect the created {@code JsonSerializableWordBank}.
*/
public JsonSerializableWordBank(ReadOnlyWordBank source) {
JsonSerializableWordBank(ReadOnlyWordBank source) {
this.name = source.getName();
wordBank.addAll(source.getCardList().stream().map(JsonAdaptedCard::new).collect(Collectors.toList()));
}
Expand Down

This file was deleted.

29 changes: 14 additions & 15 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_MEANING;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WORD;
//import static seedu.address.testutil.Assert.assertThrows;

//import java.util.ArrayList;
import static seedu.address.testutil.Assert.assertThrows;

import java.util.ArrayList;
import java.util.Arrays;
//import java.util.List;
import java.util.List;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.cardcommands.EditCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.card.Card;
import seedu.address.model.card.WordContainsKeywordsPredicate;
//import seedu.address.model.wordbank.WordBank;
import seedu.address.model.wordbanklist.WordBankList;
import seedu.address.testutil.EditCardDescriptorBuilder;

/**
Expand Down Expand Up @@ -95,16 +94,16 @@ public static void assertCommandSuccess(Command command, Model actualModel, Stri
* - the CommandException message matches {@code expectedMessage} <br>
* - the address book, filtered card list and selected person in {@code actualModel} remain unchanged
*/
// public static void assertCommandFailure(Command command, Model actualModel, String expectedMessage) {
// // we are unable to defensively copy the model for comparison later, so we can
// // only do so by copying its components.
// WordBank expectedWordBank = new WordBank(actualModel.toModelType());
// List<Card> expectedFilteredList = new ArrayList<>(actualModel.getFilteredCardList());
//
// assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel));
// assertEquals(expectedWordBank, actualModel.toModelType());
// assertEquals(expectedFilteredList, actualModel.getFilteredCardList());
// }
public static void assertCommandFailure(Command command, Model actualModel, String expectedMessage) {
// we are unable to defensively copy the model for comparison later, so we can
// only do so by copying its components.
WordBankList expectedWbl = actualModel.getWordBankList();
List<Card> expectedFilteredList = new ArrayList<>(actualModel.getFilteredCardList());

assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel));
assertEquals(expectedWbl, actualModel.getWordBankList());
assertEquals(expectedFilteredList, actualModel.getFilteredCardList());
}

/**
* Updates {@code model}'s filtered list to show only the card at the given {@code targetIndex} in the
Expand Down
103 changes: 0 additions & 103 deletions src/test/java/seedu/address/logic/commands/DeleteCommandTest.java

This file was deleted.

12 changes: 6 additions & 6 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import static seedu.address.logic.commands.CommandTestUtil.DESC_ABRA;
import static seedu.address.logic.commands.CommandTestUtil.DESC_BUTTERFREE;

import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_CARD;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_CARD;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -137,11 +137,11 @@ public class EditCommandTest {

@Test
public void equals() {
final EditCommand standardCommand = new EditCommand(INDEX_FIRST_PERSON, DESC_ABRA);
final EditCommand standardCommand = new EditCommand(INDEX_FIRST_CARD, DESC_ABRA);

// same values -> returns true
EditCommand.EditCardDescriptor copyDescriptor = new EditCommand.EditCardDescriptor(DESC_ABRA);
EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_PERSON, copyDescriptor);
EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_CARD, copyDescriptor);
assertTrue(standardCommand.equals(commandWithSameValues));

// same object -> returns true
Expand All @@ -154,10 +154,10 @@ public void equals() {
assertFalse(standardCommand.equals(new ClearCommand()));

// different index -> returns false
assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_PERSON, DESC_ABRA)));
assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_CARD, DESC_ABRA)));

// different descriptor -> returns false
assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_PERSON, DESC_BUTTERFREE)));
assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_CARD, DESC_BUTTERFREE)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.address.logic.commands.cardcommands;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.commons.core.Messages;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.card.Card;
import seedu.address.testutil.CardBuilder;

/**
* Contains integration tests (interaction with the Model) for {@code AddCommand}.
*/
class AddCommandIntegrationTest {

private Model model;

@BeforeEach
void setUp() {
model = new ModelManager();
}

@Test
void execute_newCard_success() {
Card abra = new CardBuilder().withWord("Abra").build();

Model expectedModel = new ModelManager();

expectedModel.addCard(abra);

assertCommandSuccess(new AddCommand(abra), model,
String.format(AddCommand.MESSAGE_SUCCESS, abra), expectedModel);
}


@Test
void execute_duplicateCard_throwsCommandException() {
Card cardInList = model.getCurrentWordBank().getCardList().get(0);
assertCommandFailure(new AddCommand(cardInList), model, Messages.MESSAGE_DUPLICATE_CARD);
}

}

0 comments on commit 159e5b4

Please sign in to comment.