forked from AY2324S2-CS2103T-T12-1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AY2324S2-CS2103T-T12-1#62 from Teee728/send-email-…
…directly-feature-test Add tests for mail feature
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package seedu.address.logic; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.mockito.MockedStatic; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static seedu.address.testutil.TypicalContacts.GEORGE; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.awt.Desktop; | ||
|
||
|
||
public class MailAppTest { | ||
|
||
@Test | ||
public void handleEmailClicked_validEmail_opensMailApp() { | ||
MailApp mailApp = new MailApp(GEORGE); | ||
mailApp.handleEmailClicked(); | ||
} | ||
|
||
@Test | ||
public void handleEmailClicked_noDesktopMailApp_throwsException() { | ||
// Create a mock object for the Desktop class | ||
try (MockedStatic desktopMock = mockStatic(Desktop.class)) { | ||
desktopMock.when(Desktop::isDesktopSupported).thenReturn(false); | ||
|
||
MailApp mailApp = new MailApp(GEORGE); | ||
assertThrows(RuntimeException.class, () -> mailApp.handleEmailClicked()); | ||
} | ||
} | ||
|
||
@Test | ||
public void handleEmailClicked_noMailActionSupported_throwsException() { | ||
try (MockedStatic<Desktop> desktopMock = mockStatic(Desktop.class)) { | ||
Desktop desktop = mock(Desktop.class); | ||
when(Desktop.getDesktop()).thenReturn(desktop); | ||
when(desktop.isSupported(Desktop.Action.MAIL)).thenReturn(false); | ||
|
||
MailApp mailApp = new MailApp(GEORGE); | ||
|
||
assertThrows(RuntimeException.class, () -> mailApp.handleEmailClicked()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters