diff --git a/pom.xml b/pom.xml
index 4062b0f..dcdfb21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,6 +17,7 @@
UTF-8
21
21
+ 5.18.0
@@ -28,6 +29,16 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.5.3
+
+
+ -javaagent:"${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar"
+
+
+
org.flywaydb
flyway-maven-plugin
@@ -201,12 +212,7 @@
org.gitlab4j
gitlab4j-api
- 6.0.0-rc.9
-
-
- org.gitlab4j
- gitlab4j-models
- 6.0.0-rc.9
+ 6.0.0-rc.10
@@ -268,6 +274,13 @@
org.junit.jupiter
junit-jupiter
5.12.2
+ test
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
diff --git a/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java b/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java
index a71551f..320a234 100644
--- a/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java
+++ b/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java
@@ -90,13 +90,12 @@ public class ReportIssueTask extends ModalTask {
gitLabApi.setRequestTimeout(1000, 5000);
String title = String.format("Bug report: %s", modalTitle.getAsString());
- StringBuilder description = new StringBuilder();
- description.append("Issue reported from user of bot\n\n");
- description.append("User: ").append(user.getName()).append(String.format("[%s]", user.getId())).append("\n\n");
- description.append("Last Sentry ID: ").append(Sentry.getLastEventId()).append("\n\n");
- description.append("Description from user: \n\n").append(modalDescription.getAsString());
+ String description = "Issue reported from user of bot\n\n" +
+ "User: " + user.getName() + String.format("[%s]", user.getId()) + "\n\n" +
+ "Last Sentry ID: " + Sentry.getLastEventId() + "\n\n" +
+ "Description from user: \n\n" + modalDescription.getAsString();
- Issue issue = gitLabApi.getIssuesApi().createIssue(projectId, title, description.toString());
+ Issue issue = gitLabApi.getIssuesApi().createIssue(projectId, title, description);
context.reply(String.format("Issue was successfully created: %s", issue.getWebUrl()));
diff --git a/src/test/java/me/bobert/netneutrality/command/git/ReportIssueCommandTest.java b/src/test/java/me/bobert/netneutrality/command/git/ReportIssueCommandTest.java
new file mode 100644
index 0000000..991d621
--- /dev/null
+++ b/src/test/java/me/bobert/netneutrality/command/git/ReportIssueCommandTest.java
@@ -0,0 +1,63 @@
+package me.bobert.netneutrality.command.git;
+
+/*
+ * Copyright (c) anthorob
+ *
+ * https://discord.gg/qUa6zNFZsd
+ */
+
+import org.gitlab4j.api.GitLabApi;
+import org.gitlab4j.api.IssuesApi;
+import org.gitlab4j.api.models.Issue;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class ReportIssueCommandTest {
+ private GitLabApi mockGitLabApi;
+ private IssuesApi mockIssuesApi;
+
+ @BeforeEach
+ void setup() {
+ mockGitLabApi = mock(GitLabApi.class);
+ mockIssuesApi = mock(IssuesApi.class);
+
+ when(mockGitLabApi.getIssuesApi()).thenReturn(mockIssuesApi);
+ }
+
+ @Test
+ void testCreateIssueMocked() throws Exception {
+ int projectId = 123456;
+ String modalTitle = "Bug report: mocked bug report";
+ String modalDescription = "This is a mocked description";
+ String userName = "TestUser";
+ String userId = UUID.randomUUID().toString();
+ String sentryId = UUID.randomUUID().toString();
+
+ String expectedTitle = String.format("Bug report: %s", modalTitle);
+ String expectedDescription = "Issue reported from user of bot\n\n" +
+ "User: " + userName + String.format("[%s]", userId) + "\n\n" +
+ "Last Sentry ID: " + sentryId + "\n\n" +
+ "Description from user: \n\n" + modalDescription;
+
+ Issue mockedIssue = new Issue();
+ mockedIssue.setTitle(expectedTitle);
+ mockedIssue.setDescription(expectedDescription);
+
+ when(mockIssuesApi.createIssue(eq(projectId), eq(expectedTitle), eq(expectedDescription))).thenReturn(mockedIssue);
+
+ Issue created = mockGitLabApi.getIssuesApi().createIssue(projectId, expectedTitle, expectedDescription);
+ assertNotNull(created);
+ assertEquals(expectedTitle, created.getTitle());
+ assertEquals(expectedDescription, created.getDescription());
+
+ verify(mockIssuesApi).createIssue(projectId, expectedTitle, expectedDescription);
+ }
+}
\ No newline at end of file