diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/redistestcontainers/service/ProductServiceManualTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/redistestcontainers/service/ProductServiceManualTest.java index 00c0c3a1f7..f0fcde5186 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/redistestcontainers/service/ProductServiceManualTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/redistestcontainers/service/ProductServiceManualTest.java @@ -1,14 +1,15 @@ package com.baeldung.redistestcontainers.service; -import com.baeldung.redistestcontainers.hash.Product; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.testcontainers.containers.GenericContainer; import org.testcontainers.utility.DockerImageName; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import com.baeldung.redistestcontainers.hash.Product; /** * Requires Docker running on the machine to run without errors @@ -76,4 +77,4 @@ public class ProductServiceManualTest { assertEquals("Test Product", productFromDb.getName()); assertEquals(10.0, productFromDb.getPrice()); } -} \ No newline at end of file +} diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java index b3d80a7d8b..c91a4e8408 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java @@ -1,10 +1,14 @@ package com.baeldung.testloglevel; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -15,13 +19,10 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; - @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) -@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) +@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) @ActiveProfiles("logback-test2") public class LogbackMultiProfileTestLogLevelIntegrationTest { diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java index f60a5e0ee3..d9e6a70b9c 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java @@ -1,10 +1,14 @@ package com.baeldung.testloglevel; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -15,13 +19,10 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; - @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) -@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) +@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) @ActiveProfiles("logback-test") public class LogbackTestLogLevelIntegrationTest { @@ -37,7 +38,8 @@ public class LogbackTestLogLevelIntegrationTest { public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintDebugLogsForOurPackage() { ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); - assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThat(response.getStatusCode() + .value()).isEqualTo(200); assertThatOutputContainsLogForOurPackage("DEBUG"); } @@ -45,7 +47,8 @@ public class LogbackTestLogLevelIntegrationTest { public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenNoDebugLogsForOtherPackages() { ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); - assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThat(response.getStatusCode() + .value()).isEqualTo(200); assertThatOutputDoesntContainLogForOtherPackages("DEBUG"); } @@ -53,7 +56,8 @@ public class LogbackTestLogLevelIntegrationTest { public void givenErrorRootLevelAndDebugLevelForOurPackage_whenCall_thenPrintErrorLogs() { ResponseEntity response = restTemplate.getForEntity(baseUrl, String.class); - assertThat(response.getStatusCode().value()).isEqualTo(200); + assertThat(response.getStatusCode() + .value()).isEqualTo(200); assertThatOutputContainsLogForOurPackage("ERROR"); assertThatOutputContainsLogForOtherPackages("ERROR"); } @@ -63,11 +67,13 @@ public class LogbackTestLogLevelIntegrationTest { } private void assertThatOutputDoesntContainLogForOtherPackages(String level) { - assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level); + assertThat(outputCapture.toString() + .replaceAll("(?m)^.*TestLogLevelController.*$", "")).doesNotContain(level); } private void assertThatOutputContainsLogForOtherPackages(String level) { - assertThat(outputCapture.toString().replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level); + assertThat(outputCapture.toString() + .replaceAll("(?m)^.*TestLogLevelController.*$", "")).contains(level); } } diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java index e59b673a1c..c68c84172f 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java @@ -1,10 +1,14 @@ package com.baeldung.testloglevel; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -15,13 +19,10 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; - @RunWith(SpringRunner.class) @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) -@EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) +@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class }) @ActiveProfiles("logging-test") public class TestLogLevelWithProfileIntegrationTest { diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java index ea9924193b..edd15090b8 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/webservice/ProductEndpointIntegrationTest.java @@ -1,6 +1,16 @@ package com.baeldung.webservice; -import com.baeldung.webservice.generated.Product; +import static org.mockito.Mockito.when; +import static org.springframework.ws.test.server.RequestCreators.withPayload; +import static org.springframework.ws.test.server.ResponseMatchers.noFault; +import static org.springframework.ws.test.server.ResponseMatchers.payload; +import static org.springframework.ws.test.server.ResponseMatchers.validPayload; +import static org.springframework.ws.test.server.ResponseMatchers.xpath; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest; @@ -9,16 +19,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.ws.test.server.MockWebServiceClient; import org.springframework.xml.transform.StringSource; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import static org.mockito.Mockito.when; -import static org.springframework.ws.test.server.RequestCreators.withPayload; -import static org.springframework.ws.test.server.ResponseMatchers.noFault; -import static org.springframework.ws.test.server.ResponseMatchers.payload; -import static org.springframework.ws.test.server.ResponseMatchers.validPayload; -import static org.springframework.ws.test.server.ResponseMatchers.xpath; +import com.baeldung.webservice.generated.Product; @WebServiceServerTest class ProductEndpointIntegrationTest { diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java index e9ee8f3951..3de2bc0949 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java @@ -1,15 +1,14 @@ package com.baeldung.xmlapplicationcontext; -import com.baeldung.xmlapplicationcontext.service.EmployeeService; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; - +import com.baeldung.xmlapplicationcontext.service.EmployeeService; @RunWith(SpringRunner.class) @SpringBootTest(classes = XmlBeanApplication.class) diff --git a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java index 0182d5dbb1..9ab590a8ea 100644 --- a/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing-2/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java @@ -1,6 +1,7 @@ package com.baeldung.xmlapplicationcontext; -import com.baeldung.xmlapplicationcontext.service.EmployeeService; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -9,7 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import static org.assertj.core.api.Assertions.assertThat; +import com.baeldung.xmlapplicationcontext.service.EmployeeService; @RunWith(SpringRunner.class) @SpringBootTest(classes = XmlBeanApplication.class)