From 47c755435251a26f72cdf64ed8d04b5c84aa3954 Mon Sep 17 00:00:00 2001 From: luca Date: Fri, 10 Nov 2023 14:30:22 +0100 Subject: [PATCH 1/6] feat: override spring bean --- .../com/baeldung/overridebean/Endpoint.java | 19 ++++++++++ .../com/baeldung/overridebean/Service.java | 5 +++ .../baeldung/overridebean/ServiceImpl.java | 8 ++++ .../overridebean/basic/Application.java | 14 +++++++ .../baeldung/overridebean/basic/Config.java | 16 ++++++++ .../overridebean/conditional/Application.java | 14 +++++++ .../conditional/ConditionalConfig.java | 18 +++++++++ .../overridebean/profile/Application.java | 14 +++++++ .../overridebean/profile/ProfileConfig.java | 18 +++++++++ .../src/main/resources/application.properties | 1 + .../conditional/ConditionIntegrationTest.java | 29 +++++++++++++++ .../conditional/ConditionalStub.java | 10 +++++ .../conditional/ConditionalTestConfig.java | 17 +++++++++ .../mockbean/MockBeanIntegrationTest.java | 37 +++++++++++++++++++ ...OverrideBeanDefinitionIntegrationTest.java | 31 ++++++++++++++++ .../OverrideBeanDefinitionServiceStub.java | 10 +++++ .../OverrideBeanDefinitionTestConfig.java | 15 ++++++++ .../primary/PrimaryIntegrationTest.java | 31 ++++++++++++++++ .../primary/PrimaryServiceStub.java | 10 +++++ .../primary/PrimaryTestConfig.java | 17 +++++++++ .../profile/ProfileIntegrationTest.java | 29 +++++++++++++++ .../profile/ProfileServiceStub.java | 10 +++++ .../profile/ProfileTestConfig.java | 15 ++++++++ 23 files changed, 388 insertions(+) create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Endpoint.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Service.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/ServiceImpl.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Application.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Config.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/ConditionalConfig.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/ProfileConfig.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalStub.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionServiceStub.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionTestConfig.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryServiceStub.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryTestConfig.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileServiceStub.java create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Endpoint.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Endpoint.java new file mode 100644 index 0000000000..e199d1f25b --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Endpoint.java @@ -0,0 +1,19 @@ +package com.baeldung.overridebean; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class Endpoint { + + private final Service service; + + public Endpoint(Service service) { + this.service = service; + } + + @GetMapping("/hello") + public String helloWorldEndpoint() { + return service.helloWorld(); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Service.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Service.java new file mode 100644 index 0000000000..0872fcc372 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Service.java @@ -0,0 +1,5 @@ +package com.baeldung.overridebean; + +public interface Service { + String helloWorld(); +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/ServiceImpl.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/ServiceImpl.java new file mode 100644 index 0000000000..4d4b5582e6 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/ServiceImpl.java @@ -0,0 +1,8 @@ +package com.baeldung.overridebean; + +public class ServiceImpl implements Service { + + public String helloWorld() { + return "hello world"; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Application.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Application.java new file mode 100644 index 0000000000..6f9acde3d8 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Application.java @@ -0,0 +1,14 @@ +package com.baeldung.overridebean.basic; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; + +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Config.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Config.java new file mode 100644 index 0000000000..67d999958d --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Config.java @@ -0,0 +1,16 @@ +package com.baeldung.overridebean.basic; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.overridebean.Service; +import com.baeldung.overridebean.ServiceImpl; + +@Configuration +public class Config { + + @Bean + public Service helloWorld() { + return new ServiceImpl(); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java new file mode 100644 index 0000000000..9c4cdbf8ec --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java @@ -0,0 +1,14 @@ +package com.baeldung.overridebean.conditional; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; + +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/ConditionalConfig.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/ConditionalConfig.java new file mode 100644 index 0000000000..e18689e042 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/ConditionalConfig.java @@ -0,0 +1,18 @@ +package com.baeldung.overridebean.conditional; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.overridebean.Service; +import com.baeldung.overridebean.ServiceImpl; + +@Configuration +public class ConditionalConfig { + + @Bean + @ConditionalOnProperty(name = "service.stub", havingValue = "false") + public Service helloWorld() { + return new ServiceImpl(); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java new file mode 100644 index 0000000000..d3298b2eb4 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java @@ -0,0 +1,14 @@ +package com.baeldung.overridebean.profile; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; + +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/ProfileConfig.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/ProfileConfig.java new file mode 100644 index 0000000000..64cdfff8a5 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/ProfileConfig.java @@ -0,0 +1,18 @@ +package com.baeldung.overridebean.profile; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import com.baeldung.overridebean.Service; +import com.baeldung.overridebean.ServiceImpl; + +@Configuration +@Profile("prod") +public class ProfileConfig { + + @Bean + public Service helloWorld() { + return new ServiceImpl(); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/resources/application.properties b/spring-boot-modules/spring-boot-testing-2/src/main/resources/application.properties index b628a708bd..0982b7bac0 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-testing-2/src/main/resources/application.properties @@ -1,2 +1,3 @@ keycloak.enabled=true spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8180/auth/realms/baeldung-api +service.stub=false \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java new file mode 100644 index 0000000000..5f6b1d128f --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java @@ -0,0 +1,29 @@ +package com.baeldung.overridebean.conditional; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.overridebean.Endpoint; + +@SpringBootTest(classes = { Application.class, ConditionalConfig.class, Endpoint.class, ConditionalTestConfig.class }, properties = "service.stub=true") +@AutoConfigureMockMvc +class ConditionIntegrationTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void givenConditionalConfig_whenServiceStubIsTrue_thenStubOk() throws Exception { + this.mockMvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("hello conditional stub"))); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalStub.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalStub.java new file mode 100644 index 0000000000..6b3e447108 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalStub.java @@ -0,0 +1,10 @@ +package com.baeldung.overridebean.conditional; + +import com.baeldung.overridebean.Service; + +public class ConditionalStub implements Service { + + public String helloWorld() { + return "hello conditional stub"; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java new file mode 100644 index 0000000000..c48c4e2266 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java @@ -0,0 +1,17 @@ +package com.baeldung.overridebean.conditional; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +import com.baeldung.overridebean.Service; + +@TestConfiguration +public class ConditionalTestConfig { + + @ConditionalOnProperty(name = "service.stub", havingValue = "true") + @Bean + public Service helloWorld() { + return new ConditionalStub(); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java new file mode 100644 index 0000000000..6a7be1cbda --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java @@ -0,0 +1,37 @@ +package com.baeldung.overridebean.mockbean; + +import static org.hamcrest.Matchers.containsString; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.overridebean.Endpoint; +import com.baeldung.overridebean.Service; +import com.baeldung.overridebean.basic.Application; + +@SpringBootTest(classes = { Application.class, Endpoint.class }) +@AutoConfigureMockMvc +class MockBeanIntegrationTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private Service serviceExample; + + @Test + void givenServiceMockBean_whenGetHelloEndpoint_thenMockOk() throws Exception { + when(serviceExample.helloWorld()).thenReturn("hello mock bean"); + this.mockMvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("hello mock bean"))); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java new file mode 100644 index 0000000000..0f3753ef34 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java @@ -0,0 +1,31 @@ +package com.baeldung.overridebean.overridebeandefinition; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.overridebean.Endpoint; +import com.baeldung.overridebean.basic.Application; +import com.baeldung.overridebean.basic.Config; + +@SpringBootTest(classes = { Application.class, Config.class, Endpoint.class, OverrideBeanDefinitionTestConfig.class }, properties = "spring.main.allow-bean-definition-overriding=true") +@AutoConfigureMockMvc +class OverrideBeanDefinitionIntegrationTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void givenNoProfile_whenAllowBeanDefinitionOverriding_thenStubOk() throws Exception { + this.mockMvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("hello no profile stub"))); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionServiceStub.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionServiceStub.java new file mode 100644 index 0000000000..d06b43cf24 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionServiceStub.java @@ -0,0 +1,10 @@ +package com.baeldung.overridebean.overridebeandefinition; + +import com.baeldung.overridebean.Service; + +public class OverrideBeanDefinitionServiceStub implements Service { + + public String helloWorld() { + return "hello no profile stub"; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionTestConfig.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionTestConfig.java new file mode 100644 index 0000000000..5c35304296 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionTestConfig.java @@ -0,0 +1,15 @@ +package com.baeldung.overridebean.overridebeandefinition; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +import com.baeldung.overridebean.Service; + +@TestConfiguration +public class OverrideBeanDefinitionTestConfig { + + @Bean + public Service helloWorld() { + return new OverrideBeanDefinitionServiceStub(); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java new file mode 100644 index 0000000000..2bddfd4637 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java @@ -0,0 +1,31 @@ +package com.baeldung.overridebean.primary; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.overridebean.Endpoint; +import com.baeldung.overridebean.basic.Application; +import com.baeldung.overridebean.basic.Config; + +@SpringBootTest(classes = { Application.class, Config.class, Endpoint.class, PrimaryTestConfig.class }) +@AutoConfigureMockMvc +class PrimaryIntegrationTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void givenTestConfiguration_whenPrimaryBeanIsDefined_thenStubOk() throws Exception { + this.mockMvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("hello primary stub"))); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryServiceStub.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryServiceStub.java new file mode 100644 index 0000000000..1d3d887f99 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryServiceStub.java @@ -0,0 +1,10 @@ +package com.baeldung.overridebean.primary; + +import com.baeldung.overridebean.Service; + +public class PrimaryServiceStub implements Service { + + public String helloWorld() { + return "hello primary stub"; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryTestConfig.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryTestConfig.java new file mode 100644 index 0000000000..3765377b41 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryTestConfig.java @@ -0,0 +1,17 @@ +package com.baeldung.overridebean.primary; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; + +import com.baeldung.overridebean.Service; + +@TestConfiguration +public class PrimaryTestConfig { + + @Primary + @Bean("service.stub") + public Service helloWorld() { + return new PrimaryServiceStub(); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java new file mode 100644 index 0000000000..deabfea9e5 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java @@ -0,0 +1,29 @@ +package com.baeldung.overridebean.profile; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.overridebean.Endpoint; + +@SpringBootTest(classes = { Application.class, ProfileConfig.class, Endpoint.class, ProfileTestConfig.class }) +@AutoConfigureMockMvc +class ProfileIntegrationTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void givenConfigurationWithProfile_whenNoProductionProfileIsActive_thenStubOk() throws Exception { + this.mockMvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("hello profile stub"))); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileServiceStub.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileServiceStub.java new file mode 100644 index 0000000000..ef1f2e7a22 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileServiceStub.java @@ -0,0 +1,10 @@ +package com.baeldung.overridebean.profile; + +import com.baeldung.overridebean.Service; + +public class ProfileServiceStub implements Service { + + public String helloWorld() { + return "hello profile stub"; + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java new file mode 100644 index 0000000000..edd33162e0 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java @@ -0,0 +1,15 @@ +package com.baeldung.overridebean.profile; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +import com.baeldung.overridebean.Service; + +@TestConfiguration +public class ProfileTestConfig { + + @Bean + public Service helloWorld() { + return new ProfileServiceStub(); + } +} From 1e13611b4de219f646c491eeb382e5a04bfac856 Mon Sep 17 00:00:00 2001 From: luca Date: Fri, 10 Nov 2023 15:09:18 +0100 Subject: [PATCH 2/6] Trigger Jenkins From 25a02eb86de26a26bb983f4dfa357480d8384247 Mon Sep 17 00:00:00 2001 From: luca Date: Mon, 13 Nov 2023 12:24:40 +0100 Subject: [PATCH 3/6] fix: add only one spring boot app --- .../baeldung/overridebean/{basic => }/Config.java | 5 +---- .../overridebean/{basic => boot}/Application.java | 2 +- .../overridebean/conditional/Application.java | 14 -------------- .../baeldung/overridebean/profile/Application.java | 14 -------------- .../conditional/ConditionIntegrationTest.java | 1 + .../mockbean/MockBeanIntegrationTest.java | 2 +- .../OverrideBeanDefinitionIntegrationTest.java | 4 ++-- .../primary/PrimaryIntegrationTest.java | 4 ++-- .../profile/ProfileIntegrationTest.java | 1 + 9 files changed, 9 insertions(+), 38 deletions(-) rename spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/{basic => }/Config.java (64%) rename spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/{basic => boot}/Application.java (93%) delete mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java delete mode 100644 spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Config.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Config.java similarity index 64% rename from spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Config.java rename to spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Config.java index 67d999958d..f0892338f8 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Config.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/Config.java @@ -1,11 +1,8 @@ -package com.baeldung.overridebean.basic; +package com.baeldung.overridebean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.baeldung.overridebean.Service; -import com.baeldung.overridebean.ServiceImpl; - @Configuration public class Config { diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Application.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/boot/Application.java similarity index 93% rename from spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Application.java rename to spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/boot/Application.java index 6f9acde3d8..1eb0012493 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/basic/Application.java +++ b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/boot/Application.java @@ -1,4 +1,4 @@ -package com.baeldung.overridebean.basic; +package com.baeldung.overridebean.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java deleted file mode 100644 index 9c4cdbf8ec..0000000000 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/conditional/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.overridebean.conditional; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; - -@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } -} diff --git a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java b/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java deleted file mode 100644 index d3298b2eb4..0000000000 --- a/spring-boot-modules/spring-boot-testing-2/src/main/java/com/baeldung/overridebean/profile/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.overridebean.profile; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; - -@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } -} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java index 5f6b1d128f..b3a5164ff5 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionIntegrationTest.java @@ -12,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.servlet.MockMvc; import com.baeldung.overridebean.Endpoint; +import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, ConditionalConfig.class, Endpoint.class, ConditionalTestConfig.class }, properties = "service.stub=true") @AutoConfigureMockMvc diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java index 6a7be1cbda..2ece28482d 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java @@ -15,7 +15,7 @@ import org.springframework.test.web.servlet.MockMvc; import com.baeldung.overridebean.Endpoint; import com.baeldung.overridebean.Service; -import com.baeldung.overridebean.basic.Application; +import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, Endpoint.class }) @AutoConfigureMockMvc diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java index 0f3753ef34..a8dba58b79 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/overridebeandefinition/OverrideBeanDefinitionIntegrationTest.java @@ -11,9 +11,9 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.servlet.MockMvc; +import com.baeldung.overridebean.Config; import com.baeldung.overridebean.Endpoint; -import com.baeldung.overridebean.basic.Application; -import com.baeldung.overridebean.basic.Config; +import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, Config.class, Endpoint.class, OverrideBeanDefinitionTestConfig.class }, properties = "spring.main.allow-bean-definition-overriding=true") @AutoConfigureMockMvc diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java index 2bddfd4637..b6061c86d5 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/primary/PrimaryIntegrationTest.java @@ -11,9 +11,9 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.servlet.MockMvc; +import com.baeldung.overridebean.Config; import com.baeldung.overridebean.Endpoint; -import com.baeldung.overridebean.basic.Application; -import com.baeldung.overridebean.basic.Config; +import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, Config.class, Endpoint.class, PrimaryTestConfig.class }) @AutoConfigureMockMvc diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java index deabfea9e5..7f4aae026c 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java @@ -12,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.servlet.MockMvc; import com.baeldung.overridebean.Endpoint; +import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, ProfileConfig.class, Endpoint.class, ProfileTestConfig.class }) @AutoConfigureMockMvc From f20a18ed9b97ead5c6f6e67f55993d3acc4c12dc Mon Sep 17 00:00:00 2001 From: luca Date: Tue, 14 Nov 2023 10:28:22 +0100 Subject: [PATCH 4/6] clean, add mock example --- .../conditional/ConditionalTestConfig.java | 2 +- .../mockbean/MockBeanIntegrationTest.java | 4 +- .../profile/ProfileIntegrationMockTest.java | 38 +++++++++++++++++++ ...t.java => ProfileIntegrationStubTest.java} | 6 ++- .../profile/ProfileTestConfig.java | 12 +++++- 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationMockTest.java rename spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/{ProfileIntegrationTest.java => ProfileIntegrationStubTest.java} (84%) diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java index c48c4e2266..ce82b43df0 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/conditional/ConditionalTestConfig.java @@ -9,8 +9,8 @@ import com.baeldung.overridebean.Service; @TestConfiguration public class ConditionalTestConfig { - @ConditionalOnProperty(name = "service.stub", havingValue = "true") @Bean + @ConditionalOnProperty(name = "service.stub", havingValue = "true") public Service helloWorld() { return new ConditionalStub(); } diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java index 2ece28482d..9a63ad4113 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/mockbean/MockBeanIntegrationTest.java @@ -25,11 +25,11 @@ class MockBeanIntegrationTest { private MockMvc mockMvc; @MockBean - private Service serviceExample; + private Service service; @Test void givenServiceMockBean_whenGetHelloEndpoint_thenMockOk() throws Exception { - when(serviceExample.helloWorld()).thenReturn("hello mock bean"); + when(service.helloWorld()).thenReturn("hello mock bean"); this.mockMvc.perform(get("/hello")) .andExpect(status().isOk()) .andExpect(content().string(containsString("hello mock bean"))); diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationMockTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationMockTest.java new file mode 100644 index 0000000000..43fb69860d --- /dev/null +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationMockTest.java @@ -0,0 +1,38 @@ +package com.baeldung.overridebean.profile; + +import static org.hamcrest.Matchers.containsString; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.overridebean.Endpoint; +import com.baeldung.overridebean.Service; +import com.baeldung.overridebean.boot.Application; + +@SpringBootTest(classes = { Application.class, ProfileConfig.class, Endpoint.class, ProfileTestConfig.class }) +@AutoConfigureMockMvc +@ActiveProfiles("mock") +class ProfileIntegrationMockTest { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private Service service; + + @Test + void givenConfigurationWithProfile_whenTestProfileIsActive_thenMockOk() throws Exception { + when(service.helloWorld()).thenReturn("hello profile mock"); + this.mockMvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("hello profile mock"))); + } +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationStubTest.java similarity index 84% rename from spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java rename to spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationStubTest.java index 7f4aae026c..e1c88f2a31 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationStubTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import com.baeldung.overridebean.Endpoint; @@ -16,13 +17,14 @@ import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, ProfileConfig.class, Endpoint.class, ProfileTestConfig.class }) @AutoConfigureMockMvc -class ProfileIntegrationTest { +@ActiveProfiles("stub") +class ProfileIntegrationStubTest { @Autowired private MockMvc mockMvc; @Test - void givenConfigurationWithProfile_whenNoProductionProfileIsActive_thenStubOk() throws Exception { + void givenConfigurationWithProfile_whenTestProfileIsActive_thenStubOk() throws Exception { this.mockMvc.perform(get("/hello")) .andExpect(status().isOk()) .andExpect(content().string(containsString("hello profile stub"))); diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java index edd33162e0..7e1de309d3 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileTestConfig.java @@ -1,7 +1,10 @@ package com.baeldung.overridebean.profile; +import static org.mockito.Mockito.mock; + import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Profile; import com.baeldung.overridebean.Service; @@ -9,7 +12,14 @@ import com.baeldung.overridebean.Service; public class ProfileTestConfig { @Bean - public Service helloWorld() { + @Profile("stub") + public Service helloWorldStub() { return new ProfileServiceStub(); } + + @Bean + @Profile("mock") + public Service helloWorldMock() { + return mock(Service.class); + } } From 7f88b9748e82bd6b51f37ae9bfb6981a062a9b98 Mon Sep 17 00:00:00 2001 From: Maiklins Date: Fri, 17 Nov 2023 21:24:13 +0100 Subject: [PATCH 5/6] Update and rename ProfileIntegrationStubTest.java to ProfileStubIntegrationTest.java Satisfy test naming convention --- ...IntegrationStubTest.java => ProfileStubIntegrationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/{ProfileIntegrationStubTest.java => ProfileStubIntegrationTest.java} (97%) diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationStubTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileStubIntegrationTest.java similarity index 97% rename from spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationStubTest.java rename to spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileStubIntegrationTest.java index e1c88f2a31..2d6eb06d32 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationStubTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileStubIntegrationTest.java @@ -18,7 +18,7 @@ import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, ProfileConfig.class, Endpoint.class, ProfileTestConfig.class }) @AutoConfigureMockMvc @ActiveProfiles("stub") -class ProfileIntegrationStubTest { +class ProfileStubIntegrationTest { @Autowired private MockMvc mockMvc; From 92ef912fcf29b2fd755560dad3fdcdf67a89fb59 Mon Sep 17 00:00:00 2001 From: Maiklins Date: Fri, 17 Nov 2023 21:24:57 +0100 Subject: [PATCH 6/6] Update and rename ProfileIntegrationMockTest.java to ProfileMockIntegrationTest.java Satisfy naming convention --- ...IntegrationMockTest.java => ProfileMockIntegrationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/{ProfileIntegrationMockTest.java => ProfileMockIntegrationTest.java} (97%) diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationMockTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileMockIntegrationTest.java similarity index 97% rename from spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationMockTest.java rename to spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileMockIntegrationTest.java index 43fb69860d..2fac6d954a 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileIntegrationMockTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/overridebean/profile/ProfileMockIntegrationTest.java @@ -20,7 +20,7 @@ import com.baeldung.overridebean.boot.Application; @SpringBootTest(classes = { Application.class, ProfileConfig.class, Endpoint.class, ProfileTestConfig.class }) @AutoConfigureMockMvc @ActiveProfiles("mock") -class ProfileIntegrationMockTest { +class ProfileMockIntegrationTest { @Autowired private MockMvc mockMvc;