Skip to content

Replace @SpyBean and @MockBean with @MockitoSpyBean and @MockitoBean #1271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<argLine>@{argLine} -javaagent:${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar</argLine>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;
Expand Down Expand Up @@ -64,9 +64,9 @@ class ActionControllerIT {
}
]
""";
@MockBean
@MockitoBean
ActionAuthorizationService actionAuthorizationService;
@MockBean
@MockitoBean
ActionMapper actionMapper;
@Autowired
private MockMvc mvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

@WithMockUser(value = "spring")
@ExtendWith(MockitoExtension.class)
@WebMvcTest(AlignmentController.class)
@Import(AlignmentSelectionMapper.class)
class AlignmentControllerIT {
@Autowired
private MockMvc mvc;
@MockBean

@MockitoBean
private AlignmentSelectionBusinessService alignmentSelectionBusinessService;
@SpyBean
private AlignmentSelectionMapper alignmentSelectionMapper;

static String alignmentObjectiveName = "Objective 5";
static List<AlignmentSelection> alignmentSelectionPuzzle = List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

Expand All @@ -23,7 +23,7 @@
class CacheControllerIT {
@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private CacheService cacheService;

@DisplayName("Should empty authorization cache of users")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,29 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;

@WithMockUser(value = "spring")
@ExtendWith(MockitoExtension.class)
@WebMvcTest(CheckInController.class)
@Import(DeserializerHelper.class)
class CheckInControllerIT {
@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private CheckInAuthorizationService checkInAuthorizationService;
@MockBean
@MockitoBean
private CheckInMapper checkInMapper;
@MockBean
@MockitoBean
private KeyResultBusinessService keyResultBusinessService;
@SpyBean
DeserializerHelper deserializerHelper;

@BeforeEach
void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

Expand All @@ -29,7 +29,7 @@ public class ClientConfigControllerIT {

@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private ClientConfigService configService;

@DisplayName("Should get client config with correct values")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;
Expand All @@ -51,9 +51,9 @@ class CompletedControllerIT {
}
""".formatted(OBJECTIVE_ID, COMPLETED_COMMENT);

@MockBean
@MockitoBean
CompletedAuthorizationService completedAuthorizationService;
@MockBean
@MockitoBean
private CompletedMapper completedMapper;

private final Completed successfulCompleted = Completed.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,38 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;

@WithMockUser(value = "spring")
@ExtendWith(MockitoExtension.class)
@WebMvcTest(KeyResultController.class)
@Import(DeserializerHelper.class)
class KeyResultControllerIT {

@MockBean
@MockitoBean
KeyResultMapper keyResultMapper;
@MockBean
@MockitoBean
CheckInMapper checkInMapper;
@MockBean
@MockitoBean
ActionMapper actionMapper;
@MockBean
@MockitoBean
KeyResultAuthorizationService keyResultAuthorizationService;
@MockBean
@MockitoBean
ActionAuthorizationService actionAuthorizationService;
@MockBean
@MockitoBean
UserPersistenceService userPersistenceService;
@MockBean
@MockitoBean
ObjectivePersistenceService objectivePersistenceService;
@MockBean
@MockitoBean
private KeyResultBusinessService keyResultBusinessService;
@SpyBean
DeserializerHelper deserializerHelper;
@Autowired
private MockMvc mvc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;
Expand Down Expand Up @@ -134,17 +134,17 @@ class ObjectiveControllerIT {

@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private ObjectiveAuthorizationService objectiveAuthorizationService;
@Mock
private AuthorizationService authorizationService;
@MockBean
@MockitoBean
private ActionAuthorizationService actionAuthorizationService;
@MockBean
@MockitoBean
private ObjectiveMapper objectiveMapper;
@MockBean
@MockitoBean
private KeyResultMapper keyResultMapper;
@MockBean
@MockitoBean
private DeserializerHelper deserializerHelper;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

@WithMockUser(value = "spring")
@ExtendWith(MockitoExtension.class)
@WebMvcTest(OverviewController.class)
@Import(OverviewMapper.class)
class OverviewControllerIT {
@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private OverviewAuthorizationService overviewAuthorizationService;
// Dashboard and OverviewMapper are required for testing
@SpyBean
private OverviewMapper overviewMapper;

public static final String PUZZLE = "Puzzle";
public static final String DESCRIPTION = "This is a description";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

Expand Down Expand Up @@ -57,7 +57,7 @@ class QuarterControllerIT {

@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private QuarterBusinessService quarterBusinessService;

@DisplayName("Should get all quarters")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;
Expand Down Expand Up @@ -72,9 +72,9 @@ class TeamControllerIT {

@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private TeamAuthorizationService teamAuthorizationService;
@MockBean
@MockitoBean
private TeamMapper teamMapper;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.server.ResponseStatusException;
Expand Down Expand Up @@ -64,11 +64,11 @@ class UserControllerIT {
static UserDto userBobDto = new UserDto(9L, 4, FIRST_NAME_2, LAST_NAME_2, EMAIL_2, new ArrayList<>(), false);
@Autowired
private MockMvc mvc;
@MockBean
@MockitoBean
private UserAuthorizationService userAuthorizationService;
@MockBean
@MockitoBean
private AuthorizationService authorizationService;
@MockBean
@MockitoBean
private UserMapper userMapper;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

@ExtendWith(MockitoExtension.class)
class TeamBusinessServiceTest {
@MockBean
@MockitoBean
TeamPersistenceService teamPersistenceService = Mockito.mock(TeamPersistenceService.class);
Team team1;
Team team2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

@ExtendWith(MockitoExtension.class)
class CheckInValidationServiceTest {
@MockBean
@MockitoBean
CheckInPersistenceService checkInPersistenceService = Mockito.mock(CheckInPersistenceService.class);

private final User user = User.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.web.server.ResponseStatusException;

@ExtendWith(MockitoExtension.class)
class CompletedValidationServiceTest {
@MockBean
@MockitoBean
CompletedPersistenceService completedPersistenceService = Mockito.mock(CompletedPersistenceService.class);

Completed validCompleted;
Expand Down
Loading