From 56a718d88655acbb1ae2605cc3bc4b159239a840 Mon Sep 17 00:00:00 2001 From: hizmailovich Date: Wed, 14 Feb 2024 12:55:52 +0300 Subject: [PATCH] Tests fixed --- .../pmo/controller/ProjectControllerTest.java | 8 +++---- .../pmo/project/DefaultProjectsTest.java | 19 +++-------------- .../pmo/ticket/DefaultTicketsTest.java | 21 +++---------------- 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/test/java/git/tracehub/pmo/controller/ProjectControllerTest.java b/src/test/java/git/tracehub/pmo/controller/ProjectControllerTest.java index 8f27333..ef04b27 100644 --- a/src/test/java/git/tracehub/pmo/controller/ProjectControllerTest.java +++ b/src/test/java/git/tracehub/pmo/controller/ProjectControllerTest.java @@ -18,7 +18,7 @@ package git.tracehub.pmo.controller; import git.tracehub.pmo.platforms.Platform; -import git.tracehub.pmo.platforms.github.GithubPlatform; +import git.tracehub.pmo.platforms.github.Github; import git.tracehub.pmo.project.Project; import git.tracehub.pmo.project.Projects; import io.github.eocqrs.eokson.Jocument; @@ -99,7 +99,7 @@ void returnsProjectById() throws Exception { @Test void createsNewProject() throws Exception { - final Platform platform = Mockito.mock(GithubPlatform.class); + final Platform platform = Mockito.mock(Github.class); Mockito.when(this.platforms.get(Mockito.any())) .thenReturn(platform); Mockito.when(this.projects.employ(Mockito.any(Scalar.class))) @@ -111,9 +111,7 @@ void createsNewProject() throws Exception { true ) ); - Mockito.doNothing().when(platform).createWebhook(Mockito.any(), Mockito.any()); - Mockito.doNothing().when(platform).createLabel(Mockito.any(), Mockito.any()); - Mockito.doNothing().when(platform).inviteCollaborator(Mockito.any(), Mockito.any()); + Mockito.doNothing().when(platform).prepare(Mockito.any(), Mockito.any()); this.mvc.perform( MockMvcRequestBuilders.post("/projects") .with(SecurityMockMvcRequestPostProcessors.jwt()) diff --git a/src/test/java/git/tracehub/pmo/project/DefaultProjectsTest.java b/src/test/java/git/tracehub/pmo/project/DefaultProjectsTest.java index b388f92..c3358b0 100644 --- a/src/test/java/git/tracehub/pmo/project/DefaultProjectsTest.java +++ b/src/test/java/git/tracehub/pmo/project/DefaultProjectsTest.java @@ -104,7 +104,7 @@ void returnsProjectById() throws SQLException { "Description", true ); - this.mock(expected); + new MockProject(this.set).exec(expected); Mockito.when(this.set.next()).thenReturn(true); final Project project = this.projects.byId(expected.getId()); MatcherAssert.assertThat( @@ -129,7 +129,7 @@ void returnsProjectsByUser() throws SQLException { "Description", true ); - this.mock(expected); + new MockProject(this.set).exec(expected); Mockito.when(this.set.next()).thenReturn(true, false); final List actual = this.projects.byUser(email); MatcherAssert.assertThat( @@ -153,7 +153,7 @@ void employsProject() throws SQLException { "Description", true ); - this.mock(expected); + new MockProject(this.set).exec(expected); Mockito.when(this.set.next()).thenReturn(true); final Project project = this.projects.employ(() -> expected); MatcherAssert.assertThat( @@ -201,17 +201,4 @@ void throwsOnCreatingInvalidProject() throws SQLException { ).affirm(); } - private void mock(final Project project) throws SQLException { - Mockito.when(this.set.getString("id")) - .thenReturn(project.getId().toString()); - Mockito.when(this.set.getString("name")) - .thenReturn(project.getName()); - Mockito.when(this.set.getString("location")) - .thenReturn(project.getLocation()); - Mockito.when(this.set.getString("description")) - .thenReturn(project.getDescription()); - Mockito.when(this.set.getBoolean("active")) - .thenReturn(project.isActive()); - } - } diff --git a/src/test/java/git/tracehub/pmo/ticket/DefaultTicketsTest.java b/src/test/java/git/tracehub/pmo/ticket/DefaultTicketsTest.java index fe083cf..c6d02f7 100644 --- a/src/test/java/git/tracehub/pmo/ticket/DefaultTicketsTest.java +++ b/src/test/java/git/tracehub/pmo/ticket/DefaultTicketsTest.java @@ -104,7 +104,7 @@ void returnsTicketByJob() throws SQLException { "path/to/job", Ticket.Status.OPENED ); - this.mock(expected); + new MockTicket(this.set).exec(expected); Mockito.when(this.set.next()).thenReturn(true); final Ticket ticket = this.tickets.byJob( expected.getJob(), @@ -132,7 +132,7 @@ void returnsTicketByIssueNumber() throws SQLException { "path/to/job", Ticket.Status.OPENED ); - this.mock(expected); + new MockTicket(this.set).exec(expected); Mockito.when(this.set.next()).thenReturn(true); final Ticket ticket = this.tickets.byNumber( expected.getNumber(), @@ -160,7 +160,7 @@ void createsTicket() throws SQLException { "path/to/job", Ticket.Status.OPENED ); - this.mock(expected); + new MockTicket(this.set).exec(expected); Mockito.when(this.set.next()).thenReturn(true); final Ticket ticket = this.tickets.create(() -> expected); MatcherAssert.assertThat( @@ -226,19 +226,4 @@ void throwsOnCreatingInvalidTicket() throws SQLException { ).affirm(); } - private void mock(final Ticket ticket) throws SQLException { - Mockito.when(this.set.getString("id")) - .thenReturn(ticket.getId().toString()); - Mockito.when(this.set.getString("project")) - .thenReturn(ticket.getProject().toString()); - Mockito.when(this.set.getInt("number")) - .thenReturn(ticket.getNumber()); - Mockito.when(this.set.getString("repo")) - .thenReturn(ticket.getRepo()); - Mockito.when(this.set.getString("job")) - .thenReturn(ticket.getJob()); - Mockito.when(this.set.getString("status")) - .thenReturn(ticket.getStatus().name()); - } - }