diff --git a/build.gradle b/build.gradle index 303fb29c615..576b42dafbd 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,8 @@ dependencies { testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion + testImplementation 'org.mockito:mockito-core:5.11.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion } diff --git a/src/test/java/seedu/address/logic/MailAppTest.java b/src/test/java/seedu/address/logic/MailAppTest.java new file mode 100644 index 00000000000..7ed8085f28b --- /dev/null +++ b/src/test/java/seedu/address/logic/MailAppTest.java @@ -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 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()); + } + } +} diff --git a/src/test/java/seedu/address/testutil/ContactBuilder.java b/src/test/java/seedu/address/testutil/ContactBuilder.java index ee00f6d92ec..42b928310b5 100644 --- a/src/test/java/seedu/address/testutil/ContactBuilder.java +++ b/src/test/java/seedu/address/testutil/ContactBuilder.java @@ -118,5 +118,4 @@ public Contact build() { return new Contact(name, phone, email, address, gitHubUsername, techStack, tags); } - }