Skip to content

Commit

Permalink
Tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dukris committed Feb 14, 2024
1 parent d3c00d3 commit 56a718d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
Expand All @@ -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())
Expand Down
19 changes: 3 additions & 16 deletions src/test/java/git/tracehub/pmo/project/DefaultProjectsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<Project> actual = this.projects.byUser(email);
MatcherAssert.assertThat(
Expand All @@ -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(
Expand Down Expand Up @@ -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());
}

}
21 changes: 3 additions & 18 deletions src/test/java/git/tracehub/pmo/ticket/DefaultTicketsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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());
}

}

0 comments on commit 56a718d

Please sign in to comment.