Move tests to JUnit 5 wherever possible

This commit is contained in:
Andy Wilkinson
2019-05-24 11:24:29 +01:00
parent 36f56d034a
commit b18fffaf14
1320 changed files with 13424 additions and 14185 deletions

View File

@@ -16,8 +16,12 @@
package org.springframework.boot.cli;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
@@ -26,13 +30,18 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
*/
public class ClassLoaderIntegrationTests {
@ExtendWith(OutputCaptureExtension.class)
class ClassLoaderIntegrationTests {
@Rule
public CliTester cli = new CliTester("src/test/resources/");
@RegisterExtension
private CliTester cli;
ClassLoaderIntegrationTests(CapturedOutput capturedOutput) {
this.cli = new CliTester("src/test/resources/", capturedOutput);
}
@Test
public void runWithIsolatedClassLoader() throws Exception {
void runWithIsolatedClassLoader() throws Exception {
// CLI classes or dependencies should not be exposed to the app
String output = this.cli.run("classloader-test-app.groovy", SpringCli.class.getName());
assertThat(output).contains("HasClasses-false-true-false");

View File

@@ -19,11 +19,13 @@ package org.springframework.boot.cli;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
@@ -31,36 +33,37 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.junit.Assume;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.boot.cli.command.AbstractCommand;
import org.springframework.boot.cli.command.OptionParsingCommand;
import org.springframework.boot.cli.command.archive.JarCommand;
import org.springframework.boot.cli.command.grab.GrabCommand;
import org.springframework.boot.cli.command.run.RunCommand;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.testsupport.BuildOutput;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StringUtils;
/**
* {@link TestRule} that can be used to invoke CLI commands.
* JUnit 5 {@link Extension} that can be used to invoke CLI commands.
*
* @author Phillip Webb
* @author Dave Syer
* @author Andy Wilkinson
*/
public class CliTester implements TestRule {
public class CliTester implements BeforeEachCallback, AfterEachCallback {
private final TemporaryFolder temp = new TemporaryFolder();
private final File temp;
private final BuildOutput buildOutput = new BuildOutput(getClass());
private final OutputCaptureRule outputCapture = new OutputCaptureRule();
private final CapturedOutput capturedOutput;
private String previousOutput = "";
@@ -72,8 +75,15 @@ public class CliTester implements TestRule {
private File serverPortFile;
public CliTester(String prefix) {
public CliTester(String prefix, CapturedOutput capturedOutput) {
this.prefix = prefix;
try {
this.temp = Files.createTempDirectory("cli-tester").toFile();
}
catch (IOException ex) {
throw new IllegalStateException("Failed to create temp directory");
}
this.capturedOutput = capturedOutput;
}
public void setTimeout(long timeout) {
@@ -110,6 +120,10 @@ public class CliTester implements TestRule {
return getOutput();
}
public File getTemp() {
return this.temp;
}
private <T extends OptionParsingCommand> Future<T> submitCommand(T command, String... args) {
clearUrlHandler();
final String[] sources = getSources(args);
@@ -118,7 +132,7 @@ public class CliTester implements TestRule {
System.setProperty("server.port", "0");
System.setProperty("spring.application.class.name",
"org.springframework.boot.cli.CliTesterSpringApplication");
this.serverPortFile = new File(this.temp.newFolder(), "server.port");
this.serverPortFile = new File(this.temp, "server.port");
System.setProperty("portfile", this.serverPortFile.getAbsolutePath());
try {
command.run(sources);
@@ -168,25 +182,27 @@ public class CliTester implements TestRule {
}
private String getOutput() {
String output = this.outputCapture.toString().substring(this.previousOutput.length());
String output = this.capturedOutput.toString().substring(this.previousOutput.length());
this.previousOutput = output;
return output;
}
@Override
public Statement apply(Statement base, Description description) {
final Statement statement = this.temp
.apply(this.outputCapture.apply(new RunLauncherStatement(base), description), description);
return new Statement() {
public void beforeEach(ExtensionContext extensionContext) {
Assumptions.assumeTrue(System.getProperty("spring.profiles.active", "integration").contains("integration"),
"Not running sample integration tests because integration profile not active");
System.setProperty("disableSpringSnapshotRepos", "false");
}
@Override
public void evaluate() throws Throwable {
Assume.assumeTrue("Not running sample integration tests because integration profile not active",
System.getProperty("spring.profiles.active", "integration").contains("integration"));
statement.evaluate();
@Override
public void afterEach(ExtensionContext extensionContext) {
for (AbstractCommand command : this.commands) {
if (command != null && command instanceof RunCommand) {
((RunCommand) command).stop();
}
};
}
System.clearProperty("disableSpringSnapshotRepos");
FileSystemUtils.deleteRecursively(this.temp);
}
public String getHttpOutput() {
@@ -205,35 +221,4 @@ public class CliTester implements TestRule {
}
}
private final class RunLauncherStatement extends Statement {
private final Statement base;
private RunLauncherStatement(Statement base) {
this.base = base;
}
@Override
public void evaluate() throws Throwable {
System.setProperty("disableSpringSnapshotRepos", "false");
try {
try {
this.base.evaluate();
}
finally {
for (AbstractCommand command : CliTester.this.commands) {
if (command != null && command instanceof RunCommand) {
((RunCommand) command).stop();
}
}
System.clearProperty("disableSpringSnapshotRepos");
}
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 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,8 +16,12 @@
package org.springframework.boot.cli;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
@@ -26,23 +30,28 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Dave Syer
*/
public class DirectorySourcesIntegrationTests {
@ExtendWith(OutputCaptureExtension.class)
class DirectorySourcesIntegrationTests {
@Rule
public CliTester cli = new CliTester("src/test/resources/dir-sample/");
@RegisterExtension
private CliTester cli;
DirectorySourcesIntegrationTests(CapturedOutput capturedOutput) {
this.cli = new CliTester("src/test/resources/dir-sample/", capturedOutput);
}
@Test
public void runDirectory() throws Exception {
void runDirectory() throws Exception {
assertThat(this.cli.run("code")).contains("Hello World");
}
@Test
public void runDirectoryRecursive() throws Exception {
void runDirectoryRecursive() throws Exception {
assertThat(this.cli.run("")).contains("Hello World");
}
@Test
public void runPathPattern() throws Exception {
void runPathPattern() throws Exception {
assertThat(this.cli.run("**/*.groovy")).contains("Hello World");
}

View File

@@ -18,13 +18,15 @@ package org.springframework.boot.cli;
import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.cli.command.grab.GrabCommand;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.util.FileSystemUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,45 +38,47 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Andy Wilkinson
* @author Dave Syer
*/
public class GrabCommandIntegrationTests {
@ExtendWith(OutputCaptureExtension.class)
class GrabCommandIntegrationTests {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@RegisterExtension
private CliTester cli;
@Rule
public CliTester cli = new CliTester("src/test/resources/grab-samples/");
GrabCommandIntegrationTests(CapturedOutput capturedOutput) {
this.cli = new CliTester("src/test/resources/grab-samples/", capturedOutput);
}
@Before
@After
@BeforeEach
@AfterEach
public void deleteLocalRepository() {
System.clearProperty("grape.root");
System.clearProperty("groovy.grape.report.downloads");
}
@Test
public void grab() throws Exception {
void grab() throws Exception {
System.setProperty("grape.root", this.temp.getRoot().getAbsolutePath());
System.setProperty("grape.root", this.cli.getTemp().getAbsolutePath());
System.setProperty("groovy.grape.report.downloads", "true");
// Use --autoconfigure=false to limit the amount of downloaded dependencies
String output = this.cli.grab("grab.groovy", "--autoconfigure=false");
assertThat(new File(this.temp.getRoot(), "repository/joda-time/joda-time")).isDirectory();
assertThat(new File(this.cli.getTemp(), "repository/joda-time/joda-time")).isDirectory();
// Should be resolved from local repository cache
assertThat(output.contains("Downloading: file:")).isTrue();
}
@Test
public void duplicateDependencyManagementBomAnnotationsProducesAnError() {
void duplicateDependencyManagementBomAnnotationsProducesAnError() {
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> this.cli.grab("duplicateDependencyManagementBom.groovy"))
.withMessageContaining("Duplicate @DependencyManagementBom annotation");
}
@Test
public void customMetadata() throws Exception {
System.setProperty("grape.root", this.temp.getRoot().getAbsolutePath());
File repository = new File(this.temp.getRoot().getAbsolutePath(), "repository");
void customMetadata() throws Exception {
System.setProperty("grape.root", this.cli.getTemp().getAbsolutePath());
File repository = new File(this.cli.getTemp().getAbsolutePath(), "repository");
FileSystemUtils.copyRecursively(new File("src/test/resources/grab-samples/repository"), repository);
this.cli.grab("customDependencyManagement.groovy", "--autoconfigure=false");
assertThat(new File(repository, "javax/ejb/ejb-api/3.0")).isDirectory();

View File

@@ -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,8 +18,12 @@ package org.springframework.boot.cli;
import java.util.concurrent.ExecutionException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -31,13 +35,18 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
public class ReproIntegrationTests {
@ExtendWith(OutputCaptureExtension.class)
class ReproIntegrationTests {
@Rule
public CliTester cli = new CliTester("src/test/resources/repro-samples/");
@RegisterExtension
private CliTester cli;
ReproIntegrationTests(CapturedOutput capturedOutput) {
this.cli = new CliTester("src/test/resources/repro-samples/", capturedOutput);
}
@Test
public void grabAntBuilder() throws Exception {
void grabAntBuilder() throws Exception {
this.cli.run("grab-ant-builder.groovy");
assertThat(this.cli.getHttpOutput()).contains("{\"message\":\"Hello World\"}");
}
@@ -45,17 +54,17 @@ public class ReproIntegrationTests {
// Security depends on old versions of Spring so if the dependencies aren't pinned
// this will fail
@Test
public void securityDependencies() throws Exception {
void securityDependencies() throws Exception {
assertThat(this.cli.run("secure.groovy")).contains("Hello World");
}
@Test
public void dataJpaDependencies() throws Exception {
void dataJpaDependencies() throws Exception {
assertThat(this.cli.run("data-jpa.groovy")).contains("Hello World");
}
@Test
public void jarFileExtensionNeeded() throws Exception {
void jarFileExtensionNeeded() throws Exception {
assertThatExceptionOfType(ExecutionException.class)
.isThrownBy(() -> this.cli.jar("secure.groovy", "data-jpa.groovy"))
.withMessageContaining("is not a JAR file");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 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,12 +18,15 @@ package org.springframework.boot.cli;
import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.cli.command.run.RunCommand;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
@@ -32,25 +35,30 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public class RunCommandIntegrationTests {
@ExtendWith(OutputCaptureExtension.class)
class RunCommandIntegrationTests {
@Rule
public CliTester cli = new CliTester("src/it/resources/run-command/");
@RegisterExtension
private CliTester cli;
RunCommandIntegrationTests(CapturedOutput capturedOutput) {
this.cli = new CliTester("src/it/resources/run-command/", capturedOutput);
}
private Properties systemProperties = new Properties();
@Before
@BeforeEach
public void captureSystemProperties() {
this.systemProperties.putAll(System.getProperties());
}
@After
@AfterEach
public void restoreSystemProperties() {
System.setProperties(this.systemProperties);
}
@Test
public void bannerAndLoggingIsOutputByDefault() throws Exception {
void bannerAndLoggingIsOutputByDefault() throws Exception {
String output = this.cli.run("quiet.groovy");
assertThat(output).contains(" :: Spring Boot ::");
assertThat(output).contains("Starting application");
@@ -58,7 +66,7 @@ public class RunCommandIntegrationTests {
}
@Test
public void quietModeSuppressesAllCliOutput() throws Exception {
void quietModeSuppressesAllCliOutput() throws Exception {
this.cli.run("quiet.groovy");
String output = this.cli.run("quiet.groovy", "-q");
assertThat(output).isEqualTo("Ssshh");

View File

@@ -19,9 +19,13 @@ package org.springframework.boot.cli;
import java.io.File;
import java.net.URI;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,46 +37,44 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Roy Clarkson
* @author Phillip Webb
*/
public class SampleIntegrationTests {
@ExtendWith(OutputCaptureExtension.class)
class SampleIntegrationTests {
@Rule
public CliTester cli = new CliTester("samples/");
@RegisterExtension
private CliTester cli;
@Test
public void appSample() throws Exception {
String output = this.cli.run("app.groovy");
URI scriptUri = new File("samples/app.groovy").toURI();
assertThat(output).contains("Hello World! From " + scriptUri);
SampleIntegrationTests(CapturedOutput capturedOutput) {
this.cli = new CliTester("samples/", capturedOutput);
}
@Test
public void retrySample() throws Exception {
void retrySample() throws Exception {
String output = this.cli.run("retry.groovy");
URI scriptUri = new File("samples/retry.groovy").toURI();
assertThat(output).contains("Hello World! From " + scriptUri);
}
@Test
public void beansSample() throws Exception {
void beansSample() throws Exception {
this.cli.run("beans.groovy");
String output = this.cli.getHttpOutput();
assertThat(output).contains("Hello World!");
}
@Test
public void templateSample() throws Exception {
void templateSample() throws Exception {
String output = this.cli.run("template.groovy");
assertThat(output).contains("Hello World!");
}
@Test
public void jobSample() throws Exception {
void jobSample() throws Exception {
String output = this.cli.run("job.groovy", "foo=bar");
assertThat(output).contains("completed with the following parameters");
}
@Test
public void jobWebSample() throws Exception {
void jobWebSample() throws Exception {
String output = this.cli.run("job.groovy", "web.groovy", "foo=bar");
assertThat(output).contains("completed with the following parameters");
String result = this.cli.getHttpOutput();
@@ -80,13 +82,13 @@ public class SampleIntegrationTests {
}
@Test
public void webSample() throws Exception {
void webSample() throws Exception {
this.cli.run("web.groovy");
assertThat(this.cli.getHttpOutput()).isEqualTo("World!");
}
@Test
public void uiSample() throws Exception {
void uiSample() throws Exception {
this.cli.run("ui.groovy", "--classpath=.:src/test/resources");
String result = this.cli.getHttpOutput();
assertThat(result).contains("Hello World");
@@ -95,37 +97,37 @@ public class SampleIntegrationTests {
}
@Test
public void actuatorSample() throws Exception {
void actuatorSample() throws Exception {
this.cli.run("actuator.groovy");
assertThat(this.cli.getHttpOutput()).isEqualTo("{\"message\":\"Hello World!\"}");
}
@Test
public void httpSample() throws Exception {
void httpSample() throws Exception {
String output = this.cli.run("http.groovy");
assertThat(output).contains("Hello World");
}
@Test
public void integrationSample() throws Exception {
void integrationSample() throws Exception {
String output = this.cli.run("integration.groovy");
assertThat(output).contains("Hello, World");
}
@Test
public void xmlSample() throws Exception {
void xmlSample() throws Exception {
String output = this.cli.run("runner.xml", "runner.groovy");
assertThat(output).contains("Hello World");
}
@Test
public void txSample() throws Exception {
void txSample() throws Exception {
String output = this.cli.run("tx.groovy");
assertThat(output).contains("Foo count=");
}
@Test
public void jmsSample() throws Exception {
void jmsSample() throws Exception {
System.setProperty("spring.artemis.embedded.queues", "spring-boot");
try {
String output = this.cli.run("jms.groovy");
@@ -137,14 +139,14 @@ public class SampleIntegrationTests {
}
@Test
@Ignore("Requires RabbitMQ to be run, so disable it be default")
public void rabbitSample() throws Exception {
@Disabled("Requires RabbitMQ to be run, so disable it by default")
void rabbitSample() throws Exception {
String output = this.cli.run("rabbit.groovy");
assertThat(output).contains("Received Greetings from Spring Boot via RabbitMQ");
}
@Test
public void caching() throws Exception {
void caching() throws Exception {
assertThat(this.cli.run("caching.groovy")).contains("Hello World");
}

View File

@@ -21,8 +21,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -31,34 +31,34 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public class SpringApplicationLauncherTests {
class SpringApplicationLauncherTests {
private Map<String, String> env = new HashMap<>();
@After
@AfterEach
public void cleanUp() {
System.clearProperty("spring.application.class.name");
}
@Test
public void defaultLaunch() {
void defaultLaunch() {
assertThat(launch()).contains("org.springframework.boot.SpringApplication");
}
@Test
public void launchWithClassConfiguredBySystemProperty() {
void launchWithClassConfiguredBySystemProperty() {
System.setProperty("spring.application.class.name", "system.property.SpringApplication");
assertThat(launch()).contains("system.property.SpringApplication");
}
@Test
public void launchWithClassConfiguredByEnvironmentVariable() {
void launchWithClassConfiguredByEnvironmentVariable() {
this.env.put("SPRING_APPLICATION_CLASS_NAME", "environment.variable.SpringApplication");
assertThat(launch()).contains("environment.variable.SpringApplication");
}
@Test
public void systemPropertyOverridesEnvironmentVariable() {
void systemPropertyOverridesEnvironmentVariable() {
System.setProperty("spring.application.class.name", "system.property.SpringApplication");
this.env.put("SPRING_APPLICATION_CLASS_NAME", "environment.variable.SpringApplication");
assertThat(launch()).contains("system.property.SpringApplication");
@@ -66,7 +66,7 @@ public class SpringApplicationLauncherTests {
}
@Test
public void sourcesDefaultPropertiesAndArgsAreUsedToLaunch() throws Exception {
void sourcesDefaultPropertiesAndArgsAreUsedToLaunch() throws Exception {
System.setProperty("spring.application.class.name", TestSpringApplication.class.getName());
Class<?>[] sources = new Class<?>[0];
String[] args = new String[0];

View File

@@ -16,38 +16,39 @@
package org.springframework.boot.cli.command;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.cli.command.run.RunCommand;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link CommandRunner}.
*
* @author Dave Syer
*/
public class CommandRunnerIntegrationTests {
@Rule
public OutputCaptureRule output = new OutputCaptureRule();
@ExtendWith(OutputCaptureExtension.class)
class CommandRunnerIntegrationTests {
@Test
public void debugAddsAutoconfigReport() {
void debugAddsAutoconfigReport(CapturedOutput capturedOutput) {
CommandRunner runner = new CommandRunner("spring");
runner.addCommand(new RunCommand());
// -d counts as "debug" for the spring command, but not for the
// LoggingApplicationListener
runner.runAndHandleErrors("run", "samples/app.groovy", "-d");
assertThat(this.output.toString()).contains("Negative matches:");
assertThat(capturedOutput).contains("Negative matches:");
}
@Test
public void debugSwitchedOffForAppArgs() {
void debugSwitchedOffForAppArgs(CapturedOutput capturedOutput) {
CommandRunner runner = new CommandRunner("spring");
runner.addCommand(new RunCommand());
runner.runAndHandleErrors("run", "samples/app.groovy", "--", "-d");
assertThat(this.output.toString()).doesNotContain("Negative matches:");
assertThat(capturedOutput).doesNotContain("Negative matches:");
}
}

View File

@@ -19,9 +19,9 @@ package org.springframework.boot.cli.command;
import java.util.EnumSet;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Dave Syer
*/
public class CommandRunnerTests {
class CommandRunnerTests {
private CommandRunner commandRunner;
@@ -54,13 +54,13 @@ public class CommandRunnerTests {
private ClassLoader loader;
@After
@AfterEach
public void close() {
Thread.currentThread().setContextClassLoader(this.loader);
System.clearProperty("debug");
}
@Before
@BeforeEach
public void setup() {
this.loader = Thread.currentThread().getContextClassLoader();
MockitoAnnotations.initMocks(this);
@@ -93,23 +93,23 @@ public class CommandRunnerTests {
}
@Test
public void runWithoutArguments() throws Exception {
void runWithoutArguments() throws Exception {
assertThatExceptionOfType(NoArgumentsException.class).isThrownBy(this.commandRunner::run);
}
@Test
public void runCommand() throws Exception {
void runCommand() throws Exception {
this.commandRunner.run("command", "--arg1", "arg2");
verify(this.regularCommand).run("--arg1", "arg2");
}
@Test
public void missingCommand() throws Exception {
void missingCommand() throws Exception {
assertThatExceptionOfType(NoSuchCommandException.class).isThrownBy(() -> this.commandRunner.run("missing"));
}
@Test
public void appArguments() throws Exception {
void appArguments() throws Exception {
this.commandRunner.runAndHandleErrors("command", "--", "--debug", "bar");
verify(this.regularCommand).run("--", "--debug", "bar");
// When handled by the command itself it shouldn't cause the system property to be
@@ -118,21 +118,21 @@ public class CommandRunnerTests {
}
@Test
public void handlesSuccess() {
void handlesSuccess() {
int status = this.commandRunner.runAndHandleErrors("command");
assertThat(status).isEqualTo(0);
assertThat(this.calls).isEmpty();
}
@Test
public void handlesNoSuchCommand() {
void handlesNoSuchCommand() {
int status = this.commandRunner.runAndHandleErrors("missing");
assertThat(status).isEqualTo(1);
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE);
}
@Test
public void handlesRegularExceptionWithMessage() throws Exception {
void handlesRegularExceptionWithMessage() throws Exception {
willThrow(new RuntimeException("With Message")).given(this.regularCommand).run();
int status = this.commandRunner.runAndHandleErrors("command");
assertThat(status).isEqualTo(1);
@@ -140,7 +140,7 @@ public class CommandRunnerTests {
}
@Test
public void handlesRegularExceptionWithoutMessage() throws Exception {
void handlesRegularExceptionWithoutMessage() throws Exception {
willThrow(new NullPointerException()).given(this.regularCommand).run();
int status = this.commandRunner.runAndHandleErrors("command");
assertThat(status).isEqualTo(1);
@@ -148,7 +148,7 @@ public class CommandRunnerTests {
}
@Test
public void handlesExceptionWithDashD() throws Exception {
void handlesExceptionWithDashD() throws Exception {
willThrow(new RuntimeException()).given(this.regularCommand).run();
int status = this.commandRunner.runAndHandleErrors("command", "-d");
assertThat(System.getProperty("debug")).isEqualTo("true");
@@ -157,7 +157,7 @@ public class CommandRunnerTests {
}
@Test
public void handlesExceptionWithDashDashDebug() throws Exception {
void handlesExceptionWithDashDashDebug() throws Exception {
willThrow(new RuntimeException()).given(this.regularCommand).run();
int status = this.commandRunner.runAndHandleErrors("command", "--debug");
assertThat(System.getProperty("debug")).isEqualTo("true");
@@ -166,25 +166,25 @@ public class CommandRunnerTests {
}
@Test
public void exceptionMessages() {
void exceptionMessages() {
assertThat(new NoSuchCommandException("name").getMessage())
.isEqualTo("'name' is not a valid command. See 'help'.");
}
@Test
public void help() throws Exception {
void help() throws Exception {
this.commandRunner.run("help", "command");
verify(this.regularCommand).getHelp();
}
@Test
public void helpNoCommand() throws Exception {
void helpNoCommand() throws Exception {
assertThatExceptionOfType(NoHelpCommandArgumentsException.class)
.isThrownBy(() -> this.commandRunner.run("help"));
}
@Test
public void helpUnknownCommand() throws Exception {
void helpUnknownCommand() throws Exception {
assertThatExceptionOfType(NoSuchCommandException.class)
.isThrownBy(() -> this.commandRunner.run("help", "missing"));
}

View File

@@ -16,7 +16,7 @@
package org.springframework.boot.cli.command;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.cli.command.options.OptionHandler;
@@ -27,10 +27,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Dave Syer
*/
public class OptionParsingCommandTests {
class OptionParsingCommandTests {
@Test
public void optionHelp() {
void optionHelp() {
OptionHandler handler = new OptionHandler();
handler.option("bar", "Bar");
OptionParsingCommand command = new TestOptionParsingCommand("foo", "Foo", handler);

View File

@@ -24,7 +24,7 @@ import java.util.Collection;
import java.util.List;
import org.assertj.core.api.Condition;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.cli.command.archive.ResourceMatcher.MatchedResource;
import org.springframework.test.util.ReflectionTestUtils;
@@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public class ResourceMatcherTests {
class ResourceMatcherTests {
@Test
public void nonExistentRoot() throws IOException {
void nonExistentRoot() throws IOException {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("alpha/**", "bravo/*", "*"),
Arrays.asList(".*", "alpha/**/excluded"));
List<MatchedResource> matchedResources = resourceMatcher.find(Arrays.asList(new File("does-not-exist")));
@@ -48,7 +48,7 @@ public class ResourceMatcherTests {
@SuppressWarnings("unchecked")
@Test
public void defaults() {
void defaults() {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList(""), Arrays.asList(""));
Collection<String> includes = (Collection<String>) ReflectionTestUtils.getField(resourceMatcher, "includes");
Collection<String> excludes = (Collection<String>) ReflectionTestUtils.getField(resourceMatcher, "excludes");
@@ -57,7 +57,7 @@ public class ResourceMatcherTests {
}
@Test
public void excludedWins() throws Exception {
void excludedWins() throws Exception {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("*"), Arrays.asList("**/*.jar"));
List<MatchedResource> found = resourceMatcher.find(Arrays.asList(new File("src/test/resources")));
assertThat(found).areNot(new Condition<MatchedResource>() {
@@ -72,7 +72,7 @@ public class ResourceMatcherTests {
@SuppressWarnings("unchecked")
@Test
public void includedDeltas() {
void includedDeltas() {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("-static/**"), Arrays.asList(""));
Collection<String> includes = (Collection<String>) ReflectionTestUtils.getField(resourceMatcher, "includes");
assertThat(includes).contains("templates/**");
@@ -81,7 +81,7 @@ public class ResourceMatcherTests {
@SuppressWarnings("unchecked")
@Test
public void includedDeltasAndNewEntries() {
void includedDeltasAndNewEntries() {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("-static/**", "foo.jar"),
Arrays.asList("-**/*.jar"));
Collection<String> includes = (Collection<String>) ReflectionTestUtils.getField(resourceMatcher, "includes");
@@ -94,14 +94,14 @@ public class ResourceMatcherTests {
@SuppressWarnings("unchecked")
@Test
public void excludedDeltas() {
void excludedDeltas() {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList(""), Arrays.asList("-**/*.jar"));
Collection<String> excludes = (Collection<String>) ReflectionTestUtils.getField(resourceMatcher, "excludes");
assertThat(excludes).doesNotContain("**/*.jar");
}
@Test
public void jarFileAlwaysMatches() throws Exception {
void jarFileAlwaysMatches() throws Exception {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("*"), Arrays.asList("**/*.jar"));
List<MatchedResource> found = resourceMatcher
.find(Arrays.asList(new File("src/test/resources/templates"), new File("src/test/resources/foo.jar")));
@@ -116,7 +116,7 @@ public class ResourceMatcherTests {
}
@Test
public void resourceMatching() throws IOException {
void resourceMatching() throws IOException {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("alpha/**", "bravo/*", "*"),
Arrays.asList(".*", "alpha/**/excluded"));
List<MatchedResource> matchedResources = resourceMatcher

View File

@@ -16,9 +16,9 @@
package org.springframework.boot.cli.command.encodepassword;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.MockitoAnnotations;
@@ -37,26 +37,26 @@ import static org.mockito.Mockito.verify;
*
* @author Phillip Webb
*/
public class EncodePasswordCommandTests {
class EncodePasswordCommandTests {
private MockLog log;
@Captor
private ArgumentCaptor<String> message;
@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
this.log = MockLog.attach();
}
@After
@AfterEach
public void cleanup() {
MockLog.clear();
}
@Test
public void encodeWithNoAlgorithmShouldUseBcrypt() throws Exception {
void encodeWithNoAlgorithmShouldUseBcrypt() throws Exception {
EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("boot");
verify(this.log).info(this.message.capture());
@@ -67,7 +67,7 @@ public class EncodePasswordCommandTests {
}
@Test
public void encodeWithBCryptShouldUseBCrypt() throws Exception {
void encodeWithBCryptShouldUseBCrypt() throws Exception {
EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("-a", "bcrypt", "boot");
verify(this.log).info(this.message.capture());
@@ -77,7 +77,7 @@ public class EncodePasswordCommandTests {
}
@Test
public void encodeWithPbkdf2ShouldUsePbkdf2() throws Exception {
void encodeWithPbkdf2ShouldUsePbkdf2() throws Exception {
EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("-a", "pbkdf2", "boot");
verify(this.log).info(this.message.capture());
@@ -87,7 +87,7 @@ public class EncodePasswordCommandTests {
}
@Test
public void encodeWithUnknownAlgorithmShouldExitWithError() throws Exception {
void encodeWithUnknownAlgorithmShouldExitWithError() throws Exception {
EncodePasswordCommand command = new EncodePasswordCommand();
ExitStatus status = command.run("--algorithm", "bad", "boot");
verify(this.log).error("Unknown algorithm, valid options are: default,bcrypt,pbkdf2");

View File

@@ -27,10 +27,9 @@ import java.util.zip.ZipOutputStream;
import joptsimple.OptionSet;
import org.apache.http.Header;
import org.apache.http.client.methods.HttpUriRequest;
import org.junit.Before;
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.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.MockitoAnnotations;
@@ -46,10 +45,7 @@ import static org.mockito.Mockito.verify;
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
public class InitCommandTests extends AbstractHttpClientMockTests {
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
class InitCommandTests extends AbstractHttpClientMockTests {
private final TestableInitCommandOptionHandler handler;
@@ -58,7 +54,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
@Captor
private ArgumentCaptor<HttpUriRequest> requestCaptor;
@Before
@BeforeEach
public void setupMocks() {
MockitoAnnotations.initMocks(this);
}
@@ -70,25 +66,25 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void listServiceCapabilitiesText() throws Exception {
void listServiceCapabilitiesText() throws Exception {
mockSuccessfulMetadataTextGet();
this.command.run("--list", "--target=https://fake-service");
}
@Test
public void listServiceCapabilities() throws Exception {
void listServiceCapabilities() throws Exception {
mockSuccessfulMetadataGet(true);
this.command.run("--list", "--target=https://fake-service");
}
@Test
public void listServiceCapabilitiesV2() throws Exception {
void listServiceCapabilitiesV2() throws Exception {
mockSuccessfulMetadataGetV2(true);
this.command.run("--list", "--target=https://fake-service");
}
@Test
public void generateProject() throws Exception {
void generateProject() throws Exception {
String fileName = UUID.randomUUID().toString() + ".zip";
File file = new File(fileName);
assertThat(file.exists()).as("file should not exist").isFalse();
@@ -104,50 +100,47 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectNoFileNameAvailable() throws Exception {
void generateProjectNoFileNameAvailable() throws Exception {
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip", null);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run()).isEqualTo(ExitStatus.ERROR);
}
@Test
public void generateProjectAndExtract() throws Exception {
File folder = this.temporaryFolder.newFolder();
void generateProjectAndExtract(@TempDir File tempDir) throws Exception {
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip", "demo.zip",
archive);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run("--extract", folder.getAbsolutePath())).isEqualTo(ExitStatus.OK);
File archiveFile = new File(folder, "test.txt");
assertThat(this.command.run("--extract", tempDir.getAbsolutePath())).isEqualTo(ExitStatus.OK);
File archiveFile = new File(tempDir, "test.txt");
assertThat(archiveFile).exists();
}
@Test
public void generateProjectAndExtractWillNotWriteEntriesOutsideOutputLocation() throws Exception {
File folder = this.temporaryFolder.newFolder();
void generateProjectAndExtractWillNotWriteEntriesOutsideOutputLocation(@TempDir File tempDir) throws Exception {
byte[] archive = createFakeZipArchive("../outside.txt", "Fake content");
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip", "demo.zip",
archive);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run("--extract", folder.getAbsolutePath())).isEqualTo(ExitStatus.ERROR);
File archiveFile = new File(folder.getParentFile(), "outside.txt");
assertThat(this.command.run("--extract", tempDir.getAbsolutePath())).isEqualTo(ExitStatus.ERROR);
File archiveFile = new File(tempDir.getParentFile(), "outside.txt");
assertThat(archiveFile).doesNotExist();
}
@Test
public void generateProjectAndExtractWithConvention() throws Exception {
File folder = this.temporaryFolder.newFolder();
void generateProjectAndExtractWithConvention(@TempDir File tempDir) throws Exception {
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip", "demo.zip",
archive);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run(folder.getAbsolutePath() + "/")).isEqualTo(ExitStatus.OK);
File archiveFile = new File(folder, "test.txt");
assertThat(this.command.run(tempDir.getAbsolutePath() + "/")).isEqualTo(ExitStatus.OK);
File archiveFile = new File(tempDir, "test.txt");
assertThat(archiveFile).exists();
}
@Test
public void generateProjectArchiveExtractedByDefault() throws Exception {
void generateProjectArchiveExtractedByDefault() throws Exception {
String fileName = UUID.randomUUID().toString();
assertThat(fileName.contains(".")).as("No dot in filename").isFalse();
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
@@ -167,7 +160,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectFileSavedAsFileByDefault() throws Exception {
void generateProjectFileSavedAsFileByDefault() throws Exception {
String fileName = UUID.randomUUID().toString();
String content = "Fake Content";
byte[] archive = content.getBytes();
@@ -186,8 +179,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectAndExtractUnsupportedArchive() throws Exception {
File folder = this.temporaryFolder.newFolder();
void generateProjectAndExtractUnsupportedArchive(@TempDir File tempDir) throws Exception {
String fileName = UUID.randomUUID().toString() + ".zip";
File file = new File(fileName);
assertThat(file.exists()).as("file should not exist").isFalse();
@@ -196,7 +188,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/foobar",
fileName, archive);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run("--extract", folder.getAbsolutePath())).isEqualTo(ExitStatus.OK);
assertThat(this.command.run("--extract", tempDir.getAbsolutePath())).isEqualTo(ExitStatus.OK);
assertThat(file.exists()).as("file should have been saved instead").isTrue();
}
finally {
@@ -205,8 +197,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectAndExtractUnknownContentType() throws Exception {
File folder = this.temporaryFolder.newFolder();
void generateProjectAndExtractUnknownContentType(@TempDir File tempDir) throws Exception {
String fileName = UUID.randomUUID().toString() + ".zip";
File file = new File(fileName);
assertThat(file.exists()).as("file should not exist").isFalse();
@@ -214,7 +205,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(null, fileName, archive);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run("--extract", folder.getAbsolutePath())).isEqualTo(ExitStatus.OK);
assertThat(this.command.run("--extract", tempDir.getAbsolutePath())).isEqualTo(ExitStatus.OK);
assertThat(file.exists()).as("file should have been saved instead").isTrue();
}
finally {
@@ -223,8 +214,9 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void fileNotOverwrittenByDefault() throws Exception {
File file = this.temporaryFolder.newFile();
void fileNotOverwrittenByDefault(@TempDir File tempDir) throws Exception {
File file = new File(tempDir, "test.file");
file.createNewFile();
long fileLength = file.length();
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip",
file.getAbsolutePath());
@@ -234,8 +226,9 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void overwriteFile() throws Exception {
File file = this.temporaryFolder.newFile();
void overwriteFile(@TempDir File tempDir) throws Exception {
File file = new File(tempDir, "test.file");
file.createNewFile();
long fileLength = file.length();
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip",
file.getAbsolutePath());
@@ -245,9 +238,8 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void fileInArchiveNotOverwrittenByDefault() throws Exception {
File folder = this.temporaryFolder.newFolder();
File conflict = new File(folder, "test.txt");
void fileInArchiveNotOverwrittenByDefault(@TempDir File tempDir) throws Exception {
File conflict = new File(tempDir, "test.txt");
assertThat(conflict.createNewFile()).as("Should have been able to create file").isTrue();
long fileLength = conflict.length();
// also contains test.txt
@@ -255,12 +247,12 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip", "demo.zip",
archive);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run("--extract", folder.getAbsolutePath())).isEqualTo(ExitStatus.ERROR);
assertThat(this.command.run("--extract", tempDir.getAbsolutePath())).isEqualTo(ExitStatus.ERROR);
assertThat(conflict.length()).as("File should not have changed").isEqualTo(fileLength);
}
@Test
public void parseProjectOptions() throws Exception {
void parseProjectOptions() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("-g=org.demo", "-a=acme", "-v=1.2.3-SNAPSHOT", "-n=acme-sample",
"--description=Acme sample project", "--package-name=demo.foo", "-t=ant-project", "--build=grunt",
@@ -285,9 +277,8 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void overwriteFileInArchive() throws Exception {
File folder = this.temporaryFolder.newFolder();
File conflict = new File(folder, "test.txt");
void overwriteFileInArchive(@TempDir File tempDir) throws Exception {
File conflict = new File(tempDir, "test.txt");
assertThat(conflict.createNewFile()).as("Should have been able to create file").isTrue();
long fileLength = conflict.length();
// also contains test.txt
@@ -295,12 +286,12 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest("application/zip", "demo.zip",
archive);
mockSuccessfulProjectGeneration(request);
assertThat(this.command.run("--force", "--extract", folder.getAbsolutePath())).isEqualTo(ExitStatus.OK);
assertThat(this.command.run("--force", "--extract", tempDir.getAbsolutePath())).isEqualTo(ExitStatus.OK);
assertThat(fileLength != conflict.length()).as("File should have changed").isTrue();
}
@Test
public void parseTypeOnly() throws Exception {
void parseTypeOnly() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("-t=ant-project");
assertThat(this.handler.lastRequest.getBuild()).isEqualTo("maven");
@@ -310,7 +301,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void parseBuildOnly() throws Exception {
void parseBuildOnly() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("--build=ant");
assertThat(this.handler.lastRequest.getBuild()).isEqualTo("ant");
@@ -320,7 +311,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void parseFormatOnly() throws Exception {
void parseFormatOnly() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("--format=web");
assertThat(this.handler.lastRequest.getBuild()).isEqualTo("maven");
@@ -330,14 +321,14 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void parseLocation() throws Exception {
void parseLocation() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("foobar.zip");
assertThat(this.handler.lastRequest.getOutput()).isEqualTo("foobar.zip");
}
@Test
public void parseLocationWithSlash() throws Exception {
void parseLocationWithSlash() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("foobar/");
assertThat(this.handler.lastRequest.getOutput()).isEqualTo("foobar");
@@ -345,13 +336,13 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
}
@Test
public void parseMoreThanOneArg() throws Exception {
void parseMoreThanOneArg() throws Exception {
this.handler.disableProjectGeneration();
assertThat(this.command.run("foobar", "barfoo")).isEqualTo(ExitStatus.ERROR);
}
@Test
public void userAgent() throws Exception {
void userAgent() throws Exception {
this.command.run("--list", "--target=https://fake-service");
verify(this.http).execute(this.requestCaptor.capture());
Header agent = this.requestCaptor.getValue().getHeaders("User-Agent")[0];

View File

@@ -22,7 +22,7 @@ import java.nio.charset.StandardCharsets;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Stephane Nicoll
*/
public class InitializrServiceMetadataTests {
class InitializrServiceMetadataTests {
@Test
public void parseDefaults() throws Exception {
void parseDefaults() throws Exception {
InitializrServiceMetadata metadata = createInstance("2.0.0");
assertThat(metadata.getDefaults().get("bootVersion")).isEqualTo("1.1.8.RELEASE");
assertThat(metadata.getDefaults().get("javaVersion")).isEqualTo("1.7");
@@ -55,7 +55,7 @@ public class InitializrServiceMetadataTests {
}
@Test
public void parseDependencies() throws Exception {
void parseDependencies() throws Exception {
InitializrServiceMetadata metadata = createInstance("2.0.0");
assertThat(metadata.getDependencies()).hasSize(5);
@@ -69,7 +69,7 @@ public class InitializrServiceMetadataTests {
}
@Test
public void parseTypes() throws Exception {
void parseTypes() throws Exception {
InitializrServiceMetadata metadata = createInstance("2.0.0");
ProjectType projectType = metadata.getProjectTypes().get("maven-project");
assertThat(projectType).isNotNull();

View File

@@ -18,7 +18,7 @@ package org.springframework.boot.cli.command.init;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -31,19 +31,19 @@ import static org.mockito.Mockito.mock;
*
* @author Stephane Nicoll
*/
public class InitializrServiceTests extends AbstractHttpClientMockTests {
class InitializrServiceTests extends AbstractHttpClientMockTests {
private final InitializrService invoker = new InitializrService(this.http);
@Test
public void loadMetadata() throws Exception {
void loadMetadata() throws Exception {
mockSuccessfulMetadataGet(false);
InitializrServiceMetadata metadata = this.invoker.loadMetadata("https://foo/bar");
assertThat(metadata).isNotNull();
}
@Test
public void generateSimpleProject() throws Exception {
void generateSimpleProject() throws Exception {
ProjectGenerationRequest request = new ProjectGenerationRequest();
MockHttpProjectGenerationRequest mockHttpRequest = new MockHttpProjectGenerationRequest("application/xml",
"foo.zip");
@@ -52,7 +52,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectCustomTargetFilename() throws Exception {
void generateProjectCustomTargetFilename() throws Exception {
ProjectGenerationRequest request = new ProjectGenerationRequest();
request.setOutput("bar.zip");
MockHttpProjectGenerationRequest mockHttpRequest = new MockHttpProjectGenerationRequest("application/xml",
@@ -62,7 +62,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectNoDefaultFileName() throws Exception {
void generateProjectNoDefaultFileName() throws Exception {
ProjectGenerationRequest request = new ProjectGenerationRequest();
MockHttpProjectGenerationRequest mockHttpRequest = new MockHttpProjectGenerationRequest("application/xml",
null);
@@ -71,7 +71,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectBadRequest() throws Exception {
void generateProjectBadRequest() throws Exception {
String jsonMessage = "Unknown dependency foo:bar";
mockProjectGenerationError(400, jsonMessage);
ProjectGenerationRequest request = new ProjectGenerationRequest();
@@ -81,7 +81,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectBadRequestNoExtraMessage() throws Exception {
void generateProjectBadRequestNoExtraMessage() throws Exception {
mockProjectGenerationError(400, null);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
@@ -89,7 +89,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void generateProjectNoContent() throws Exception {
void generateProjectNoContent() throws Exception {
mockSuccessfulMetadataGet(false);
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
mockStatus(response, 500);
@@ -100,7 +100,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void loadMetadataBadRequest() throws Exception {
void loadMetadataBadRequest() throws Exception {
String jsonMessage = "whatever error on the server";
mockMetadataGetError(500, jsonMessage);
ProjectGenerationRequest request = new ProjectGenerationRequest();
@@ -109,7 +109,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void loadMetadataInvalidJson() throws Exception {
void loadMetadataInvalidJson() throws Exception {
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
mockHttpEntity(response, "Foo-Bar-Not-JSON".getBytes(), "application/json");
mockStatus(response, 200);
@@ -120,7 +120,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
}
@Test
public void loadMetadataNoContent() throws Exception {
void loadMetadataNoContent() throws Exception {
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
mockStatus(response, 500);
given(this.http.execute(isA(HttpGet.class))).willReturn(response);

View File

@@ -25,7 +25,7 @@ import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -40,19 +40,19 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
public class ProjectGenerationRequestTests {
class ProjectGenerationRequestTests {
public static final Map<String, String> EMPTY_TAGS = Collections.emptyMap();
private final ProjectGenerationRequest request = new ProjectGenerationRequest();
@Test
public void defaultSettings() {
void defaultSettings() {
assertThat(this.request.generateUrl(createDefaultMetadata())).isEqualTo(createDefaultUrl("?type=test-type"));
}
@Test
public void customServer() throws URISyntaxException {
void customServer() throws URISyntaxException {
String customServerUrl = "https://foo:8080/initializr";
this.request.setServiceUrl(customServerUrl);
this.request.getDependencies().add("security");
@@ -61,21 +61,21 @@ public class ProjectGenerationRequestTests {
}
@Test
public void customBootVersion() {
void customBootVersion() {
this.request.setBootVersion("1.2.0.RELEASE");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&bootVersion=1.2.0.RELEASE"));
}
@Test
public void singleDependency() {
void singleDependency() {
this.request.getDependencies().add("web");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?dependencies=web&type=test-type"));
}
@Test
public void multipleDependencies() {
void multipleDependencies() {
this.request.getDependencies().add("web");
this.request.getDependencies().add("data-jpa");
assertThat(this.request.generateUrl(createDefaultMetadata()))
@@ -83,21 +83,21 @@ public class ProjectGenerationRequestTests {
}
@Test
public void customJavaVersion() {
void customJavaVersion() {
this.request.setJavaVersion("1.8");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&javaVersion=1.8"));
}
@Test
public void customPackageName() {
void customPackageName() {
this.request.setPackageName("demo.foo");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?packageName=demo.foo&type=test-type"));
}
@Test
public void customType() throws URISyntaxException {
void customType() throws URISyntaxException {
ProjectType projectType = new ProjectType("custom", "Custom Type", "/foo", true, EMPTY_TAGS);
InitializrServiceMetadata metadata = new InitializrServiceMetadata(projectType);
this.request.setType("custom");
@@ -107,21 +107,21 @@ public class ProjectGenerationRequestTests {
}
@Test
public void customPackaging() {
void customPackaging() {
this.request.setPackaging("war");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&packaging=war"));
}
@Test
public void customLanguage() {
void customLanguage() {
this.request.setLanguage("groovy");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?type=test-type&language=groovy"));
}
@Test
public void customProjectInfo() {
void customProjectInfo() {
this.request.setGroupId("org.acme");
this.request.setArtifactId("sample");
this.request.setVersion("1.0.1-SNAPSHOT");
@@ -132,28 +132,28 @@ public class ProjectGenerationRequestTests {
}
@Test
public void outputCustomizeArtifactId() {
void outputCustomizeArtifactId() {
this.request.setOutput("my-project");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
}
@Test
public void outputArchiveCustomizeArtifactId() {
void outputArchiveCustomizeArtifactId() {
this.request.setOutput("my-project.zip");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
}
@Test
public void outputArchiveWithDotsCustomizeArtifactId() {
void outputArchiveWithDotsCustomizeArtifactId() {
this.request.setOutput("my.nice.project.zip");
assertThat(this.request.generateUrl(createDefaultMetadata()))
.isEqualTo(createDefaultUrl("?artifactId=my.nice.project&type=test-type"));
}
@Test
public void outputDoesNotOverrideCustomArtifactId() {
void outputDoesNotOverrideCustomArtifactId() {
this.request.setOutput("my-project");
this.request.setArtifactId("my-id");
assertThat(this.request.generateUrl(createDefaultMetadata()))
@@ -161,7 +161,7 @@ public class ProjectGenerationRequestTests {
}
@Test
public void buildNoMatch() throws Exception {
void buildNoMatch() throws Exception {
InitializrServiceMetadata metadata = readMetadata();
setBuildAndFormat("does-not-exist", null);
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.request.generateUrl(metadata))
@@ -169,7 +169,7 @@ public class ProjectGenerationRequestTests {
}
@Test
public void buildMultipleMatch() throws Exception {
void buildMultipleMatch() throws Exception {
InitializrServiceMetadata metadata = readMetadata("types-conflict");
setBuildAndFormat("gradle", null);
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.request.generateUrl(metadata))
@@ -177,14 +177,14 @@ public class ProjectGenerationRequestTests {
}
@Test
public void buildOneMatch() throws Exception {
void buildOneMatch() throws Exception {
InitializrServiceMetadata metadata = readMetadata();
setBuildAndFormat("gradle", null);
assertThat(this.request.generateUrl(metadata)).isEqualTo(createDefaultUrl("?type=gradle-project"));
}
@Test
public void typeAndBuildAndFormat() throws Exception {
void typeAndBuildAndFormat() throws Exception {
InitializrServiceMetadata metadata = readMetadata();
setBuildAndFormat("gradle", "project");
this.request.setType("maven-build");
@@ -192,14 +192,14 @@ public class ProjectGenerationRequestTests {
}
@Test
public void invalidType() {
void invalidType() {
this.request.setType("does-not-exist");
assertThatExceptionOfType(ReportableException.class)
.isThrownBy(() -> this.request.generateUrl(createDefaultMetadata()));
}
@Test
public void noTypeAndNoDefault() throws Exception {
void noTypeAndNoDefault() throws Exception {
assertThatExceptionOfType(ReportableException.class)
.isThrownBy(() -> this.request.generateUrl(readMetadata("types-conflict")))
.withMessageContaining("no default is defined");

View File

@@ -18,7 +18,7 @@ package org.springframework.boot.cli.command.init;
import java.io.IOException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,13 +27,13 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Stephane Nicoll
*/
public class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientMockTests {
class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientMockTests {
private final ServiceCapabilitiesReportGenerator command = new ServiceCapabilitiesReportGenerator(
new InitializrService(this.http));
@Test
public void listMetadataFromServer() throws IOException {
void listMetadataFromServer() throws IOException {
mockSuccessfulMetadataTextGet();
String expected = new String(readClasspathResource("metadata/service-metadata-2.1.0.txt"));
String content = this.command.generate("http://localhost");
@@ -41,13 +41,13 @@ public class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientM
}
@Test
public void listMetadata() throws IOException {
void listMetadata() throws IOException {
mockSuccessfulMetadataGet(true);
doTestGenerateCapabilitiesFromJson();
}
@Test
public void listMetadataV2() throws IOException {
void listMetadataV2() throws IOException {
mockSuccessfulMetadataGetV2(true);
doTestGenerateCapabilitiesFromJson();
}

View File

@@ -24,8 +24,8 @@ import java.util.List;
import java.util.Set;
import org.assertj.core.api.Condition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration;
import org.springframework.boot.cli.compiler.GroovyCompilerScope;
@@ -42,11 +42,11 @@ import static org.hamcrest.Matchers.startsWith;
*
* @author Andy Wilkinson
*/
public class GroovyGrabDependencyResolverTests {
class GroovyGrabDependencyResolverTests {
private DependencyResolver resolver;
@Before
@BeforeEach
public void setupResolver() {
GroovyCompilerConfiguration configuration = new GroovyCompilerConfiguration() {
@@ -90,14 +90,14 @@ public class GroovyGrabDependencyResolverTests {
}
@Test
public void resolveArtifactWithNoDependencies() throws Exception {
void resolveArtifactWithNoDependencies() throws Exception {
List<File> resolved = this.resolver.resolve(Arrays.asList("commons-logging:commons-logging:1.1.3"));
assertThat(resolved).hasSize(1);
assertThat(getNames(resolved)).containsOnly("commons-logging-1.1.3.jar");
}
@Test
public void resolveArtifactWithDependencies() throws Exception {
void resolveArtifactWithDependencies() throws Exception {
List<File> resolved = this.resolver.resolve(Arrays.asList("org.springframework:spring-core:4.1.1.RELEASE"));
assertThat(resolved).hasSize(2);
assertThat(getNames(resolved)).containsOnly("commons-logging-1.1.3.jar", "spring-core-4.1.1.RELEASE.jar");
@@ -105,7 +105,7 @@ public class GroovyGrabDependencyResolverTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void resolveShorthandArtifactWithDependencies() throws Exception {
void resolveShorthandArtifactWithDependencies() throws Exception {
List<File> resolved = this.resolver.resolve(Arrays.asList("spring-beans"));
assertThat(resolved).hasSize(3);
assertThat(getNames(resolved)).has((Condition) Matched
@@ -113,7 +113,7 @@ public class GroovyGrabDependencyResolverTests {
}
@Test
public void resolveMultipleArtifacts() throws Exception {
void resolveMultipleArtifacts() throws Exception {
List<File> resolved = this.resolver
.resolve(Arrays.asList("junit:junit:4.11", "commons-logging:commons-logging:1.1.3"));
assertThat(resolved).hasSize(4);

View File

@@ -22,11 +22,10 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
@@ -37,28 +36,28 @@ import static org.mockito.Mockito.mock;
*
* @author Andy Wilkinson
*/
public class InstallerTests {
class InstallerTests {
public DependencyResolver resolver = mock(DependencyResolver.class);
private final DependencyResolver resolver = mock(DependencyResolver.class);
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@TempDir
File tempDir;
private Installer installer;
@Before
@BeforeEach
public void setUp() throws IOException {
System.setProperty("spring.home", this.tempFolder.getRoot().getAbsolutePath());
System.setProperty("spring.home", this.tempDir.getAbsolutePath());
this.installer = new Installer(this.resolver);
}
@After
@AfterEach
public void cleanUp() {
System.clearProperty("spring.home");
}
@Test
public void installNewDependency() throws Exception {
void installNewDependency() throws Exception {
File foo = createTemporaryFile("foo.jar");
given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo));
this.installer.install(Arrays.asList("foo"));
@@ -66,7 +65,7 @@ public class InstallerTests {
}
@Test
public void installAndUninstall() throws Exception {
void installAndUninstall() throws Exception {
File foo = createTemporaryFile("foo.jar");
given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo));
this.installer.install(Arrays.asList("foo"));
@@ -75,7 +74,7 @@ public class InstallerTests {
}
@Test
public void installAndUninstallWithCommonDependencies() throws Exception {
void installAndUninstallWithCommonDependencies() throws Exception {
File alpha = createTemporaryFile("alpha.jar");
File bravo = createTemporaryFile("bravo.jar");
File charlie = createTemporaryFile("charlie.jar");
@@ -92,7 +91,7 @@ public class InstallerTests {
}
@Test
public void uninstallAll() throws Exception {
void uninstallAll() throws Exception {
File alpha = createTemporaryFile("alpha.jar");
File bravo = createTemporaryFile("bravo.jar");
File charlie = createTemporaryFile("charlie.jar");
@@ -107,15 +106,15 @@ public class InstallerTests {
private Set<String> getNamesOfFilesInLibExt() {
Set<String> names = new HashSet<>();
for (File file : new File(this.tempFolder.getRoot(), "lib/ext").listFiles()) {
for (File file : new File(this.tempDir, "lib/ext").listFiles()) {
names.add(file.getName());
}
return names;
}
private File createTemporaryFile(String name) throws IOException {
File temporaryFile = this.tempFolder.newFile(name);
temporaryFile.deleteOnExit();
File temporaryFile = new File(this.tempDir, name);
temporaryFile.createNewFile();
return temporaryFile;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.boot.cli.command.run;
import java.util.logging.Level;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.BDDMockito.given;
@@ -29,10 +29,10 @@ import static org.mockito.Mockito.mock;
*
* @author Andy Wilkinson
*/
public class SpringApplicationRunnerTests {
class SpringApplicationRunnerTests {
@Test
public void exceptionMessageWhenSourcesContainsNoClasses() throws Exception {
void exceptionMessageWhenSourcesContainsNoClasses() throws Exception {
SpringApplicationRunnerConfiguration configuration = mock(SpringApplicationRunnerConfiguration.class);
given(configuration.getClasspath()).willReturn(new String[] { "foo", "bar" });
given(configuration.getLogLevel()).willReturn(Level.INFO);

View File

@@ -17,7 +17,7 @@
package org.springframework.boot.cli.command.shell;
import jline.console.completer.ArgumentCompleter.ArgumentList;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -26,12 +26,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
*/
public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
class EscapeAwareWhiteSpaceArgumentDelimiterTests {
private final EscapeAwareWhiteSpaceArgumentDelimiter delimiter = new EscapeAwareWhiteSpaceArgumentDelimiter();
@Test
public void simple() {
void simple() {
String s = "one two";
assertThat(this.delimiter.delimit(s, 0).getArguments()).containsExactly("one", "two");
assertThat(this.delimiter.parseArguments(s)).containsExactly("one", "two");
@@ -41,7 +41,7 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
}
@Test
public void escaped() {
void escaped() {
String s = "o\\ ne two";
assertThat(this.delimiter.delimit(s, 0).getArguments()).containsExactly("o\\ ne", "two");
assertThat(this.delimiter.parseArguments(s)).containsExactly("o ne", "two");
@@ -52,28 +52,28 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
}
@Test
public void quoted() {
void quoted() {
String s = "'o ne' 't w o'";
assertThat(this.delimiter.delimit(s, 0).getArguments()).containsExactly("'o ne'", "'t w o'");
assertThat(this.delimiter.parseArguments(s)).containsExactly("o ne", "t w o");
}
@Test
public void doubleQuoted() {
void doubleQuoted() {
String s = "\"o ne\" \"t w o\"";
assertThat(this.delimiter.delimit(s, 0).getArguments()).containsExactly("\"o ne\"", "\"t w o\"");
assertThat(this.delimiter.parseArguments(s)).containsExactly("o ne", "t w o");
}
@Test
public void nestedQuotes() {
void nestedQuotes() {
String s = "\"o 'n''e\" 't \"w o'";
assertThat(this.delimiter.delimit(s, 0).getArguments()).containsExactly("\"o 'n''e\"", "'t \"w o'");
assertThat(this.delimiter.parseArguments(s)).containsExactly("o 'n''e", "t \"w o");
}
@Test
public void escapedQuotes() {
void escapedQuotes() {
String s = "\\'a b";
ArgumentList argumentList = this.delimiter.delimit(s, 0);
assertThat(argumentList.getArguments()).isEqualTo(new String[] { "\\'a", "b" });
@@ -81,7 +81,7 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
}
@Test
public void escapes() {
void escapes() {
String s = "\\ \\\\.\\\\\\t";
assertThat(this.delimiter.parseArguments(s)).containsExactly(" \\.\\\t");
}

View File

@@ -25,8 +25,8 @@ import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.ModuleNode;
import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.control.SourceUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -41,7 +41,7 @@ import static org.mockito.BDDMockito.given;
*
* @author Andy Wilkinson
*/
public class DependencyCustomizerTests {
class DependencyCustomizerTests {
private final ModuleNode moduleNode = new ModuleNode((SourceUnit) null);
@@ -52,7 +52,7 @@ public class DependencyCustomizerTests {
private DependencyCustomizer dependencyCustomizer;
@Before
@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);
given(this.resolver.getGroupId("spring-boot-starter-logging")).willReturn("org.springframework.boot");
@@ -70,7 +70,7 @@ public class DependencyCustomizerTests {
}
@Test
public void basicAdd() {
void basicAdd() {
this.dependencyCustomizer.add("spring-boot-starter-logging");
List<AnnotationNode> grabAnnotations = this.classNode.getAnnotations(new ClassNode(Grab.class));
assertThat(grabAnnotations).hasSize(1);
@@ -80,7 +80,7 @@ public class DependencyCustomizerTests {
}
@Test
public void nonTransitiveAdd() {
void nonTransitiveAdd() {
this.dependencyCustomizer.add("spring-boot-starter-logging", false);
List<AnnotationNode> grabAnnotations = this.classNode.getAnnotations(new ClassNode(Grab.class));
assertThat(grabAnnotations).hasSize(1);
@@ -90,7 +90,7 @@ public class DependencyCustomizerTests {
}
@Test
public void fullyCustomized() {
void fullyCustomized() {
this.dependencyCustomizer.add("spring-boot-starter-logging", "my-classifier", "my-type", false);
List<AnnotationNode> grabAnnotations = this.classNode.getAnnotations(new ClassNode(Grab.class));
assertThat(grabAnnotations).hasSize(1);
@@ -100,39 +100,39 @@ public class DependencyCustomizerTests {
}
@Test
public void anyMissingClassesWithMissingClassesPerformsAdd() {
void anyMissingClassesWithMissingClassesPerformsAdd() {
this.dependencyCustomizer.ifAnyMissingClasses("does.not.Exist").add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
}
@Test
public void anyMissingClassesWithMixtureOfClassesPerformsAdd() {
void anyMissingClassesWithMixtureOfClassesPerformsAdd() {
this.dependencyCustomizer.ifAnyMissingClasses(getClass().getName(), "does.not.Exist")
.add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
}
@Test
public void anyMissingClassesWithNoMissingClassesDoesNotPerformAdd() {
void anyMissingClassesWithNoMissingClassesDoesNotPerformAdd() {
this.dependencyCustomizer.ifAnyMissingClasses(getClass().getName()).add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
}
@Test
public void allMissingClassesWithNoMissingClassesDoesNotPerformAdd() {
void allMissingClassesWithNoMissingClassesDoesNotPerformAdd() {
this.dependencyCustomizer.ifAllMissingClasses(getClass().getName()).add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
}
@Test
public void allMissingClassesWithMixtureOfClassesDoesNotPerformAdd() {
void allMissingClassesWithMixtureOfClassesDoesNotPerformAdd() {
this.dependencyCustomizer.ifAllMissingClasses(getClass().getName(), "does.not.Exist")
.add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
}
@Test
public void allMissingClassesWithAllClassesMissingPerformsAdd() {
void allMissingClassesWithAllClassesMissingPerformsAdd() {
this.dependencyCustomizer.ifAllMissingClasses("does.not.Exist", "does.not.exist.Either")
.add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);

View File

@@ -16,8 +16,7 @@
package org.springframework.boot.cli.compiler;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -27,39 +26,34 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*
* @author Phillip Webb
*/
public class ExtendedGroovyClassLoaderTests {
class ExtendedGroovyClassLoaderTests {
private ClassLoader contextClassLoader;
private final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
private ExtendedGroovyClassLoader defaultScopeGroovyClassLoader;
@Before
public void setup() {
this.contextClassLoader = Thread.currentThread().getContextClassLoader();
this.defaultScopeGroovyClassLoader = new ExtendedGroovyClassLoader(GroovyCompilerScope.DEFAULT);
}
private final ExtendedGroovyClassLoader defaultScopeGroovyClassLoader = new ExtendedGroovyClassLoader(
GroovyCompilerScope.DEFAULT);
@Test
public void loadsGroovyFromSameClassLoader() throws Exception {
void loadsGroovyFromSameClassLoader() throws Exception {
Class<?> c1 = this.contextClassLoader.loadClass("groovy.lang.Script");
Class<?> c2 = this.defaultScopeGroovyClassLoader.loadClass("groovy.lang.Script");
assertThat(c1.getClassLoader()).isSameAs(c2.getClassLoader());
}
@Test
public void filtersNonGroovy() throws Exception {
void filtersNonGroovy() throws Exception {
this.contextClassLoader.loadClass("org.springframework.util.StringUtils");
assertThatExceptionOfType(ClassNotFoundException.class)
.isThrownBy(() -> this.defaultScopeGroovyClassLoader.loadClass("org.springframework.util.StringUtils"));
}
@Test
public void loadsJavaTypes() throws Exception {
void loadsJavaTypes() throws Exception {
this.defaultScopeGroovyClassLoader.loadClass("java.lang.Boolean");
}
@Test
public void loadsSqlTypes() throws Exception {
void loadsSqlTypes() throws Exception {
this.contextClassLoader.loadClass("java.sql.SQLException");
this.defaultScopeGroovyClassLoader.loadClass("java.sql.SQLException");
}

View File

@@ -31,7 +31,7 @@ import org.codehaus.groovy.ast.expr.ListExpression;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.control.io.ReaderSource;
import org.codehaus.groovy.transform.ASTTransformation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.groovy.DependencyManagementBom;
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
* @author Dave Syer
*/
public final class GenericBomAstTransformationTests {
final class GenericBomAstTransformationTests {
private final SourceUnit sourceUnit = new SourceUnit((String) null, (ReaderSource) null, null, null, null);
@@ -64,21 +64,21 @@ public final class GenericBomAstTransformationTests {
};
@Test
public void transformationOfEmptyPackage() {
void transformationOfEmptyPackage() {
this.moduleNode.setPackage(new PackageNode("foo"));
this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
assertThat(getValue().toString()).isEqualTo("[test:child:1.0.0]");
}
@Test
public void transformationOfClass() {
void transformationOfClass() {
this.moduleNode.addClass(ClassHelper.make("MyClass"));
this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
assertThat(getValue().toString()).isEqualTo("[test:child:1.0.0]");
}
@Test
public void transformationOfClassWithExistingManagedDependencies() {
void transformationOfClassWithExistingManagedDependencies() {
this.moduleNode.setPackage(new PackageNode("foo"));
ClassNode cls = ClassHelper.make("MyClass");
this.moduleNode.addClass(cls);

View File

@@ -20,7 +20,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
@@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public class RepositoryConfigurationFactoryTests {
class RepositoryConfigurationFactoryTests {
@Test
public void defaultRepositories() {
void defaultRepositories() {
TestPropertyValues.of("user.home:src/test/resources/maven-settings/basic").applyToSystemProperties(() -> {
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
.createDefaultRepositoryConfiguration();
@@ -46,7 +46,7 @@ public class RepositoryConfigurationFactoryTests {
}
@Test
public void snapshotRepositoriesDisabled() {
void snapshotRepositoriesDisabled() {
TestPropertyValues.of("user.home:src/test/resources/maven-settings/basic", "disableSpringSnapshotRepos:true")
.applyToSystemProperties(() -> {
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
@@ -57,7 +57,7 @@ public class RepositoryConfigurationFactoryTests {
}
@Test
public void activeByDefaultProfileRepositories() {
void activeByDefaultProfileRepositories() {
TestPropertyValues.of("user.home:src/test/resources/maven-settings/active-profile-repositories")
.applyToSystemProperties(() -> {
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
@@ -69,7 +69,7 @@ public class RepositoryConfigurationFactoryTests {
}
@Test
public void activeByPropertyProfileRepositories() {
void activeByPropertyProfileRepositories() {
TestPropertyValues.of("user.home:src/test/resources/maven-settings/active-profile-repositories", "foo:bar")
.applyToSystemProperties(() -> {
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
@@ -81,7 +81,7 @@ public class RepositoryConfigurationFactoryTests {
}
@Test
public void interpolationProfileRepositories() {
void interpolationProfileRepositories() {
TestPropertyValues
.of("user.home:src/test/resources/maven-settings/active-profile-repositories", "interpolate:true")
.applyToSystemProperties(() -> {

View File

@@ -39,8 +39,8 @@ import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.control.io.ReaderSource;
import org.codehaus.groovy.transform.ASTTransformation;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver;
import org.springframework.boot.cli.compiler.dependencies.SpringBootDependenciesDependencyManagement;
@@ -55,7 +55,7 @@ import static org.mockito.Mockito.mock;
*
* @author Andy Wilkinson
*/
public final class ResolveDependencyCoordinatesTransformationTests {
final class ResolveDependencyCoordinatesTransformationTests {
private final SourceUnit sourceUnit = new SourceUnit((String) null, (ReaderSource) null, null, null, null);
@@ -81,40 +81,40 @@ public final class ResolveDependencyCoordinatesTransformationTests {
private final ASTTransformation transformation = new ResolveDependencyCoordinatesTransformation(
this.resolutionContext);
@Before
public void setupExpectations() {
@BeforeEach
public void setUpExpectations() {
given(this.coordinatesResolver.getGroupId("spring-core")).willReturn("org.springframework");
}
@Test
public void transformationOfAnnotationOnImport() {
void transformationOfAnnotationOnImport() {
this.moduleNode.addImport(null, null, Arrays.asList(this.grabAnnotation));
assertGrabAnnotationHasBeenTransformed();
}
@Test
public void transformationOfAnnotationOnStarImport() {
void transformationOfAnnotationOnStarImport() {
this.moduleNode.addStarImport("org.springframework.util", Arrays.asList(this.grabAnnotation));
assertGrabAnnotationHasBeenTransformed();
}
@Test
public void transformationOfAnnotationOnStaticImport() {
void transformationOfAnnotationOnStaticImport() {
this.moduleNode.addStaticImport(null, null, null, Arrays.asList(this.grabAnnotation));
assertGrabAnnotationHasBeenTransformed();
}
@Test
public void transformationOfAnnotationOnStaticStarImport() {
void transformationOfAnnotationOnStaticStarImport() {
this.moduleNode.addStaticStarImport(null, null, Arrays.asList(this.grabAnnotation));
assertGrabAnnotationHasBeenTransformed();
}
@Test
public void transformationOfAnnotationOnPackage() {
void transformationOfAnnotationOnPackage() {
PackageNode packageNode = new PackageNode("test");
packageNode.addAnnotation(this.grabAnnotation);
this.moduleNode.setPackage(packageNode);
@@ -123,7 +123,7 @@ public final class ResolveDependencyCoordinatesTransformationTests {
}
@Test
public void transformationOfAnnotationOnClass() {
void transformationOfAnnotationOnClass() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
classNode.addAnnotation(this.grabAnnotation);
this.moduleNode.addClass(classNode);
@@ -132,11 +132,11 @@ public final class ResolveDependencyCoordinatesTransformationTests {
}
@Test
public void transformationOfAnnotationOnAnnotation() {
void transformationOfAnnotationOnAnnotation() {
}
@Test
public void transformationOfAnnotationOnField() {
void transformationOfAnnotationOnField() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
@@ -149,7 +149,7 @@ public final class ResolveDependencyCoordinatesTransformationTests {
}
@Test
public void transformationOfAnnotationOnConstructor() {
void transformationOfAnnotationOnConstructor() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
@@ -161,7 +161,7 @@ public final class ResolveDependencyCoordinatesTransformationTests {
}
@Test
public void transformationOfAnnotationOnMethod() {
void transformationOfAnnotationOnMethod() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
@@ -174,7 +174,7 @@ public final class ResolveDependencyCoordinatesTransformationTests {
}
@Test
public void transformationOfAnnotationOnMethodParameter() {
void transformationOfAnnotationOnMethodParameter() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);
@@ -189,7 +189,7 @@ public final class ResolveDependencyCoordinatesTransformationTests {
}
@Test
public void transformationOfAnnotationOnLocalVariable() {
void transformationOfAnnotationOnLocalVariable() {
ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
this.moduleNode.addClass(classNode);

View File

@@ -18,8 +18,8 @@ package org.springframework.boot.cli.compiler.dependencies;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -31,7 +31,7 @@ import static org.mockito.BDDMockito.given;
*
* @author Andy Wilkinson
*/
public class CompositeDependencyManagementTests {
class CompositeDependencyManagementTests {
@Mock
private DependencyManagement dependencyManagement1;
@@ -39,13 +39,13 @@ public class CompositeDependencyManagementTests {
@Mock
private DependencyManagement dependencyManagement2;
@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test
public void unknownSpringBootVersion() {
void unknownSpringBootVersion() {
given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null);
given(this.dependencyManagement2.getSpringBootVersion()).willReturn(null);
assertThat(new CompositeDependencyManagement(this.dependencyManagement1, this.dependencyManagement2)
@@ -53,7 +53,7 @@ public class CompositeDependencyManagementTests {
}
@Test
public void knownSpringBootVersion() {
void knownSpringBootVersion() {
given(this.dependencyManagement1.getSpringBootVersion()).willReturn("1.2.3");
given(this.dependencyManagement2.getSpringBootVersion()).willReturn("1.2.4");
assertThat(new CompositeDependencyManagement(this.dependencyManagement1, this.dependencyManagement2)
@@ -61,7 +61,7 @@ public class CompositeDependencyManagementTests {
}
@Test
public void unknownDependency() {
void unknownDependency() {
given(this.dependencyManagement1.find("artifact")).willReturn(null);
given(this.dependencyManagement2.find("artifact")).willReturn(null);
assertThat(new CompositeDependencyManagement(this.dependencyManagement1, this.dependencyManagement2)
@@ -69,7 +69,7 @@ public class CompositeDependencyManagementTests {
}
@Test
public void knownDependency() {
void knownDependency() {
given(this.dependencyManagement1.find("artifact")).willReturn(new Dependency("test", "artifact", "1.2.3"));
given(this.dependencyManagement2.find("artifact")).willReturn(new Dependency("test", "artifact", "1.2.4"));
assertThat(new CompositeDependencyManagement(this.dependencyManagement1, this.dependencyManagement2)
@@ -77,7 +77,7 @@ public class CompositeDependencyManagementTests {
}
@Test
public void getDependencies() {
void getDependencies() {
given(this.dependencyManagement1.getDependencies())
.willReturn(Arrays.asList(new Dependency("test", "artifact", "1.2.3")));
given(this.dependencyManagement2.getDependencies())

View File

@@ -16,8 +16,8 @@
package org.springframework.boot.cli.compiler.dependencies;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
@@ -32,13 +32,13 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class DependencyManagementArtifactCoordinatesResolverTests {
class DependencyManagementArtifactCoordinatesResolverTests {
private DependencyManagement dependencyManagement;
private DependencyManagementArtifactCoordinatesResolver resolver;
@Before
@BeforeEach
public void setup() {
this.dependencyManagement = mock(DependencyManagement.class);
given(this.dependencyManagement.find("a1")).willReturn(new Dependency("g1", "a1", "0"));
@@ -47,18 +47,18 @@ public class DependencyManagementArtifactCoordinatesResolverTests {
}
@Test
public void getGroupIdForBootArtifact() {
void getGroupIdForBootArtifact() {
assertThat(this.resolver.getGroupId("spring-boot-something")).isEqualTo("org.springframework.boot");
verify(this.dependencyManagement, never()).find(anyString());
}
@Test
public void getGroupIdFound() {
void getGroupIdFound() {
assertThat(this.resolver.getGroupId("a1")).isEqualTo("g1");
}
@Test
public void getGroupIdNotFound() {
void getGroupIdNotFound() {
assertThat(this.resolver.getGroupId("a2")).isNull();
}

View File

@@ -16,7 +16,7 @@
package org.springframework.boot.cli.compiler.dependencies;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.empty;
@@ -26,17 +26,17 @@ import static org.hamcrest.Matchers.empty;
*
* @author Andy Wilkinson
*/
public class SpringBootDependenciesDependencyManagementTests {
class SpringBootDependenciesDependencyManagementTests {
private final DependencyManagement dependencyManagement = new SpringBootDependenciesDependencyManagement();
@Test
public void springBootVersion() {
void springBootVersion() {
assertThat(this.dependencyManagement.getSpringBootVersion()).isNotNull();
}
@Test
public void find() {
void find() {
Dependency dependency = this.dependencyManagement.find("spring-boot");
assertThat(dependency).isNotNull();
assertThat(dependency.getGroupId()).isEqualTo("org.springframework.boot");
@@ -44,7 +44,7 @@ public class SpringBootDependenciesDependencyManagementTests {
}
@Test
public void getDependencies() {
void getDependencies() {
assertThat(this.dependencyManagement.getDependencies()).isNotEqualTo(empty());
}

View File

@@ -30,7 +30,7 @@ import groovy.lang.GroovyClassLoader;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.cli.compiler.dependencies.SpringBootDependenciesDependencyManagement;
import org.springframework.test.util.ReflectionTestUtils;
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*
* @author Andy Wilkinson
*/
public class AetherGrapeEngineTests {
class AetherGrapeEngineTests {
private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
@@ -62,7 +62,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void dependencyResolution() {
void dependencyResolution() {
Map<String, Object> args = new HashMap<>();
createGrapeEngine(this.springMilestones).grab(args,
createDependency("org.springframework", "spring-jdbc", null));
@@ -70,7 +70,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void proxySelector() {
void proxySelector() {
doWithCustomUserHome(() -> {
AetherGrapeEngine grapeEngine = createGrapeEngine();
DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) ReflectionTestUtils
@@ -81,7 +81,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void repositoryMirrors() {
void repositoryMirrors() {
doWithCustomUserHome(() -> {
List<RemoteRepository> repositories = getRepositories();
assertThat(repositories).hasSize(1);
@@ -90,7 +90,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void repositoryAuthentication() {
void repositoryAuthentication() {
doWithCustomUserHome(() -> {
List<RemoteRepository> repositories = getRepositories();
assertThat(repositories).hasSize(1);
@@ -100,7 +100,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void dependencyResolutionWithExclusions() {
void dependencyResolutionWithExclusions() {
Map<String, Object> args = new HashMap<>();
args.put("excludes", Arrays.asList(createExclusion("org.springframework", "spring-core")));
@@ -112,7 +112,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void nonTransitiveDependencyResolution() {
void nonTransitiveDependencyResolution() {
Map<String, Object> args = new HashMap<>();
createGrapeEngine().grab(args, createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE", false));
@@ -121,7 +121,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void dependencyResolutionWithCustomClassLoader() {
void dependencyResolutionWithCustomClassLoader() {
Map<String, Object> args = new HashMap<>();
GroovyClassLoader customClassLoader = new GroovyClassLoader();
args.put("classLoader", customClassLoader);
@@ -134,7 +134,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void resolutionWithCustomResolver() {
void resolutionWithCustomResolver() {
Map<String, Object> args = new HashMap<>();
AetherGrapeEngine grapeEngine = this.createGrapeEngine();
grapeEngine.addResolver(createResolver("spring-releases", "https://repo.spring.io/release"));
@@ -146,7 +146,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void differingTypeAndExt() {
void differingTypeAndExt() {
Map<String, Object> dependency = createDependency("org.grails", "grails-dependencies", "2.4.0");
dependency.put("type", "foo");
dependency.put("ext", "bar");
@@ -155,7 +155,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void pomDependencyResolutionViaType() {
void pomDependencyResolutionViaType() {
Map<String, Object> args = new HashMap<>();
Map<String, Object> dependency = createDependency("org.springframework", "spring-framework-bom",
"4.0.5.RELEASE");
@@ -167,7 +167,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void pomDependencyResolutionViaExt() {
void pomDependencyResolutionViaExt() {
Map<String, Object> args = new HashMap<>();
Map<String, Object> dependency = createDependency("org.springframework", "spring-framework-bom",
"4.0.5.RELEASE");
@@ -179,7 +179,7 @@ public class AetherGrapeEngineTests {
}
@Test
public void resolutionWithClassifier() {
void resolutionWithClassifier() {
Map<String, Object> args = new HashMap<>();
Map<String, Object> dependency = createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE", false);

View File

@@ -16,25 +16,26 @@
package org.springframework.boot.cli.compiler.grape;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.cli.compiler.dependencies.SpringBootDependenciesDependencyManagement;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
* Tests for {@link DependencyResolutionContext}.
*
* @author Dave Syer
*/
public class DependencyResolutionContextTests {
class DependencyResolutionContextTests {
@Test
public void defaultDependenciesEmpty() {
void defaultDependenciesEmpty() {
assertThat(new DependencyResolutionContext().getManagedDependencies()).isEmpty();
}
@Test
public void canAddSpringBootDependencies() {
void canAddSpringBootDependencies() {
DependencyResolutionContext dependencyResolutionContext = new DependencyResolutionContext();
dependencyResolutionContext.addDependencyManagement(new SpringBootDependenciesDependencyManagement());
assertThat(dependencyResolutionContext.getManagedDependencies()).isNotEmpty();

View File

@@ -23,8 +23,8 @@ import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.transfer.TransferEvent;
import org.eclipse.aether.transfer.TransferResource;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
public final class DetailedProgressReporterTests {
final class DetailedProgressReporterTests {
private static final String REPOSITORY = "https://repo.example.com/";
@@ -47,13 +47,13 @@ public final class DetailedProgressReporterTests {
private final DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
@Before
@BeforeEach
public void initialize() {
new DetailedProgressReporter(this.session, this.out);
}
@Test
public void downloading() throws TransferCancelledException {
void downloading() throws TransferCancelledException {
TransferEvent startedEvent = new TransferEvent.Builder(this.session, this.resource).build();
this.session.getTransferListener().transferStarted(startedEvent);
assertThat(new String(this.baos.toByteArray()))
@@ -61,7 +61,7 @@ public final class DetailedProgressReporterTests {
}
@Test
public void downloaded() throws InterruptedException {
void downloaded() throws InterruptedException {
// Ensure some transfer time
Thread.sleep(100);
TransferEvent completedEvent = new TransferEvent.Builder(this.session, this.resource).addTransferredBytes(4096)

View File

@@ -24,8 +24,8 @@ import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.LocalRepositoryManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
@@ -44,20 +44,20 @@ import static org.mockito.Mockito.verify;
*
* @author Andy Wilkinson
*/
public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
class GrapeRootRepositorySystemSessionAutoConfigurationTests {
private DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
@Mock
private RepositorySystem repositorySystem;
@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test
public void noLocalRepositoryWhenNoGrapeRoot() {
void noLocalRepositoryWhenNoGrapeRoot() {
given(this.repositorySystem.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class)))
.willAnswer((invocation) -> {
LocalRepository localRepository = invocation.getArgument(1);
@@ -70,7 +70,7 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
}
@Test
public void grapeRootConfiguresLocalRepositoryLocation() {
void grapeRootConfiguresLocalRepositoryLocation() {
given(this.repositorySystem.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class)))
.willAnswer(new LocalRepositoryManagerAnswer());

View File

@@ -27,8 +27,8 @@ import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.Proxy;
import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -44,28 +44,28 @@ import static org.mockito.BDDMockito.given;
*
* @author Andy Wilkinson
*/
public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
@Mock
private RepositorySystem repositorySystem;
@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test
public void basicSessionCustomization() {
void basicSessionCustomization() {
assertSessionCustomization("src/test/resources/maven-settings/basic");
}
@Test
public void encryptedSettingsSessionCustomization() {
void encryptedSettingsSessionCustomization() {
assertSessionCustomization("src/test/resources/maven-settings/encrypted");
}
@Test
public void propertyInterpolation() {
void propertyInterpolation() {
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
given(this.repositorySystem.newLocalRepositoryManager(eq(session), any(LocalRepository.class)))
.willAnswer((invocation) -> {

View File

@@ -21,7 +21,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.ClassUtils;
@@ -32,17 +32,17 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Dave Syer
*/
public class ResourceUtilsTests {
class ResourceUtilsTests {
@Test
public void explicitClasspathResource() {
void explicitClasspathResource() {
List<String> urls = ResourceUtils.getUrls("classpath:init.groovy", ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
assertThat(urls.get(0).startsWith("file:")).isTrue();
}
@Test
public void duplicateResource() throws Exception {
void duplicateResource() throws Exception {
URLClassLoader loader = new URLClassLoader(new URL[] { new URL("file:./src/test/resources/"),
new File("src/test/resources/").getAbsoluteFile().toURI().toURL() });
List<String> urls = ResourceUtils.getUrls("classpath:init.groovy", loader);
@@ -51,34 +51,34 @@ public class ResourceUtilsTests {
}
@Test
public void explicitClasspathResourceWithSlash() {
void explicitClasspathResourceWithSlash() {
List<String> urls = ResourceUtils.getUrls("classpath:/init.groovy", ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
assertThat(urls.get(0).startsWith("file:")).isTrue();
}
@Test
public void implicitClasspathResource() {
void implicitClasspathResource() {
List<String> urls = ResourceUtils.getUrls("init.groovy", ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
assertThat(urls.get(0).startsWith("file:")).isTrue();
}
@Test
public void implicitClasspathResourceWithSlash() {
void implicitClasspathResourceWithSlash() {
List<String> urls = ResourceUtils.getUrls("/init.groovy", ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
assertThat(urls.get(0).startsWith("file:")).isTrue();
}
@Test
public void nonexistentClasspathResource() {
void nonexistentClasspathResource() {
List<String> urls = ResourceUtils.getUrls("classpath:nonexistent.groovy", null);
assertThat(urls).isEmpty();
}
@Test
public void explicitFile() {
void explicitFile() {
List<String> urls = ResourceUtils.getUrls("file:src/test/resources/init.groovy",
ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
@@ -86,27 +86,27 @@ public class ResourceUtilsTests {
}
@Test
public void implicitFile() {
void implicitFile() {
List<String> urls = ResourceUtils.getUrls("src/test/resources/init.groovy", ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
assertThat(urls.get(0).startsWith("file:")).isTrue();
}
@Test
public void nonexistentFile() {
void nonexistentFile() {
List<String> urls = ResourceUtils.getUrls("file:nonexistent.groovy", null);
assertThat(urls).isEmpty();
}
@Test
public void recursiveFiles() {
void recursiveFiles() {
List<String> urls = ResourceUtils.getUrls("src/test/resources/dir-sample", ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
assertThat(urls.get(0).startsWith("file:")).isTrue();
}
@Test
public void recursiveFilesByPatternWithPrefix() {
void recursiveFilesByPatternWithPrefix() {
List<String> urls = ResourceUtils.getUrls("file:src/test/resources/dir-sample/**/*.groovy",
ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
@@ -114,7 +114,7 @@ public class ResourceUtilsTests {
}
@Test
public void recursiveFilesByPattern() {
void recursiveFilesByPattern() {
List<String> urls = ResourceUtils.getUrls("src/test/resources/dir-sample/**/*.groovy",
ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
@@ -122,7 +122,7 @@ public class ResourceUtilsTests {
}
@Test
public void directoryOfFilesWithPrefix() {
void directoryOfFilesWithPrefix() {
List<String> urls = ResourceUtils.getUrls("file:src/test/resources/dir-sample/code/*",
ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);
@@ -130,7 +130,7 @@ public class ResourceUtilsTests {
}
@Test
public void directoryOfFiles() {
void directoryOfFiles() {
List<String> urls = ResourceUtils.getUrls("src/test/resources/dir-sample/code/*",
ClassUtils.getDefaultClassLoader());
assertThat(urls).hasSize(1);