From 6704dec346a7db639ee23968454634cb15ebd72b Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 25 Feb 2021 23:45:12 +0100 Subject: [PATCH] JAVA-4397: Use random port for the GreetControllerRealIntegrationTest --- .../GreetControllerRealIntegrationTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java index 36751ba883..825520526e 100644 --- a/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java +++ b/spring-web-modules/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java @@ -1,22 +1,25 @@ package com.baeldung.web.controller; import io.restassured.RestAssured; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.context.TestPropertySource; -import static io.restassured.RestAssured.DEFAULT_PORT; import static io.restassured.RestAssured.given; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@SpringBootTest(webEnvironment = DEFINED_PORT) +@SpringBootTest(webEnvironment = RANDOM_PORT) @TestPropertySource(properties = {"spring.main.allow-bean-definition-overriding=true", "server.servlet.context-path=/"}) public class GreetControllerRealIntegrationTest { - @Before + @LocalServerPort + private int port; + + @BeforeEach public void setUp() { - RestAssured.port = DEFAULT_PORT; + RestAssured.port = port; } @Test