Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,19 +16,17 @@
|
||||
|
||||
package org.springframework.boot.cli;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration Tests for the command line application.
|
||||
@@ -36,56 +34,52 @@ import static org.junit.Assert.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class CommandLineIT {
|
||||
class CommandLineIT {
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
private CommandLineInvoker cli;
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker(this.temp);
|
||||
@BeforeEach
|
||||
public void setup(@TempDir File tempDir) {
|
||||
this.cli = new CommandLineInvoker(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hintProducesListOfValidCommands()
|
||||
@Test void hintProducesListOfValidCommands()
|
||||
throws IOException, InterruptedException {
|
||||
Invocation cli = this.cli.invoke("hint");
|
||||
assertThat(cli.await(), equalTo(0));
|
||||
assertThat("Unexpected error: \n" + cli.getErrorOutput(),
|
||||
cli.getErrorOutput().length(), equalTo(0));
|
||||
assertThat(cli.getStandardOutputLines().size(), equalTo(11));
|
||||
assertThat(cli.await()).isEqualTo(0);
|
||||
assertThat(cli.getErrorOutput()).isEmpty();
|
||||
assertThat(cli.getStandardOutputLines()).hasSize(11);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokingWithNoArgumentsDisplaysHelp()
|
||||
@Test void invokingWithNoArgumentsDisplaysHelp()
|
||||
throws IOException, InterruptedException {
|
||||
Invocation cli = this.cli.invoke();
|
||||
assertThat(cli.await(), equalTo(1));
|
||||
assertThat(cli.getErrorOutput().length(), equalTo(0));
|
||||
assertThat(cli.getStandardOutput(), startsWith("usage:"));
|
||||
assertThat(cli.await()).isEqualTo(1);
|
||||
assertThat(cli.getErrorOutput()).isEmpty();
|
||||
assertThat(cli.getStandardOutput()).startsWith("usage:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unrecognizedCommandsAreHandledGracefully()
|
||||
@Test void unrecognizedCommandsAreHandledGracefully()
|
||||
throws IOException, InterruptedException {
|
||||
Invocation cli = this.cli.invoke("not-a-real-command");
|
||||
assertThat(cli.await(), equalTo(1));
|
||||
assertThat(cli.getErrorOutput(),
|
||||
containsString("'not-a-real-command' is not a valid command"));
|
||||
assertThat(cli.getStandardOutput().length(), equalTo(0));
|
||||
assertThat(cli.await()).isEqualTo(1);
|
||||
assertThat(cli.getErrorOutput())
|
||||
.contains("'not-a-real-command' is not a valid command");
|
||||
assertThat(cli.getStandardOutput()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void version() throws IOException, InterruptedException {
|
||||
@Test void version() throws IOException, InterruptedException {
|
||||
Invocation cli = this.cli.invoke("version");
|
||||
assertThat(cli.await(), equalTo(0));
|
||||
assertThat(cli.getErrorOutput().length(), equalTo(0));
|
||||
assertThat(cli.getStandardOutput(), startsWith("Spring CLI v"));
|
||||
assertThat(cli.await()).isEqualTo(0);
|
||||
assertThat(cli.getErrorOutput()).isEmpty();
|
||||
assertThat(cli.getStandardOutput()).startsWith("Spring CLI v");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void help() throws IOException, InterruptedException {
|
||||
@Test void help() throws IOException, InterruptedException {
|
||||
Invocation cli = this.cli.invoke("help");
|
||||
assertThat(cli.await(), equalTo(1));
|
||||
assertThat(cli.getErrorOutput().length(), equalTo(0));
|
||||
assertThat(cli.getStandardOutput(), startsWith("usage:"));
|
||||
assertThat(cli.await()).isEqualTo(1);
|
||||
assertThat(cli.getErrorOutput()).isEmpty();
|
||||
assertThat(cli.getStandardOutput()).startsWith("usage:");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,21 +18,16 @@ package org.springframework.boot.cli;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.cli.command.archive.JarCommand;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation;
|
||||
import org.springframework.boot.loader.tools.JavaExecutable;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration test for {@link JarCommand}.
|
||||
@@ -40,51 +35,52 @@ import static org.junit.Assert.assertTrue;
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JarCommandIT {
|
||||
class JarCommandIT {
|
||||
|
||||
private static final boolean JAVA_9_OR_LATER = isClassPresent(
|
||||
"java.security.cert.URICertStoreParameters");
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
private CommandLineInvoker cli;
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker(
|
||||
new File("src/it/resources/jar-command"), this.temp);
|
||||
private File tempDir;
|
||||
|
||||
@Test
|
||||
public void noArguments() throws Exception {
|
||||
@BeforeEach
|
||||
public void setup(@TempDir File tempDir) {
|
||||
this.cli = new CommandLineInvoker(new File("src/it/resources/jar-command"),
|
||||
tempDir);
|
||||
this.tempDir = tempDir;
|
||||
}
|
||||
|
||||
@Test void noArguments() throws Exception {
|
||||
Invocation invocation = this.cli.invoke("jar");
|
||||
invocation.await();
|
||||
assertThat(invocation.getStandardOutput(), equalTo(""));
|
||||
assertThat(invocation.getErrorOutput(), containsString("The name of the "
|
||||
+ "resulting jar and at least one source file must be specified"));
|
||||
assertThat(invocation.getStandardOutput()).isEqualTo("");
|
||||
assertThat(invocation.getErrorOutput()).contains("The name of the "
|
||||
+ "resulting jar and at least one source file must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noSources() throws Exception {
|
||||
@Test void noSources() throws Exception {
|
||||
Invocation invocation = this.cli.invoke("jar", "test-app.jar");
|
||||
invocation.await();
|
||||
assertThat(invocation.getStandardOutput(), equalTo(""));
|
||||
assertThat(invocation.getErrorOutput(), containsString("The name of the "
|
||||
+ "resulting jar and at least one source file must be specified"));
|
||||
assertThat(invocation.getStandardOutput()).isEqualTo("");
|
||||
assertThat(invocation.getErrorOutput()).contains("The name of the "
|
||||
+ "resulting jar and at least one source file must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarCreationWithGrabResolver() throws Exception {
|
||||
File jar = new File(this.temp.getRoot(), "test-app.jar");
|
||||
@Test void jarCreationWithGrabResolver() throws Exception {
|
||||
File jar = new File(this.tempDir, "test-app.jar");
|
||||
Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(),
|
||||
"bad.groovy");
|
||||
invocation.await();
|
||||
if (!JAVA_9_OR_LATER) {
|
||||
assertThat(invocation.getErrorOutput(), equalTo(""));
|
||||
assertThat(invocation.getErrorOutput()).isEqualTo("");
|
||||
}
|
||||
invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "bad.groovy");
|
||||
invocation.await();
|
||||
if (!JAVA_9_OR_LATER) {
|
||||
assertEquals(invocation.getErrorOutput(), 0,
|
||||
invocation.getErrorOutput().length());
|
||||
assertThat(invocation.getErrorOutput()).isEmpty();
|
||||
}
|
||||
assertTrue(jar.exists());
|
||||
assertThat(jar).exists();
|
||||
|
||||
Process process = new JavaExecutable()
|
||||
.processBuilder("-jar", jar.getAbsolutePath()).start();
|
||||
@@ -92,21 +88,19 @@ public class JarCommandIT {
|
||||
invocation.await();
|
||||
|
||||
if (!JAVA_9_OR_LATER) {
|
||||
assertThat(invocation.getErrorOutput(), equalTo(""));
|
||||
assertThat(invocation.getErrorOutput()).isEqualTo("");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarCreation() throws Exception {
|
||||
File jar = new File(this.temp.getRoot(), "test-app.jar");
|
||||
@Test void jarCreation() throws Exception {
|
||||
File jar = new File(this.tempDir, "test-app.jar");
|
||||
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
|
||||
"jar.groovy");
|
||||
invocation.await();
|
||||
if (!JAVA_9_OR_LATER) {
|
||||
assertEquals(invocation.getErrorOutput(), 0,
|
||||
invocation.getErrorOutput().length());
|
||||
assertThat(invocation.getErrorOutput()).isEmpty();
|
||||
}
|
||||
assertTrue(jar.exists());
|
||||
assertThat(jar).exists();
|
||||
|
||||
Process process = new JavaExecutable()
|
||||
.processBuilder("-jar", jar.getAbsolutePath()).start();
|
||||
@@ -114,33 +108,25 @@ public class JarCommandIT {
|
||||
invocation.await();
|
||||
|
||||
if (!JAVA_9_OR_LATER) {
|
||||
assertThat(invocation.getErrorOutput(), equalTo(""));
|
||||
assertThat(invocation.getErrorOutput()).isEqualTo("");
|
||||
}
|
||||
assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/BOOT-INF/classes!/public/public.txt"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/BOOT-INF/classes!/resources/resource.txt"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/BOOT-INF/classes!/static/static.txt"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/BOOT-INF/classes!/templates/template.txt"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/BOOT-INF/classes!/root.properties"));
|
||||
assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
|
||||
assertThat(invocation.getStandardOutput()).contains("Hello World!")
|
||||
.contains("/BOOT-INF/classes!/public/public.txt")
|
||||
.contains("/BOOT-INF/classes!/resources/resource.txt")
|
||||
.contains("/BOOT-INF/classes!/static/static.txt")
|
||||
.contains("/BOOT-INF/classes!/templates/template.txt")
|
||||
.contains("/BOOT-INF/classes!/root.properties").contains("Goodbye Mama");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarCreationWithIncludes() throws Exception {
|
||||
File jar = new File(this.temp.getRoot(), "test-app.jar");
|
||||
@Test void jarCreationWithIncludes() throws Exception {
|
||||
File jar = new File(this.tempDir, "test-app.jar");
|
||||
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "--include",
|
||||
"-public/**,-resources/**", "jar.groovy");
|
||||
invocation.await();
|
||||
if (!JAVA_9_OR_LATER) {
|
||||
assertEquals(invocation.getErrorOutput(), 0,
|
||||
invocation.getErrorOutput().length());
|
||||
assertThat(invocation.getErrorOutput()).isEmpty();
|
||||
}
|
||||
assertTrue(jar.exists());
|
||||
assertThat(jar).exists();
|
||||
|
||||
Process process = new JavaExecutable()
|
||||
.processBuilder("-jar", jar.getAbsolutePath()).start();
|
||||
@@ -148,17 +134,12 @@ public class JarCommandIT {
|
||||
invocation.await();
|
||||
|
||||
if (!JAVA_9_OR_LATER) {
|
||||
assertThat(invocation.getErrorOutput(), equalTo(""));
|
||||
assertThat(invocation.getErrorOutput()).isEqualTo("");
|
||||
}
|
||||
assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
not(containsString("/public/public.txt")));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
not(containsString("/resources/resource.txt")));
|
||||
assertThat(invocation.getStandardOutput(), containsString("/static/static.txt"));
|
||||
assertThat(invocation.getStandardOutput(),
|
||||
containsString("/templates/template.txt"));
|
||||
assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
|
||||
assertThat(invocation.getStandardOutput()).contains("Hello World!")
|
||||
.doesNotContain("/public/public.txt")
|
||||
.doesNotContain("/resources/resource.txt").contains("/static/static.txt")
|
||||
.contains("/templates/template.txt").contains("Goodbye Mama");
|
||||
}
|
||||
|
||||
private static boolean isClassPresent(String name) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,9 @@ package org.springframework.boot.cli;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.cli.command.archive.WarCommand;
|
||||
import org.springframework.boot.cli.infrastructure.CommandLineInvoker;
|
||||
@@ -35,17 +35,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andrey Stolyarov
|
||||
* @author Henri Kerola
|
||||
*/
|
||||
public class WarCommandIT {
|
||||
class WarCommandIT {
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
private CommandLineInvoker cli;
|
||||
|
||||
private final CommandLineInvoker cli = new CommandLineInvoker(
|
||||
new File("src/it/resources/war-command"), this.temp);
|
||||
private File tempDir;
|
||||
|
||||
@Test
|
||||
public void warCreation() throws Exception {
|
||||
File war = new File(this.temp.getRoot(), "test-app.war");
|
||||
@BeforeEach
|
||||
public void setup(@TempDir File tempDir) {
|
||||
this.cli = new CommandLineInvoker(new File("src/it/resources/war-command"),
|
||||
tempDir);
|
||||
this.tempDir = tempDir;
|
||||
}
|
||||
|
||||
@Test void warCreation() throws Exception {
|
||||
File war = new File(this.tempDir, "test-app.war");
|
||||
Invocation invocation = this.cli.invoke("war", war.getAbsolutePath(),
|
||||
"war.groovy");
|
||||
invocation.await();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,8 +32,6 @@ import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.testsupport.BuildOutput;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StreamUtils;
|
||||
@@ -49,13 +47,13 @@ public final class CommandLineInvoker {
|
||||
|
||||
private final File workingDirectory;
|
||||
|
||||
private final TemporaryFolder temp;
|
||||
private final File temp;
|
||||
|
||||
public CommandLineInvoker(TemporaryFolder temp) {
|
||||
public CommandLineInvoker(File temp) {
|
||||
this(new File("."), temp);
|
||||
}
|
||||
|
||||
public CommandLineInvoker(File workingDirectory, TemporaryFolder temp) {
|
||||
public CommandLineInvoker(File workingDirectory, File temp) {
|
||||
this.workingDirectory = workingDirectory;
|
||||
this.temp = temp;
|
||||
}
|
||||
@@ -75,7 +73,7 @@ public final class CommandLineInvoker {
|
||||
}
|
||||
|
||||
private File findLaunchScript() throws IOException {
|
||||
File unpacked = new File(this.temp.getRoot(), "unpacked-cli");
|
||||
File unpacked = new File(this.temp, "unpacked-cli");
|
||||
if (!unpacked.isDirectory()) {
|
||||
File zip = new BuildOutput(getClass()).getRootLocation()
|
||||
.listFiles((pathname) -> pathname.getName().endsWith("-bin.zip"))[0];
|
||||
|
||||
Reference in New Issue
Block a user