From aca5f5329303ba8f16f5c73ae970a845adb0e26c Mon Sep 17 00:00:00 2001 From: TresaAnnThomas Date: Tue, 19 Mar 2024 15:45:33 +0800 Subject: [PATCH 1/3] Add tests for mail feature --- build.gradle | 2 + .../java/seedu/address/logic/MailAppTest.java | 47 +++++++++++++++++++ .../seedu/address/testutil/PersonBuilder.java | 4 ++ 3 files changed, 53 insertions(+) create mode 100644 src/test/java/seedu/address/logic/MailAppTest.java diff --git a/build.gradle b/build.gradle index 8cd88833649..665dd1e7a60 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..27588d6604e --- /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.TypicalPersons.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/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index eaa95d43037..8fb22900feb 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -23,6 +23,7 @@ public class PersonBuilder { public static final String DEFAULT_EMAIL = "amy@gmail.com"; public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111"; public static final String DEFAULT_GITHUB_USERNAME = "amy-bee675"; + public static final String DEFAULT_TECH_STACK = "Java"; private Name name; private Phone phone; @@ -41,6 +42,8 @@ public PersonBuilder() { email = new Email(DEFAULT_EMAIL); address = new Address(DEFAULT_ADDRESS); gitHubUsername = new GitHubUsername(DEFAULT_GITHUB_USERNAME); + techStack = new HashSet<>(); + techStack.add(new TechStack(DEFAULT_TECH_STACK)); tags = new HashSet<>(); } @@ -52,6 +55,7 @@ public PersonBuilder(Person personToCopy) { phone = personToCopy.getPhone(); email = personToCopy.getEmail(); address = personToCopy.getAddress(); + gitHubUsername = personToCopy.getGitHubUsername(); techStack = new HashSet<>(personToCopy.getTechStack()); tags = new HashSet<>(personToCopy.getTags()); } From 998535c3f83aeb2dba2e106b134f4bd58d4f858d Mon Sep 17 00:00:00 2001 From: TresaAnnThomas Date: Wed, 20 Mar 2024 13:07:49 +0800 Subject: [PATCH 2/3] Fix Person Builder class --- src/test/java/seedu/address/testutil/PersonBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index 8fb22900feb..03bf7705ebf 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -23,7 +23,7 @@ public class PersonBuilder { public static final String DEFAULT_EMAIL = "amy@gmail.com"; public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111"; public static final String DEFAULT_GITHUB_USERNAME = "amy-bee675"; - public static final String DEFAULT_TECH_STACK = "Java"; + //public static final String DEFAULT_TECH_STACK = "Java"; private Name name; private Phone phone; @@ -43,7 +43,7 @@ public PersonBuilder() { address = new Address(DEFAULT_ADDRESS); gitHubUsername = new GitHubUsername(DEFAULT_GITHUB_USERNAME); techStack = new HashSet<>(); - techStack.add(new TechStack(DEFAULT_TECH_STACK)); + //techStack.add(new TechStack(DEFAULT_TECH_STACK)); tags = new HashSet<>(); } From e889a14eff4958ba7bd6a8f755e545252c1c06ed Mon Sep 17 00:00:00 2001 From: TresaAnnThomas Date: Wed, 20 Mar 2024 23:54:10 +0800 Subject: [PATCH 3/3] Fix TypicalPersons to TypicalContacts --- src/test/java/seedu/address/logic/MailAppTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/logic/MailAppTest.java b/src/test/java/seedu/address/logic/MailAppTest.java index 27588d6604e..7ed8085f28b 100644 --- a/src/test/java/seedu/address/logic/MailAppTest.java +++ b/src/test/java/seedu/address/logic/MailAppTest.java @@ -6,7 +6,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; -import static seedu.address.testutil.TypicalPersons.GEORGE; +import static seedu.address.testutil.TypicalContacts.GEORGE; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when;