Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2103T-T12-1#62 from Teee728/send-email-…
Browse files Browse the repository at this point in the history
…directly-feature-test

Add tests for mail feature
  • Loading branch information
Teeesa7 authored Mar 21, 2024
2 parents a5fb68f + e889a14 commit 4b44a88
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
47 changes: 47 additions & 0 deletions src/test/java/seedu/address/logic/MailAppTest.java
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());
}
}
}
1 change: 0 additions & 1 deletion src/test/java/seedu/address/testutil/ContactBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,4 @@ public Contact build() {
return new Contact(name, phone, email, address, gitHubUsername, techStack, tags);
}


}

0 comments on commit 4b44a88

Please sign in to comment.