Skip to content

Commit

Permalink
Merge pull request #229 from ongweekeong/master
Browse files Browse the repository at this point in the history
Fixed logout bug
  • Loading branch information
iamputradanish authored Nov 8, 2018
2 parents d77388d + 5926bf4 commit ce96379
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/InboxCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CommandResult execute() {
}

public static String concatenateMsg(int messageNum, Msg message) throws NullPointerException{
String concatenatedMsg;
String concatenatedMsg = null;
TimeAndDate dateFormatter = new TimeAndDate();
// try{
// concatenatedMsg = String.valueOf(messageNum) + ".\t[UNREAD] Sender: " + message.getSenderId() + " Priority: " + message.getPriority() +
Expand Down
2 changes: 2 additions & 0 deletions src/seedu/addressbook/commands/LogoutCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.addressbook.commands;

import seedu.addressbook.inbox.Inbox;
import seedu.addressbook.password.Password;
import seedu.addressbook.timeanddate.TimeAndDate;

Expand All @@ -16,6 +17,7 @@ public class LogoutCommand extends Command {

@Override
public CommandResult execute() {
Inbox.resetInboxWhenLogout();
Password password = new Password();
password.lockDevice();
return new CommandResult(MESSAGE_LOCK); }
Expand Down
11 changes: 10 additions & 1 deletion src/seedu/addressbook/inbox/Inbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String markMsgAsRead(int index) throws NullPointerException, IndexOutOfBo
}
allMessages.writeToFile(notificationsToPrint);
}
catch (IndexOutOfBoundsException e){
catch (IndexOutOfBoundsException | NullPointerException e){
if(numUnreadMsgs>0) {
return INDEX_OUT_OF_BOUNDS;
}
Expand All @@ -74,4 +74,13 @@ public int checkNumUnreadMessages(){
return numUnreadMsgs;
}

public static void resetInboxWhenLogout(){
numUnreadMsgs = -1;
recordNotifications.clear();
}

public static boolean isRecordMsgsEmpty(){
return recordNotifications.isEmpty();
}

}
11 changes: 11 additions & 0 deletions test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static seedu.addressbook.common.Messages.*;
import static seedu.addressbook.password.Password.*;

Expand Down Expand Up @@ -1558,6 +1559,16 @@ public void execute_ClearInboxCommand_unsuccessful() throws Exception {
assertEquals(expected, r.feedbackToUser);
}

@Test
public void execute_clearRecordedMsgWhenLogout() throws Exception{
Password.lockIsPO(); Password.lockIsHQP();
generateMsgInInbox("populate the inbox!");
logic.execute(ShowUnreadCommand.COMMAND_WORD);
assertFalse(Inbox.isRecordMsgsEmpty());
logic.execute(LogoutCommand.COMMAND_WORD);
assertTrue(Inbox.isRecordMsgsEmpty());
assertCommandBehavior(ReadCommand.COMMAND_WORD +" 1", Inbox.INBOX_NOT_READ_YET);
}
//@@author

/**
Expand Down

0 comments on commit ce96379

Please sign in to comment.