Skip to content

Commit

Permalink
Mocked objects moved to new classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dukris committed Feb 14, 2024
1 parent 56a718d commit cc5d1f4
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/test/java/git/tracehub/pmo/project/MockProject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to read
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package git.tracehub.pmo.project;

import java.sql.ResultSet;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.cactoos.Proc;
import org.mockito.Mockito;

/**
* Mock project into ResultSet.
*
* @since 0.0.0
*/
@RequiredArgsConstructor
@SuppressWarnings({
"JTCOP.RuleCorrectTestName",
"JTCOP.RuleAllTestsHaveProductionClass"
})
final class MockProject implements Proc<Project> {

/**
* ResultSet.
*/
private final ResultSet set;

@Override
@SneakyThrows
public void exec(final Project project) {
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());
}

}
60 changes: 60 additions & 0 deletions src/test/java/git/tracehub/pmo/ticket/MockTicket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to read
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package git.tracehub.pmo.ticket;

import java.sql.ResultSet;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.cactoos.Proc;
import org.mockito.Mockito;

/**
* Mock ticket into ResultSet.
*
* @since 0.0.0
*/
@RequiredArgsConstructor
@SuppressWarnings({
"JTCOP.RuleCorrectTestName",
"JTCOP.RuleAllTestsHaveProductionClass"
})
final class MockTicket implements Proc<Ticket> {

/**
* ResultSet.
*/
private final ResultSet set;

@Override
@SneakyThrows
public void exec(final Ticket ticket) {
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 cc5d1f4

Please sign in to comment.