Migrate tests to JUnit5

See gh-802
This commit is contained in:
Madhura Bhave
2019-01-23 18:34:09 -08:00
parent 2816c21631
commit ae937ca4bc
33 changed files with 92 additions and 66 deletions

View File

@@ -52,11 +52,26 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@@ -17,18 +17,15 @@
package io.spring.initializr.web;
import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Stephane Nicoll
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Config.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public abstract class AbstractFullStackInitializrIntegrationTests
extends AbstractInitializrIntegrationTests {

View File

@@ -21,6 +21,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -40,10 +41,9 @@ import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.Untar;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.TempDirectory;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
@@ -58,7 +58,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate;
@@ -67,7 +66,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@ExtendWith(TempDirectory.class)
@SpringBootTest(classes = Config.class)
public abstract class AbstractInitializrIntegrationTests {
@@ -76,17 +75,17 @@ public abstract class AbstractInitializrIntegrationTests {
private static final ObjectMapper objectMapper = new ObjectMapper();
@Rule
public final TemporaryFolder folder = new TemporaryFolder();
public File folder;
@Autowired
private RestTemplateBuilder restTemplateBuilder;
private RestTemplate restTemplate;
@Before
public void before() {
@BeforeEach
public void before(@TempDirectory.TempDir Path folder) {
this.restTemplate = this.restTemplateBuilder.build();
this.folder = folder.toFile();
}
protected abstract String createUrl(String context);
@@ -215,7 +214,7 @@ public abstract class AbstractInitializrIntegrationTests {
try {
File archiveFile = writeArchive(content);
File project = this.folder.newFolder();
File project = new File(this.folder, "project");
switch (archiveType) {
case ZIP:
unzip(archiveFile, project);
@@ -251,7 +250,7 @@ public abstract class AbstractInitializrIntegrationTests {
}
protected File writeArchive(byte[] body) throws IOException {
File archiveFile = this.folder.newFile();
File archiveFile = new File(this.folder, "archive");
try (FileOutputStream stream = new FileOutputStream(archiveFile)) {
stream.write(body);
}

View File

@@ -16,7 +16,7 @@
package io.spring.initializr.web.autoconfigure;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.mock.env.MockEnvironment;

View File

@@ -24,7 +24,7 @@ import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.util.TemplateRenderer;
import io.spring.initializr.web.project.MainController;
import io.spring.initializr.web.ui.UiController;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.DirectFieldAccessor;

View File

@@ -25,7 +25,7 @@ import io.spring.initializr.metadata.DependencyMetadata;
import io.spring.initializr.metadata.Repository;
import io.spring.initializr.util.Version;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -24,7 +24,7 @@ import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.Link;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -22,7 +22,7 @@ import java.util.List;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.spring.initializr.metadata.Link;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -18,7 +18,7 @@ package io.spring.initializr.web.project;
import io.spring.initializr.test.generator.PomAssert;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;

View File

@@ -18,7 +18,7 @@ package io.spring.initializr.web.project;
import io.spring.initializr.test.generator.PomAssert;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;

View File

@@ -19,7 +19,7 @@ package io.spring.initializr.web.project;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;

View File

@@ -20,7 +20,7 @@ import java.net.URI;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

View File

@@ -25,8 +25,8 @@ import io.spring.initializr.web.AbstractInitializrIntegrationTests;
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.http.HttpHeaders;
@@ -160,7 +160,7 @@ public class MainControllerIntegrationTests
}
@Test
@Ignore("Need a comparator that does not care about the number of elements in an array")
@Disabled("Need a comparator that does not care about the number of elements in an array")
public void currentMetadataCompatibleWithV2() {
ResponseEntity<String> response = invokeHome(null, "*/*");
validateMetadata(response,

View File

@@ -22,7 +22,7 @@ import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;

View File

@@ -20,7 +20,7 @@ import java.net.URI;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.http.HttpStatus;

View File

@@ -21,7 +21,7 @@ import io.spring.initializr.generator.ProjectRequestPostProcessor;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import io.spring.initializr.web.project.ProjectGenerationPostProcessorTests.ProjectRequestPostProcessorConfiguration;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -19,13 +19,16 @@ package io.spring.initializr.web.project;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import io.spring.initializr.test.generator.ProjectAssert;
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.TempDirectory;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
@@ -44,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer
* @author Stephane Nicoll
*/
@ExtendWith(TempDirectory.class)
@ActiveProfiles("test-default")
public class ProjectGenerationSmokeTests
extends AbstractFullStackInitializrIntegrationTests {
@@ -54,11 +58,11 @@ public class ProjectGenerationSmokeTests
private Action enterAction;
@Before
public void setup() throws IOException {
Assume.assumeTrue("Smoke tests disabled (set System property 'smoke.test')",
Boolean.getBoolean("smoke.test"));
this.downloadDir = this.folder.newFolder();
@BeforeEach
public void setup(@TempDirectory.TempDir Path folder) throws IOException {
Assumptions.assumeTrue(Boolean.getBoolean("smoke.test"),
"Smoke tests disabled (set System property 'smoke.test')");
this.downloadDir = folder.toFile();
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("browser.download.folderList", 2);
fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
@@ -74,7 +78,7 @@ public class ProjectGenerationSmokeTests
this.enterAction = actions.sendKeys(Keys.ENTER).build();
}
@After
@AfterEach
public void destroy() {
if (this.driver != null) {
this.driver.close();

View File

@@ -23,7 +23,7 @@ import io.spring.initializr.metadata.DependencyMetadataProvider;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import io.spring.initializr.util.Version;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -22,8 +22,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
@@ -49,7 +49,7 @@ public class DefaultInitializrMetadataProviderTests {
private MockRestServiceServer mockServer;
@Before
@BeforeEach
public void setUp() {
this.restTemplate = new RestTemplate();
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);

View File

@@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.spring.initializr.metadata.DefaultMetadataElement;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.MediaType;

View File

@@ -19,7 +19,7 @@ package io.spring.initializr.web.ui;
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;