Skip to content

Commit

Permalink
spring-boot: migrate mock/spy.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Dec 3, 2024
1 parent dff25f9 commit e71342a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
8 changes: 0 additions & 8 deletions generators/java/generators/graalvm/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ export default class GraalvmGenerator extends BaseApplicationGenerator {
extname(file.path) === '.java',
refresh: false,
},
passthrough(file => {
const contents = file.contents.toString('utf8');
if (/@(MockBean|SpyBean)/.test(contents) || (application.reactive && /@AuthenticationIntegrationTest/.test(contents))) {
file.contents = Buffer.from(
addJavaAnnotation(contents, { package: 'org.springframework.test.context.aot', annotation: 'DisabledInAotMode' }),
);
}
}),
);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
<%_ if (searchEngineElasticsearch) { _%>
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
<%_ } _%>
<%_ if (databaseTypeSql && !reactive && !authenticationTypeOauth2) { _%>
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.data.auditing.AuditingHandler;
import org.springframework.data.auditing.DateTimeProvider;
<%_ } _%>
Expand Down Expand Up @@ -181,15 +181,15 @@ class UserServiceIT {
*
* @see <%= packageName %>.repository.search.UserSearchRepositoryMockConfiguration
*/
@SpyBean
@MockitoSpyBean
private UserSearchRepository spiedUserSearchRepository;
<%_ } _%>
<%_ if (databaseTypeSql && !reactive && !authenticationTypeOauth2) { _%>

@Autowired
private AuditingHandler auditingHandler;

@MockBean
@MockitoBean
private DateTimeProvider dateTimeProvider;
<%_ } _%>
<%_ if (!databaseTypeNo) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
import <%= packageName %>.repository.UserRepository;
<%_ } _%>
<%_ if (reactive) { _%>
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
<%_ } _%>

Expand Down Expand Up @@ -54,12 +54,12 @@ public class JwtAuthenticationTestUtils {
}
<%_ if (reactive) { _%>

@MockBean
@MockitoBean
private ReactiveUserDetailsService userDetailsService;
<%_ } _%>
<%_ if (reactive && generateBuiltInUserEntity) { _%>

@MockBean
@MockitoBean
private UserRepository userRepository;
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -56,7 +56,7 @@ class CustomClaimConverterIT {

private final ObjectMapper mapper = new ObjectMapper();

@MockBean
@MockitoBean
private RestTemplate restTemplate;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import java.nio.charset.Charset;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -66,7 +66,7 @@ class MailServiceIT {
@Autowired
private JHipsterProperties jHipsterProperties;

@MockBean
@MockitoBean
private JavaMailSender javaMailSender;

@Captor
Expand Down

0 comments on commit e71342a

Please sign in to comment.