mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Use AssertJ in spring-boot-cli
See gh-5083
This commit is contained in:
parent
00cfe1d054
commit
962a598531
@ -19,8 +19,7 @@ package org.springframework.boot.cli;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for CLI Classloader issues.
|
||||
@ -37,6 +36,7 @@ public class ClassLoaderIntegrationTests {
|
||||
// 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, containsString("HasClasses-false-true-false"));
|
||||
assertThat(output).contains("HasClasses-false-true-false");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,7 @@ package org.springframework.boot.cli;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for code in directories.
|
||||
@ -35,18 +34,19 @@ public class DirectorySourcesIntegrationTests {
|
||||
@Test
|
||||
public void runDirectory() throws Exception {
|
||||
this.cli.run("code");
|
||||
assertThat(this.cli.getOutput(), containsString("Hello World"));
|
||||
assertThat(this.cli.getOutput()).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runDirectoryRecursive() throws Exception {
|
||||
this.cli.run("");
|
||||
assertThat(this.cli.getOutput(), containsString("Hello World"));
|
||||
assertThat(this.cli.getOutput()).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runPathPattern() throws Exception {
|
||||
this.cli.run("**/*.groovy");
|
||||
assertThat(this.cli.getOutput(), containsString("Hello World"));
|
||||
assertThat(this.cli.getOutput()).contains("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.cli.command.grab.GrabCommand;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@ -58,9 +56,10 @@ public class GrabCommandIntegrationTests {
|
||||
|
||||
// Use --autoconfigure=false to limit the amount of downloaded dependencies
|
||||
String output = this.cli.grab("grab.groovy", "--autoconfigure=false");
|
||||
assertTrue(new File("target/repository/joda-time/joda-time").isDirectory());
|
||||
assertThat(new File("target/repository/joda-time/joda-time").isDirectory())
|
||||
.isTrue();
|
||||
// Should be resolved from local repository cache
|
||||
assertTrue(output.contains("Downloading: file:"));
|
||||
assertThat(output.contains("Downloading: file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,8 +70,8 @@ public class GrabCommandIntegrationTests {
|
||||
fail();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
assertThat(ex.getMessage(),
|
||||
containsString("Duplicate @DependencyManagementBom annotation"));
|
||||
assertThat(ex.getMessage())
|
||||
.contains("Duplicate @DependencyManagementBom annotation");
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,6 +82,7 @@ public class GrabCommandIntegrationTests {
|
||||
new File("src/test/resources/grab-samples/repository"),
|
||||
new File("target/repository"));
|
||||
this.cli.grab("customDependencyManagement.groovy", "--autoconfigure=false");
|
||||
assertTrue(new File("target/repository/javax/ejb/ejb-api/3.0").isDirectory());
|
||||
assertThat(new File("target/repository/javax/ejb/ejb-api/3.0").isDirectory())
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests to exercise and reproduce specific issues.
|
||||
@ -41,8 +40,7 @@ public class ReproIntegrationTests {
|
||||
@Test
|
||||
public void grabAntBuilder() throws Exception {
|
||||
this.cli.run("grab-ant-builder.groovy");
|
||||
assertThat(this.cli.getHttpOutput(),
|
||||
containsString("{\"message\":\"Hello World\"}"));
|
||||
assertThat(this.cli.getHttpOutput()).contains("{\"message\":\"Hello World\"}");
|
||||
}
|
||||
|
||||
// Security depends on old versions of Spring so if the dependencies aren't pinned
|
||||
@ -50,20 +48,19 @@ public class ReproIntegrationTests {
|
||||
@Test
|
||||
public void securityDependencies() throws Exception {
|
||||
this.cli.run("secure.groovy");
|
||||
assertThat(this.cli.getOutput(), containsString("Hello World"));
|
||||
assertThat(this.cli.getOutput()).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shellDependencies() throws Exception {
|
||||
this.cli.run("crsh.groovy");
|
||||
assertThat(this.cli.getHttpOutput(),
|
||||
containsString("{\"message\":\"Hello World\"}"));
|
||||
assertThat(this.cli.getHttpOutput()).contains("{\"message\":\"Hello World\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataJpaDependencies() throws Exception {
|
||||
this.cli.run("data-jpa.groovy");
|
||||
assertThat(this.cli.getOutput(), containsString("Hello World"));
|
||||
assertThat(this.cli.getOutput()).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -23,10 +23,7 @@ import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests to exercise the samples.
|
||||
@ -45,45 +42,40 @@ public class SampleIntegrationTests {
|
||||
public void appSample() throws Exception {
|
||||
String output = this.cli.run("app.groovy");
|
||||
URI scriptUri = new File("samples/app.groovy").toURI();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("Hello World! From " + scriptUri));
|
||||
assertThat(output).contains("Hello World! From " + scriptUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrySample() throws Exception {
|
||||
String output = this.cli.run("retry.groovy");
|
||||
URI scriptUri = new File("samples/retry.groovy").toURI();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("Hello World! From " + scriptUri));
|
||||
assertThat(output).contains("Hello World! From " + scriptUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beansSample() throws Exception {
|
||||
this.cli.run("beans.groovy");
|
||||
String output = this.cli.getHttpOutput();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World!"));
|
||||
assertThat(output).contains("Hello World!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void templateSample() throws Exception {
|
||||
String output = this.cli.run("template.groovy");
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World!"));
|
||||
assertThat(output).contains("Hello World!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jobSample() throws Exception {
|
||||
String output = this.cli.run("job.groovy", "foo=bar");
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("completed with the following parameters"));
|
||||
assertThat(output).contains("completed with the following parameters");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oauth2Sample() throws Exception {
|
||||
String output = this.cli.run("oauth2.groovy");
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("security.oauth2.client.clientId"));
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("security.oauth2.client.secret ="));
|
||||
assertThat(output).contains("security.oauth2.client.clientId");
|
||||
assertThat(output).contains("security.oauth2.client.secret =");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,88 +86,85 @@ public class SampleIntegrationTests {
|
||||
Thread.sleep(200);
|
||||
output = this.cli.getOutput();
|
||||
}
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Phil"));
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jobWebSample() throws Exception {
|
||||
String output = this.cli.run("job.groovy", "web.groovy", "foo=bar");
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("completed with the following parameters"));
|
||||
assertThat(output).contains("completed with the following parameters");
|
||||
String result = this.cli.getHttpOutput();
|
||||
assertEquals("World!", result);
|
||||
assertThat(result).isEqualTo("World!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webSample() throws Exception {
|
||||
this.cli.run("web.groovy");
|
||||
assertEquals("World!", this.cli.getHttpOutput());
|
||||
assertThat(this.cli.getHttpOutput()).isEqualTo("World!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uiSample() throws Exception {
|
||||
this.cli.run("ui.groovy", "--classpath=.:src/test/resources");
|
||||
String result = this.cli.getHttpOutput();
|
||||
assertTrue("Wrong output: " + result, result.contains("Hello World"));
|
||||
assertThat(result).contains("Hello World");
|
||||
result = this.cli.getHttpOutput("/css/bootstrap.min.css");
|
||||
assertTrue("Wrong output: " + result, result.contains("container"));
|
||||
assertThat(result).contains("container");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorSample() throws Exception {
|
||||
this.cli.run("actuator.groovy");
|
||||
assertEquals("{\"message\":\"Hello World!\"}", this.cli.getHttpOutput());
|
||||
assertThat(this.cli.getHttpOutput()).isEqualTo("{\"message\":\"Hello World!\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpSample() throws Exception {
|
||||
String output = this.cli.run("http.groovy");
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World"));
|
||||
assertThat(output).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationSample() throws Exception {
|
||||
String output = this.cli.run("integration.groovy");
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello, World"));
|
||||
assertThat(output).contains("Hello, World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlSample() throws Exception {
|
||||
String output = this.cli.run("runner.xml", "runner.groovy");
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World"));
|
||||
assertThat(output).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void txSample() throws Exception {
|
||||
String output = this.cli.run("tx.groovy");
|
||||
assertTrue("Wrong output: " + output, output.contains("Foo count="));
|
||||
assertThat(output).contains("Foo count=");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jmsSample() throws Exception {
|
||||
String output = this.cli.run("jms.groovy");
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("Received Greetings from Spring Boot via HornetQ"));
|
||||
assertThat(output).contains("Received Greetings from Spring Boot via HornetQ");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Requires RabbitMQ to be run, so disable it be default")
|
||||
public void rabbitSample() throws Exception {
|
||||
String output = this.cli.run("rabbit.groovy");
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("Received Greetings from Spring Boot via RabbitMQ"));
|
||||
assertThat(output).contains("Received Greetings from Spring Boot via RabbitMQ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deviceSample() throws Exception {
|
||||
this.cli.run("device.groovy");
|
||||
assertEquals("Hello Normal Device!", this.cli.getHttpOutput());
|
||||
assertThat(this.cli.getHttpOutput()).isEqualTo("Hello Normal Device!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caching() throws Exception {
|
||||
this.cli.run("caching.groovy");
|
||||
assertThat(this.cli.getOutput(), containsString("Hello World"));
|
||||
assertThat(this.cli.getOutput()).contains("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,8 +24,7 @@ import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.cli.command.test.TestCommand;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests to exercise the CLI's test command.
|
||||
@ -54,13 +53,13 @@ public class TestCommandIntegrationTests {
|
||||
@Test
|
||||
public void noTests() throws Throwable {
|
||||
String output = this.cli.test("book.groovy");
|
||||
assertThat(output, containsString("No tests found"));
|
||||
assertThat(output).contains("No tests found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void empty() throws Exception {
|
||||
String output = this.cli.test("empty.groovy");
|
||||
assertThat(output, containsString("No tests found"));
|
||||
assertThat(output).contains("No tests found");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -74,48 +73,49 @@ public class TestCommandIntegrationTests {
|
||||
@Test
|
||||
public void appAndTestsInOneFile() throws Exception {
|
||||
String output = this.cli.test("book_and_tests.groovy");
|
||||
assertThat(output, containsString("OK (1 test)"));
|
||||
assertThat(output).contains("OK (1 test)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appInOneFileTestsInAnotherFile() throws Exception {
|
||||
String output = this.cli.test("book.groovy", "test.groovy");
|
||||
assertThat(output, containsString("OK (1 test)"));
|
||||
assertThat(output).contains("OK (1 test)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationTest() throws Exception {
|
||||
String output = this.cli.test("integration.groovy");
|
||||
assertThat(output, containsString("OK (1 test)"));
|
||||
assertThat(output).contains("OK (1 test)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationAutoConfigEmbeddedTest() throws Exception {
|
||||
String output = this.cli.test("integration_auto.groovy");
|
||||
assertThat(output, containsString("OK (1 test)"));
|
||||
assertThat(output).contains("OK (1 test)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationAutoConfigTest() throws Exception {
|
||||
String output = this.cli.test("integration_auto_test.groovy", "reactor.groovy");
|
||||
assertThat(output, containsString("OK (1 test)"));
|
||||
assertThat(output).contains("OK (1 test)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spockTester() throws Exception {
|
||||
String output = this.cli.test("spock.groovy");
|
||||
assertThat(output, containsString("OK (1 test)"));
|
||||
assertThat(output).contains("OK (1 test)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spockAndJunitTester() throws Exception {
|
||||
String output = this.cli.test("spock.groovy", "book_and_tests.groovy");
|
||||
assertThat(output, containsString("OK (2 tests)"));
|
||||
assertThat(output).contains("OK (2 tests)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyFailures() throws Exception {
|
||||
String output = this.cli.test("failures.groovy");
|
||||
assertThat(output, containsString("Tests run: 5, Failures: 3"));
|
||||
assertThat(output).contains("Tests run: 5, Failures: 3");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,10 +24,7 @@ import java.util.Set;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringApplicationLauncher}
|
||||
@ -45,21 +42,21 @@ public class SpringApplicationLauncherTests {
|
||||
|
||||
@Test
|
||||
public void defaultLaunch() throws Exception {
|
||||
assertThat(launch(), contains("org.springframework.boot.SpringApplication"));
|
||||
assertThat(launch()).contains("org.springframework.boot.SpringApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithClassConfiguredBySystemProperty() {
|
||||
System.setProperty("spring.application.class.name",
|
||||
"system.property.SpringApplication");
|
||||
assertThat(launch(), contains("system.property.SpringApplication"));
|
||||
assertThat(launch()).contains("system.property.SpringApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchWithClassConfiguredByEnvironmentVariable() {
|
||||
this.env.put("SPRING_APPLICATION_CLASS_NAME",
|
||||
"environment.variable.SpringApplication");
|
||||
assertThat(launch(), contains("environment.variable.SpringApplication"));
|
||||
assertThat(launch()).contains("environment.variable.SpringApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -68,7 +65,7 @@ public class SpringApplicationLauncherTests {
|
||||
"system.property.SpringApplication");
|
||||
this.env.put("SPRING_APPLICATION_CLASS_NAME",
|
||||
"environment.variable.SpringApplication");
|
||||
assertThat(launch(), contains("system.property.SpringApplication"));
|
||||
assertThat(launch()).contains("system.property.SpringApplication");
|
||||
|
||||
}
|
||||
|
||||
@ -80,14 +77,12 @@ public class SpringApplicationLauncherTests {
|
||||
String[] args = new String[0];
|
||||
new SpringApplicationLauncher(getClass().getClassLoader()).launch(sources, args);
|
||||
|
||||
assertTrue(sources == TestSpringApplication.sources);
|
||||
assertTrue(args == TestSpringApplication.args);
|
||||
assertThat(sources == TestSpringApplication.sources).isTrue();
|
||||
assertThat(args == TestSpringApplication.args).isTrue();
|
||||
|
||||
Map<String, String> defaultProperties = TestSpringApplication.defaultProperties;
|
||||
assertThat(defaultProperties.size(), equalTo(1));
|
||||
assertThat(
|
||||
defaultProperties.get("spring.groovy.template.check-template-location"),
|
||||
equalTo("false"));
|
||||
assertThat(defaultProperties).hasSize(1)
|
||||
.containsEntry("spring.groovy.template.check-template-location", "false");
|
||||
}
|
||||
|
||||
private Set<String> launch() {
|
||||
|
@ -22,8 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.cli.command.run.RunCommand;
|
||||
import org.springframework.boot.cli.util.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@ -40,7 +39,7 @@ public class CommandRunnerIntegrationTests {
|
||||
// -d counts as "debug" for the spring command, but not for the
|
||||
// LoggingApplicationListener
|
||||
runner.runAndHandleErrors("run", "samples/app.groovy", "-d");
|
||||
assertTrue(this.output.toString().contains("Negative matches:"));
|
||||
assertThat(this.output.toString()).contains("Negative matches:");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -48,6 +47,6 @@ public class CommandRunnerIntegrationTests {
|
||||
CommandRunner runner = new CommandRunner("spring");
|
||||
runner.addCommand(new RunCommand());
|
||||
runner.runAndHandleErrors("run", "samples/app.groovy", "--", "-d");
|
||||
assertFalse(this.output.toString().contains("Negative matches:"));
|
||||
assertThat(this.output.toString()).doesNotContain("Negative matches:");
|
||||
}
|
||||
}
|
||||
|
@ -30,10 +30,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.boot.cli.command.core.HelpCommand;
|
||||
import org.springframework.boot.cli.command.core.HintCommand;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -126,64 +123,61 @@ public class CommandRunnerTests {
|
||||
verify(this.regularCommand).run("--", "--debug", "bar");
|
||||
// When handled by the command itself it shouldn't cause the system property to be
|
||||
// set
|
||||
assertNull(System.getProperty("debug"));
|
||||
assertThat(System.getProperty("debug")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesSuccess() throws Exception {
|
||||
int status = this.commandRunner.runAndHandleErrors("command");
|
||||
assertThat(status, equalTo(0));
|
||||
assertThat(this.calls, equalTo((Set<Call>) EnumSet.noneOf(Call.class)));
|
||||
assertThat(status).isEqualTo(0);
|
||||
assertThat(this.calls).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesNoSuchCommand() throws Exception {
|
||||
int status = this.commandRunner.runAndHandleErrors("missing");
|
||||
assertThat(status, equalTo(1));
|
||||
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE)));
|
||||
assertThat(status).isEqualTo(1);
|
||||
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesRegularExceptionWithMessage() throws Exception {
|
||||
willThrow(new RuntimeException("With Message")).given(this.regularCommand).run();
|
||||
int status = this.commandRunner.runAndHandleErrors("command");
|
||||
assertThat(status, equalTo(1));
|
||||
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE)));
|
||||
assertThat(status).isEqualTo(1);
|
||||
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesRegularExceptionWithoutMessage() throws Exception {
|
||||
willThrow(new NullPointerException()).given(this.regularCommand).run();
|
||||
int status = this.commandRunner.runAndHandleErrors("command");
|
||||
assertThat(status, equalTo(1));
|
||||
assertThat(this.calls, equalTo(
|
||||
(Set<Call>) EnumSet.of(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE)));
|
||||
assertThat(status).isEqualTo(1);
|
||||
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesExceptionWithDashD() throws Exception {
|
||||
willThrow(new RuntimeException()).given(this.regularCommand).run();
|
||||
int status = this.commandRunner.runAndHandleErrors("command", "-d");
|
||||
assertEquals("true", System.getProperty("debug"));
|
||||
assertThat(status, equalTo(1));
|
||||
assertThat(this.calls, equalTo(
|
||||
(Set<Call>) EnumSet.of(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE)));
|
||||
assertThat(System.getProperty("debug")).isEqualTo("true");
|
||||
assertThat(status).isEqualTo(1);
|
||||
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesExceptionWithDashDashDebug() throws Exception {
|
||||
willThrow(new RuntimeException()).given(this.regularCommand).run();
|
||||
int status = this.commandRunner.runAndHandleErrors("command", "--debug");
|
||||
assertEquals("true", System.getProperty("debug"));
|
||||
assertThat(status, equalTo(1));
|
||||
assertThat(this.calls, equalTo(
|
||||
(Set<Call>) EnumSet.of(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE)));
|
||||
assertThat(System.getProperty("debug")).isEqualTo("true");
|
||||
assertThat(status).isEqualTo(1);
|
||||
assertThat(this.calls).containsOnly(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionMessages() throws Exception {
|
||||
assertThat(new NoSuchCommandException("name").getMessage(),
|
||||
equalTo("'name' is not a valid command. See 'help'."));
|
||||
assertThat(new NoSuchCommandException("name").getMessage())
|
||||
.isEqualTo("'name' is not a valid command. See 'help'.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -20,8 +20,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.cli.command.options.OptionHandler;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link OptionParsingCommand}.
|
||||
@ -34,9 +33,17 @@ public class OptionParsingCommandTests {
|
||||
public void optionHelp() {
|
||||
OptionHandler handler = new OptionHandler();
|
||||
handler.option("bar", "Bar");
|
||||
OptionParsingCommand command = new OptionParsingCommand("foo", "Foo", handler) {
|
||||
};
|
||||
assertThat(command.getHelp(), containsString("--bar"));
|
||||
OptionParsingCommand command = new TestOptionParsingCommand("foo", "Foo",
|
||||
handler);
|
||||
assertThat(command.getHelp()).contains("--bar");
|
||||
}
|
||||
|
||||
private static class TestOptionParsingCommand extends OptionParsingCommand {
|
||||
|
||||
TestOptionParsingCommand(String name, String description, OptionHandler handler) {
|
||||
super(name, description, handler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,19 +23,13 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.cli.command.archive.ResourceMatcher.MatchedResource;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ResourceMatcher}.
|
||||
@ -51,7 +45,7 @@ public class ResourceMatcherTests {
|
||||
Arrays.asList(".*", "alpha/**/excluded"));
|
||||
List<MatchedResource> matchedResources = resourceMatcher
|
||||
.find(Arrays.asList(new File("does-not-exist")));
|
||||
assertEquals(0, matchedResources.size());
|
||||
assertThat(matchedResources).isEmpty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -59,10 +53,12 @@ public class ResourceMatcherTests {
|
||||
public void defaults() throws Exception {
|
||||
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList(""),
|
||||
Arrays.asList(""));
|
||||
assertTrue(((Collection<String>) ReflectionTestUtils.getField(resourceMatcher,
|
||||
"includes")).contains("static/**"));
|
||||
assertTrue(((Collection<String>) ReflectionTestUtils.getField(resourceMatcher,
|
||||
"excludes")).contains("**/*.jar"));
|
||||
Collection<String> includes = (Collection<String>) ReflectionTestUtils
|
||||
.getField(resourceMatcher, "includes");
|
||||
Collection<String> excludes = (Collection<String>) ReflectionTestUtils
|
||||
.getField(resourceMatcher, "excludes");
|
||||
assertThat(includes).contains("static/**");
|
||||
assertThat(excludes).contains("**/*.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,7 +67,14 @@ public class ResourceMatcherTests {
|
||||
Arrays.asList("**/*.jar"));
|
||||
List<MatchedResource> found = resourceMatcher
|
||||
.find(Arrays.asList(new File("src/test/resources")));
|
||||
assertThat(found, not(hasItem(new FooJarMatcher(MatchedResource.class))));
|
||||
assertThat(found).areNot(new Condition<MatchedResource>() {
|
||||
|
||||
@Override
|
||||
public boolean matches(MatchedResource value) {
|
||||
return value.getFile().getName().equals("foo.jar");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -81,8 +84,8 @@ public class ResourceMatcherTests {
|
||||
Arrays.asList(""));
|
||||
Collection<String> includes = (Collection<String>) ReflectionTestUtils
|
||||
.getField(resourceMatcher, "includes");
|
||||
assertTrue(includes.contains("templates/**"));
|
||||
assertFalse(includes.contains("static/**"));
|
||||
assertThat(includes).contains("templates/**");
|
||||
assertThat(includes).doesNotContain("static/**");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -92,11 +95,12 @@ public class ResourceMatcherTests {
|
||||
Arrays.asList("-static/**", "foo.jar"), Arrays.asList("-**/*.jar"));
|
||||
Collection<String> includes = (Collection<String>) ReflectionTestUtils
|
||||
.getField(resourceMatcher, "includes");
|
||||
assertTrue(includes.contains("foo.jar"));
|
||||
assertTrue(includes.contains("templates/**"));
|
||||
assertFalse(includes.contains("static/**"));
|
||||
assertFalse(((Collection<String>) ReflectionTestUtils.getField(resourceMatcher,
|
||||
"excludes")).contains("**/*.jar"));
|
||||
Collection<String> excludes = (Collection<String>) ReflectionTestUtils
|
||||
.getField(resourceMatcher, "excludes");
|
||||
assertThat(includes).contains("foo.jar");
|
||||
assertThat(includes).contains("templates/**");
|
||||
assertThat(includes).doesNotContain("static/**");
|
||||
assertThat(excludes).doesNotContain("**/*.jar");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -104,8 +108,9 @@ public class ResourceMatcherTests {
|
||||
public void excludedDeltas() throws Exception {
|
||||
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList(""),
|
||||
Arrays.asList("-**/*.jar"));
|
||||
assertFalse(((Collection<String>) ReflectionTestUtils.getField(resourceMatcher,
|
||||
"excludes")).contains("**/*.jar"));
|
||||
Collection<String> excludes = (Collection<String>) ReflectionTestUtils
|
||||
.getField(resourceMatcher, "excludes");
|
||||
assertThat(excludes).doesNotContain("**/*.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -115,10 +120,14 @@ public class ResourceMatcherTests {
|
||||
List<MatchedResource> found = resourceMatcher
|
||||
.find(Arrays.asList(new File("src/test/resources/templates"),
|
||||
new File("src/test/resources/foo.jar")));
|
||||
FooJarMatcher matcher = new FooJarMatcher(MatchedResource.class);
|
||||
assertThat(found, hasItem(matcher));
|
||||
// A jar file is always treated as a dependency (stick it in /lib)
|
||||
assertTrue(matcher.getMatched().isRoot());
|
||||
assertThat(found).areAtLeastOne(new Condition<MatchedResource>() {
|
||||
|
||||
@Override
|
||||
public boolean matches(MatchedResource value) {
|
||||
return value.getFile().getName().equals("foo.jar") && value.isRoot();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -135,37 +144,8 @@ public class ResourceMatcherTests {
|
||||
for (MatchedResource resource : matchedResources) {
|
||||
paths.add(resource.getName());
|
||||
}
|
||||
|
||||
assertEquals(6, paths.size());
|
||||
assertTrue(paths.containsAll(Arrays.asList("alpha/nested/fileA", "bravo/fileC",
|
||||
"fileD", "bravo/fileE", "fileF", "three")));
|
||||
}
|
||||
|
||||
private final class FooJarMatcher extends TypeSafeMatcher<MatchedResource> {
|
||||
|
||||
private MatchedResource matched;
|
||||
|
||||
public MatchedResource getMatched() {
|
||||
return this.matched;
|
||||
}
|
||||
|
||||
private FooJarMatcher(Class<?> expectedType) {
|
||||
super(expectedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("foo.jar");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesSafely(MatchedResource item) {
|
||||
boolean matches = item.getFile().getName().equals("foo.jar");
|
||||
if (matches) {
|
||||
this.matched = item;
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
assertThat(paths).containsOnly("alpha/nested/fileA", "bravo/fileC", "fileD",
|
||||
"bravo/fileE", "fileF", "three");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,12 +37,7 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.boot.cli.command.status.ExitStatus;
|
||||
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
@ -96,16 +91,16 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
public void generateProject() throws Exception {
|
||||
String fileName = UUID.randomUUID().toString() + ".zip";
|
||||
File file = new File(fileName);
|
||||
assertFalse("file should not exist", file.exists());
|
||||
assertThat(file.exists()).as("file should not exist").isFalse();
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", fileName);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
try {
|
||||
assertEquals(ExitStatus.OK, this.command.run());
|
||||
assertTrue("file should have been created", file.exists());
|
||||
assertThat(this.command.run()).isEqualTo(ExitStatus.OK);
|
||||
assertThat(file.exists()).as("file should have been created").isTrue();
|
||||
}
|
||||
finally {
|
||||
assertTrue("failed to delete test file", file.delete());
|
||||
assertThat(file.delete()).as("failed to delete test file").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +109,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", null);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals(ExitStatus.ERROR, this.command.run());
|
||||
assertThat(this.command.run()).isEqualTo(ExitStatus.ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -124,11 +119,10 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", "demo.zip", archive);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals(ExitStatus.OK,
|
||||
this.command.run("--extract", folder.getAbsolutePath()));
|
||||
assertThat(this.command.run("--extract", folder.getAbsolutePath()))
|
||||
.isEqualTo(ExitStatus.OK);
|
||||
File archiveFile = new File(folder, "test.txt");
|
||||
assertTrue("Archive not extracted properly " + archiveFile.getAbsolutePath()
|
||||
+ " not found", archiveFile.exists());
|
||||
assertThat(archiveFile).exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -138,16 +132,16 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", "demo.zip", archive);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals(ExitStatus.OK, this.command.run(folder.getAbsolutePath() + "/"));
|
||||
assertThat(this.command.run(folder.getAbsolutePath() + "/"))
|
||||
.isEqualTo(ExitStatus.OK);
|
||||
File archiveFile = new File(folder, "test.txt");
|
||||
assertTrue("Archive not extracted properly " + archiveFile.getAbsolutePath()
|
||||
+ " not found", archiveFile.exists());
|
||||
assertThat(archiveFile).exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateProjectArchiveExtractedByDefault() throws Exception {
|
||||
String fileName = UUID.randomUUID().toString();
|
||||
assertFalse("No dot in filename", fileName.contains("."));
|
||||
assertThat(fileName.contains(".")).as("No dot in filename").isFalse();
|
||||
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", "demo.zip", archive);
|
||||
@ -155,9 +149,8 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
File file = new File(fileName);
|
||||
File archiveFile = new File(file, "test.txt");
|
||||
try {
|
||||
assertEquals(ExitStatus.OK, this.command.run(fileName));
|
||||
assertTrue("Archive not extracted properly " + archiveFile.getAbsolutePath()
|
||||
+ " not found", archiveFile.exists());
|
||||
assertThat(this.command.run(fileName)).isEqualTo(ExitStatus.OK);
|
||||
assertThat(archiveFile).exists();
|
||||
}
|
||||
finally {
|
||||
archiveFile.delete();
|
||||
@ -175,9 +168,9 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
File file = new File(fileName);
|
||||
try {
|
||||
assertEquals(ExitStatus.OK, this.command.run(fileName));
|
||||
assertTrue("File not saved properly", file.exists());
|
||||
assertTrue("Should not be a directory", file.isFile());
|
||||
assertThat(this.command.run(fileName)).isEqualTo(ExitStatus.OK);
|
||||
assertThat(file.exists()).as("File not saved properly").isTrue();
|
||||
assertThat(file.isFile()).as("Should not be a directory").isTrue();
|
||||
}
|
||||
finally {
|
||||
file.delete();
|
||||
@ -189,18 +182,18 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
File folder = this.temporaryFolder.newFolder();
|
||||
String fileName = UUID.randomUUID().toString() + ".zip";
|
||||
File file = new File(fileName);
|
||||
assertFalse("file should not exist", file.exists());
|
||||
assertThat(file.exists()).as("file should not exist").isFalse();
|
||||
try {
|
||||
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/foobar", fileName, archive);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals(ExitStatus.OK,
|
||||
this.command.run("--extract", folder.getAbsolutePath()));
|
||||
assertTrue("file should have been saved instead", file.exists());
|
||||
assertThat(this.command.run("--extract", folder.getAbsolutePath()))
|
||||
.isEqualTo(ExitStatus.OK);
|
||||
assertThat(file.exists()).as("file should have been saved instead").isTrue();
|
||||
}
|
||||
finally {
|
||||
assertTrue("failed to delete test file", file.delete());
|
||||
assertThat(file.delete()).as("failed to delete test file").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,18 +202,18 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
File folder = this.temporaryFolder.newFolder();
|
||||
String fileName = UUID.randomUUID().toString() + ".zip";
|
||||
File file = new File(fileName);
|
||||
assertFalse("file should not exist", file.exists());
|
||||
assertThat(file.exists()).as("file should not exist").isFalse();
|
||||
try {
|
||||
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
null, fileName, archive);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals(ExitStatus.OK,
|
||||
this.command.run("--extract", folder.getAbsolutePath()));
|
||||
assertTrue("file should have been saved instead", file.exists());
|
||||
assertThat(this.command.run("--extract", folder.getAbsolutePath()))
|
||||
.isEqualTo(ExitStatus.OK);
|
||||
assertThat(file.exists()).as("file should have been saved instead").isTrue();
|
||||
}
|
||||
finally {
|
||||
assertTrue("failed to delete test file", file.delete());
|
||||
assertThat(file.delete()).as("failed to delete test file").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,8 +224,10 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", file.getAbsolutePath());
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals("Should have failed", ExitStatus.ERROR, this.command.run());
|
||||
assertEquals("File should not have changed", fileLength, file.length());
|
||||
assertThat(this.command.run()).as("Should have failed")
|
||||
.isEqualTo(ExitStatus.ERROR);
|
||||
assertThat(file.length()).as("File should not have changed")
|
||||
.isEqualTo(fileLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -242,25 +237,26 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", file.getAbsolutePath());
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals("Should not have failed", ExitStatus.OK,
|
||||
this.command.run("--force"));
|
||||
assertTrue("File should have changed", fileLength != file.length());
|
||||
assertThat(this.command.run("--force")).isEqualTo(ExitStatus.OK);
|
||||
assertThat(fileLength != file.length()).as("File should have changed").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileInArchiveNotOverwrittenByDefault() throws Exception {
|
||||
File folder = this.temporaryFolder.newFolder();
|
||||
File conflict = new File(folder, "test.txt");
|
||||
assertTrue("Should have been able to create file", conflict.createNewFile());
|
||||
assertThat(conflict.createNewFile()).as("Should have been able to create file")
|
||||
.isTrue();
|
||||
long fileLength = conflict.length();
|
||||
// also contains test.txt
|
||||
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", "demo.zip", archive);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals(ExitStatus.ERROR,
|
||||
this.command.run("--extract", folder.getAbsolutePath()));
|
||||
assertEquals("File should not have changed", fileLength, conflict.length());
|
||||
assertThat(this.command.run("--extract", folder.getAbsolutePath()))
|
||||
.isEqualTo(ExitStatus.ERROR);
|
||||
assertThat(conflict.length()).as("File should not have changed")
|
||||
.isEqualTo(fileLength);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -270,90 +266,93 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
"--description=Acme sample project", "--package-name=demo.foo",
|
||||
"-t=ant-project", "--build=grunt", "--format=web", "-p=war", "-j=1.9",
|
||||
"-l=groovy", "-b=1.2.0.RELEASE", "-d=web,data-jpa");
|
||||
assertEquals("org.demo", this.handler.lastRequest.getGroupId());
|
||||
assertEquals("acme", this.handler.lastRequest.getArtifactId());
|
||||
assertEquals("1.2.3-SNAPSHOT", this.handler.lastRequest.getVersion());
|
||||
assertEquals("acme-sample", this.handler.lastRequest.getName());
|
||||
assertEquals("Acme sample project", this.handler.lastRequest.getDescription());
|
||||
assertEquals("demo.foo", this.handler.lastRequest.getPackageName());
|
||||
assertEquals("ant-project", this.handler.lastRequest.getType());
|
||||
assertEquals("grunt", this.handler.lastRequest.getBuild());
|
||||
assertEquals("web", this.handler.lastRequest.getFormat());
|
||||
assertEquals("war", this.handler.lastRequest.getPackaging());
|
||||
assertEquals("1.9", this.handler.lastRequest.getJavaVersion());
|
||||
assertEquals("groovy", this.handler.lastRequest.getLanguage());
|
||||
assertEquals("1.2.0.RELEASE", this.handler.lastRequest.getBootVersion());
|
||||
assertThat(this.handler.lastRequest.getGroupId()).isEqualTo("org.demo");
|
||||
assertThat(this.handler.lastRequest.getArtifactId()).isEqualTo("acme");
|
||||
assertThat(this.handler.lastRequest.getVersion()).isEqualTo("1.2.3-SNAPSHOT");
|
||||
assertThat(this.handler.lastRequest.getName()).isEqualTo("acme-sample");
|
||||
assertThat(this.handler.lastRequest.getDescription())
|
||||
.isEqualTo("Acme sample project");
|
||||
assertThat(this.handler.lastRequest.getPackageName()).isEqualTo("demo.foo");
|
||||
assertThat(this.handler.lastRequest.getType()).isEqualTo("ant-project");
|
||||
assertThat(this.handler.lastRequest.getBuild()).isEqualTo("grunt");
|
||||
assertThat(this.handler.lastRequest.getFormat()).isEqualTo("web");
|
||||
assertThat(this.handler.lastRequest.getPackaging()).isEqualTo("war");
|
||||
assertThat(this.handler.lastRequest.getJavaVersion()).isEqualTo("1.9");
|
||||
assertThat(this.handler.lastRequest.getLanguage()).isEqualTo("groovy");
|
||||
assertThat(this.handler.lastRequest.getBootVersion()).isEqualTo("1.2.0.RELEASE");
|
||||
List<String> dependencies = this.handler.lastRequest.getDependencies();
|
||||
assertEquals(2, dependencies.size());
|
||||
assertTrue(dependencies.contains("web"));
|
||||
assertTrue(dependencies.contains("data-jpa"));
|
||||
assertThat(dependencies).hasSize(2);
|
||||
assertThat(dependencies.contains("web")).isTrue();
|
||||
assertThat(dependencies.contains("data-jpa")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overwriteFileInArchive() throws Exception {
|
||||
File folder = this.temporaryFolder.newFolder();
|
||||
File conflict = new File(folder, "test.txt");
|
||||
assertTrue("Should have been able to create file", conflict.createNewFile());
|
||||
assertThat(conflict.createNewFile()).as("Should have been able to create file")
|
||||
.isTrue();
|
||||
long fileLength = conflict.length();
|
||||
// also contains test.txt
|
||||
byte[] archive = createFakeZipArchive("test.txt", "Fake content");
|
||||
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
|
||||
"application/zip", "demo.zip", archive);
|
||||
mockSuccessfulProjectGeneration(request);
|
||||
assertEquals(ExitStatus.OK,
|
||||
this.command.run("--force", "--extract", folder.getAbsolutePath()));
|
||||
assertTrue("File should have changed", fileLength != conflict.length());
|
||||
assertThat(this.command.run("--force", "--extract", folder.getAbsolutePath()))
|
||||
.isEqualTo(ExitStatus.OK);
|
||||
assertThat(fileLength != conflict.length()).as("File should have changed")
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTypeOnly() throws Exception {
|
||||
this.handler.disableProjectGeneration();
|
||||
this.command.run("-t=ant-project");
|
||||
assertEquals("maven", this.handler.lastRequest.getBuild());
|
||||
assertEquals("project", this.handler.lastRequest.getFormat());
|
||||
assertFalse(this.handler.lastRequest.isDetectType());
|
||||
assertEquals("ant-project", this.handler.lastRequest.getType());
|
||||
assertThat(this.handler.lastRequest.getBuild()).isEqualTo("maven");
|
||||
assertThat(this.handler.lastRequest.getFormat()).isEqualTo("project");
|
||||
assertThat(this.handler.lastRequest.isDetectType()).isFalse();
|
||||
assertThat(this.handler.lastRequest.getType()).isEqualTo("ant-project");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseBuildOnly() throws Exception {
|
||||
this.handler.disableProjectGeneration();
|
||||
this.command.run("--build=ant");
|
||||
assertEquals("ant", this.handler.lastRequest.getBuild());
|
||||
assertEquals("project", this.handler.lastRequest.getFormat());
|
||||
assertTrue(this.handler.lastRequest.isDetectType());
|
||||
assertNull(this.handler.lastRequest.getType());
|
||||
assertThat(this.handler.lastRequest.getBuild()).isEqualTo("ant");
|
||||
assertThat(this.handler.lastRequest.getFormat()).isEqualTo("project");
|
||||
assertThat(this.handler.lastRequest.isDetectType()).isTrue();
|
||||
assertThat(this.handler.lastRequest.getType()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFormatOnly() throws Exception {
|
||||
this.handler.disableProjectGeneration();
|
||||
this.command.run("--format=web");
|
||||
assertEquals("maven", this.handler.lastRequest.getBuild());
|
||||
assertEquals("web", this.handler.lastRequest.getFormat());
|
||||
assertTrue(this.handler.lastRequest.isDetectType());
|
||||
assertNull(this.handler.lastRequest.getType());
|
||||
assertThat(this.handler.lastRequest.getBuild()).isEqualTo("maven");
|
||||
assertThat(this.handler.lastRequest.getFormat()).isEqualTo("web");
|
||||
assertThat(this.handler.lastRequest.isDetectType()).isTrue();
|
||||
assertThat(this.handler.lastRequest.getType()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLocation() throws Exception {
|
||||
this.handler.disableProjectGeneration();
|
||||
this.command.run("foobar.zip");
|
||||
assertEquals("foobar.zip", this.handler.lastRequest.getOutput());
|
||||
assertThat(this.handler.lastRequest.getOutput()).isEqualTo("foobar.zip");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLocationWithSlash() throws Exception {
|
||||
this.handler.disableProjectGeneration();
|
||||
this.command.run("foobar/");
|
||||
assertEquals("foobar", this.handler.lastRequest.getOutput());
|
||||
assertTrue(this.handler.lastRequest.isExtract());
|
||||
assertThat(this.handler.lastRequest.getOutput()).isEqualTo("foobar");
|
||||
assertThat(this.handler.lastRequest.isExtract()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMoreThanOneArg() throws Exception {
|
||||
this.handler.disableProjectGeneration();
|
||||
assertEquals(ExitStatus.ERROR, this.command.run("foobar", "barfoo"));
|
||||
assertThat(this.command.run("foobar", "barfoo")).isEqualTo(ExitStatus.ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -361,7 +360,7 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
|
||||
this.command.run("--list", "--target=http://fake-service");
|
||||
verify(this.http).execute(this.requestCaptor.capture());
|
||||
Header agent = this.requestCaptor.getValue().getHeaders("User-Agent")[0];
|
||||
assertThat(agent.getValue(), startsWith("SpringBootCli/"));
|
||||
assertThat(agent.getValue()).startsWith("SpringBootCli/");
|
||||
}
|
||||
|
||||
private byte[] createFakeZipArchive(String fileName, String content)
|
||||
|
@ -27,8 +27,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link InitializrServiceMetadata}
|
||||
@ -40,43 +39,43 @@ public class InitializrServiceMetadataTests {
|
||||
@Test
|
||||
public void parseDefaults() {
|
||||
InitializrServiceMetadata metadata = createInstance("2.0.0");
|
||||
assertEquals("1.1.8.RELEASE", metadata.getDefaults().get("bootVersion"));
|
||||
assertEquals("1.7", metadata.getDefaults().get("javaVersion"));
|
||||
assertEquals("org.test", metadata.getDefaults().get("groupId"));
|
||||
assertEquals("demo", metadata.getDefaults().get("name"));
|
||||
assertEquals("Demo project for Spring Boot",
|
||||
metadata.getDefaults().get("description"));
|
||||
assertEquals("jar", metadata.getDefaults().get("packaging"));
|
||||
assertEquals("java", metadata.getDefaults().get("language"));
|
||||
assertEquals("demo", metadata.getDefaults().get("artifactId"));
|
||||
assertEquals("demo", metadata.getDefaults().get("packageName"));
|
||||
assertEquals("maven-project", metadata.getDefaults().get("type"));
|
||||
assertEquals("0.0.1-SNAPSHOT", metadata.getDefaults().get("version"));
|
||||
assertEquals("Wrong number of defaults", 11, metadata.getDefaults().size());
|
||||
assertThat(metadata.getDefaults().get("bootVersion")).isEqualTo("1.1.8.RELEASE");
|
||||
assertThat(metadata.getDefaults().get("javaVersion")).isEqualTo("1.7");
|
||||
assertThat(metadata.getDefaults().get("groupId")).isEqualTo("org.test");
|
||||
assertThat(metadata.getDefaults().get("name")).isEqualTo("demo");
|
||||
assertThat(metadata.getDefaults().get("description"))
|
||||
.isEqualTo("Demo project for Spring Boot");
|
||||
assertThat(metadata.getDefaults().get("packaging")).isEqualTo("jar");
|
||||
assertThat(metadata.getDefaults().get("language")).isEqualTo("java");
|
||||
assertThat(metadata.getDefaults().get("artifactId")).isEqualTo("demo");
|
||||
assertThat(metadata.getDefaults().get("packageName")).isEqualTo("demo");
|
||||
assertThat(metadata.getDefaults().get("type")).isEqualTo("maven-project");
|
||||
assertThat(metadata.getDefaults().get("version")).isEqualTo("0.0.1-SNAPSHOT");
|
||||
assertThat(metadata.getDefaults()).as("Wrong number of defaults").hasSize(11);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseDependencies() {
|
||||
InitializrServiceMetadata metadata = createInstance("2.0.0");
|
||||
assertEquals(5, metadata.getDependencies().size());
|
||||
assertThat(metadata.getDependencies()).hasSize(5);
|
||||
|
||||
// Security description
|
||||
assertEquals("AOP", metadata.getDependency("aop").getName());
|
||||
assertEquals("Security", metadata.getDependency("security").getName());
|
||||
assertEquals("Security description",
|
||||
metadata.getDependency("security").getDescription());
|
||||
assertEquals("JDBC", metadata.getDependency("jdbc").getName());
|
||||
assertEquals("JPA", metadata.getDependency("data-jpa").getName());
|
||||
assertEquals("MongoDB", metadata.getDependency("data-mongodb").getName());
|
||||
assertThat(metadata.getDependency("aop").getName()).isEqualTo("AOP");
|
||||
assertThat(metadata.getDependency("security").getName()).isEqualTo("Security");
|
||||
assertThat(metadata.getDependency("security").getDescription())
|
||||
.isEqualTo("Security description");
|
||||
assertThat(metadata.getDependency("jdbc").getName()).isEqualTo("JDBC");
|
||||
assertThat(metadata.getDependency("data-jpa").getName()).isEqualTo("JPA");
|
||||
assertThat(metadata.getDependency("data-mongodb").getName()).isEqualTo("MongoDB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTypes() {
|
||||
InitializrServiceMetadata metadata = createInstance("2.0.0");
|
||||
ProjectType projectType = metadata.getProjectTypes().get("maven-project");
|
||||
assertNotNull(projectType);
|
||||
assertEquals("maven", projectType.getTags().get("build"));
|
||||
assertEquals("project", projectType.getTags().get("format"));
|
||||
assertThat(projectType).isNotNull();
|
||||
assertThat(projectType.getTags().get("build")).isEqualTo("maven");
|
||||
assertThat(projectType.getTags().get("format")).isEqualTo("project");
|
||||
}
|
||||
|
||||
private static InitializrServiceMetadata createInstance(String version) {
|
||||
|
@ -24,10 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -48,7 +45,7 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||
public void loadMetadata() throws IOException {
|
||||
mockSuccessfulMetadataGet(false);
|
||||
InitializrServiceMetadata metadata = this.invoker.loadMetadata("http://foo/bar");
|
||||
assertNotNull(metadata);
|
||||
assertThat(metadata).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -149,20 +146,20 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||
MockHttpProjectGenerationRequest mockRequest) throws IOException {
|
||||
mockSuccessfulProjectGeneration(mockRequest);
|
||||
ProjectGenerationResponse entity = this.invoker.generate(request);
|
||||
assertArrayEquals("wrong body content", mockRequest.content, entity.getContent());
|
||||
assertThat(entity.getContent()).as("wrong body content")
|
||||
.isEqualTo(mockRequest.content);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private static void assertProjectEntity(ProjectGenerationResponse entity,
|
||||
String mimeType, String fileName) {
|
||||
if (mimeType == null) {
|
||||
assertNull("No content type expected", entity.getContentType());
|
||||
assertThat(entity.getContentType()).isNull();
|
||||
}
|
||||
else {
|
||||
assertEquals("wrong mime type", mimeType,
|
||||
entity.getContentType().getMimeType());
|
||||
assertThat(entity.getContentType().getMimeType()).isEqualTo(mimeType);
|
||||
}
|
||||
assertEquals("wrong filename", fileName, entity.getFileName());
|
||||
assertThat(entity.getFileName()).isEqualTo(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ProjectGenerationRequest}
|
||||
@ -52,8 +52,8 @@ public class ProjectGenerationRequestTests {
|
||||
|
||||
@Test
|
||||
public void defaultSettings() {
|
||||
assertEquals(createDefaultUrl("?type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -61,46 +61,44 @@ public class ProjectGenerationRequestTests {
|
||||
String customServerUrl = "http://foo:8080/initializr";
|
||||
this.request.setServiceUrl(customServerUrl);
|
||||
this.request.getDependencies().add("security");
|
||||
assertEquals(
|
||||
new URI(customServerUrl
|
||||
+ "/starter.zip?dependencies=security&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata())).isEqualTo(new URI(
|
||||
customServerUrl + "/starter.zip?dependencies=security&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customBootVersion() {
|
||||
this.request.setBootVersion("1.2.0.RELEASE");
|
||||
assertEquals(createDefaultUrl("?type=test-type&bootVersion=1.2.0.RELEASE"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?type=test-type&bootVersion=1.2.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleDependency() {
|
||||
this.request.getDependencies().add("web");
|
||||
assertEquals(createDefaultUrl("?dependencies=web&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?dependencies=web&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleDependencies() {
|
||||
this.request.getDependencies().add("web");
|
||||
this.request.getDependencies().add("data-jpa");
|
||||
assertEquals(createDefaultUrl("?dependencies=web%2Cdata-jpa&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata())).isEqualTo(
|
||||
createDefaultUrl("?dependencies=web%2Cdata-jpa&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customJavaVersion() {
|
||||
this.request.setJavaVersion("1.8");
|
||||
assertEquals(createDefaultUrl("?type=test-type&javaVersion=1.8"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?type=test-type&javaVersion=1.8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customPackageName() {
|
||||
this.request.setPackageName("demo.foo");
|
||||
assertEquals(createDefaultUrl("?packageName=demo.foo&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?packageName=demo.foo&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -110,24 +108,23 @@ public class ProjectGenerationRequestTests {
|
||||
InitializrServiceMetadata metadata = new InitializrServiceMetadata(projectType);
|
||||
this.request.setType("custom");
|
||||
this.request.getDependencies().add("data-rest");
|
||||
assertEquals(
|
||||
new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL
|
||||
+ "/foo?dependencies=data-rest&type=custom"),
|
||||
this.request.generateUrl(metadata));
|
||||
assertThat(this.request.generateUrl(metadata))
|
||||
.isEqualTo(new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL
|
||||
+ "/foo?dependencies=data-rest&type=custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customPackaging() {
|
||||
this.request.setPackaging("war");
|
||||
assertEquals(createDefaultUrl("?type=test-type&packaging=war"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?type=test-type&packaging=war"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customLanguage() {
|
||||
this.request.setLanguage("groovy");
|
||||
assertEquals(createDefaultUrl("?type=test-type&language=groovy"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?type=test-type&language=groovy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -136,40 +133,39 @@ public class ProjectGenerationRequestTests {
|
||||
this.request.setArtifactId("sample");
|
||||
this.request.setVersion("1.0.1-SNAPSHOT");
|
||||
this.request.setDescription("Spring Boot Test");
|
||||
assertEquals(
|
||||
createDefaultUrl(
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl(
|
||||
"?groupId=org.acme&artifactId=sample&version=1.0.1-SNAPSHOT"
|
||||
+ "&description=Spring+Boot+Test&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
+ "&description=Spring+Boot+Test&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputCustomizeArtifactId() {
|
||||
this.request.setOutput("my-project");
|
||||
assertEquals(createDefaultUrl("?artifactId=my-project&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputArchiveCustomizeArtifactId() {
|
||||
this.request.setOutput("my-project.zip");
|
||||
assertEquals(createDefaultUrl("?artifactId=my-project&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?artifactId=my-project&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputArchiveWithDotsCustomizeArtifactId() {
|
||||
this.request.setOutput("my.nice.project.zip");
|
||||
assertEquals(createDefaultUrl("?artifactId=my.nice.project&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata())).isEqualTo(
|
||||
createDefaultUrl("?artifactId=my.nice.project&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputDoesNotOverrideCustomArtifactId() {
|
||||
this.request.setOutput("my-project");
|
||||
this.request.setArtifactId("my-id");
|
||||
assertEquals(createDefaultUrl("?artifactId=my-id&type=test-type"),
|
||||
this.request.generateUrl(createDefaultMetadata()));
|
||||
assertThat(this.request.generateUrl(createDefaultMetadata()))
|
||||
.isEqualTo(createDefaultUrl("?artifactId=my-id&type=test-type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -195,8 +191,8 @@ public class ProjectGenerationRequestTests {
|
||||
public void buildOneMatch() {
|
||||
InitializrServiceMetadata metadata = readMetadata();
|
||||
setBuildAndFormat("gradle", null);
|
||||
assertEquals(createDefaultUrl("?type=gradle-project"),
|
||||
this.request.generateUrl(metadata));
|
||||
assertThat(this.request.generateUrl(metadata))
|
||||
.isEqualTo(createDefaultUrl("?type=gradle-project"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -204,8 +200,8 @@ public class ProjectGenerationRequestTests {
|
||||
InitializrServiceMetadata metadata = readMetadata();
|
||||
setBuildAndFormat("gradle", "project");
|
||||
this.request.setType("maven-build");
|
||||
assertEquals(createUrl("/pom.xml?type=maven-build"),
|
||||
this.request.generateUrl(metadata));
|
||||
assertThat(this.request.generateUrl(metadata))
|
||||
.isEqualTo(createUrl("/pom.xml?type=maven-build"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -20,9 +20,7 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ServiceCapabilitiesReportGenerator}
|
||||
@ -40,7 +38,7 @@ public class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientM
|
||||
String expected = new String(
|
||||
readClasspathResource("metadata/service-metadata-2.1.0.txt"));
|
||||
String content = this.command.generate("http://localhost");
|
||||
assertThat(content, equalTo(expected));
|
||||
assertThat(content).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -57,10 +55,10 @@ public class ServiceCapabilitiesReportGeneratorTests extends AbstractHttpClientM
|
||||
|
||||
private void doTestGenerateCapabilitiesFromJson() throws IOException {
|
||||
String content = this.command.generate("http://localhost");
|
||||
assertThat(content, containsString("aop - AOP"));
|
||||
assertThat(content, containsString("security - Security: Security description"));
|
||||
assertThat(content, containsString("type: maven-project"));
|
||||
assertThat(content, containsString("packaging: jar"));
|
||||
assertThat(content).contains("aop - AOP");
|
||||
assertThat(content).contains("security - Security: Security description");
|
||||
assertThat(content).contains("type: maven-project");
|
||||
assertThat(content).contains("packaging: jar");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -30,11 +31,11 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration;
|
||||
import org.springframework.boot.cli.compiler.GroovyCompilerScope;
|
||||
import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory;
|
||||
import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
|
||||
import org.springframework.boot.test.assertj.Matched;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link GroovyGrabDependencyResolver}.
|
||||
@ -88,35 +89,35 @@ public class GroovyGrabDependencyResolverTests {
|
||||
public 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), hasItems("commons-logging-1.1.3.jar"));
|
||||
assertThat(resolved).hasSize(1);
|
||||
assertThat(getNames(resolved)).containsOnly("commons-logging-1.1.3.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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),
|
||||
hasItems("commons-logging-1.1.3.jar", "spring-core-4.1.1.RELEASE.jar"));
|
||||
assertThat(resolved).hasSize(2);
|
||||
assertThat(getNames(resolved)).containsOnly("commons-logging-1.1.3.jar",
|
||||
"spring-core-4.1.1.RELEASE.jar");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void resolveShorthandArtifactWithDependencies() throws Exception {
|
||||
List<File> resolved = this.resolver.resolve(Arrays.asList("spring-core"));
|
||||
assertThat(resolved, hasSize(2));
|
||||
assertThat(getNames(resolved),
|
||||
hasItems(startsWith("commons-logging-"), startsWith("spring-core-")));
|
||||
assertThat(resolved).hasSize(2);
|
||||
assertThat(getNames(resolved)).has((Condition) Matched.by(
|
||||
hasItems(startsWith("commons-logging-"), startsWith("spring-core-"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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(3));
|
||||
assertThat(getNames(resolved), hasItems("junit-4.11.jar",
|
||||
"commons-logging-1.1.3.jar", "hamcrest-core-1.3.jar"));
|
||||
assertThat(resolved).hasSize(3);
|
||||
assertThat(getNames(resolved)).containsOnly("junit-4.11.jar",
|
||||
"commons-logging-1.1.3.jar", "hamcrest-core-1.3.jar");
|
||||
}
|
||||
|
||||
public Set<String> getNames(Collection<File> files) {
|
||||
|
@ -30,9 +30,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@ -68,7 +66,7 @@ public class InstallerTests {
|
||||
File foo = createTemporaryFile("foo.jar");
|
||||
given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo));
|
||||
this.installer.install(Arrays.asList("foo"));
|
||||
assertThat(getNamesOfFilesInLib(), containsInAnyOrder("foo.jar", ".installed"));
|
||||
assertThat(getNamesOfFilesInLib()).containsOnly("foo.jar", ".installed");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -77,7 +75,7 @@ public class InstallerTests {
|
||||
given(this.resolver.resolve(Arrays.asList("foo"))).willReturn(Arrays.asList(foo));
|
||||
this.installer.install(Arrays.asList("foo"));
|
||||
this.installer.uninstall(Arrays.asList("foo"));
|
||||
assertThat(getNamesOfFilesInLib(), contains(".installed"));
|
||||
assertThat(getNamesOfFilesInLib()).contains(".installed");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -89,21 +87,17 @@ public class InstallerTests {
|
||||
.willReturn(Arrays.asList(bravo, alpha));
|
||||
given(this.resolver.resolve(Arrays.asList("charlie")))
|
||||
.willReturn(Arrays.asList(charlie, alpha));
|
||||
|
||||
this.installer.install(Arrays.asList("bravo"));
|
||||
assertThat(getNamesOfFilesInLib(),
|
||||
containsInAnyOrder("alpha.jar", "bravo.jar", ".installed"));
|
||||
|
||||
assertThat(getNamesOfFilesInLib()).containsOnly("alpha.jar", "bravo.jar",
|
||||
".installed");
|
||||
this.installer.install(Arrays.asList("charlie"));
|
||||
assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "bravo.jar",
|
||||
"charlie.jar", ".installed"));
|
||||
|
||||
assertThat(getNamesOfFilesInLib()).containsOnly("alpha.jar", "bravo.jar",
|
||||
"charlie.jar", ".installed");
|
||||
this.installer.uninstall(Arrays.asList("bravo"));
|
||||
assertThat(getNamesOfFilesInLib(),
|
||||
containsInAnyOrder("alpha.jar", "charlie.jar", ".installed"));
|
||||
|
||||
assertThat(getNamesOfFilesInLib()).containsOnly("alpha.jar", "charlie.jar",
|
||||
".installed");
|
||||
this.installer.uninstall(Arrays.asList("charlie"));
|
||||
assertThat(getNamesOfFilesInLib(), containsInAnyOrder(".installed"));
|
||||
assertThat(getNamesOfFilesInLib()).containsOnly(".installed");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -111,19 +105,16 @@ public class InstallerTests {
|
||||
File alpha = createTemporaryFile("alpha.jar");
|
||||
File bravo = createTemporaryFile("bravo.jar");
|
||||
File charlie = createTemporaryFile("charlie.jar");
|
||||
|
||||
given(this.resolver.resolve(Arrays.asList("bravo")))
|
||||
.willReturn(Arrays.asList(bravo, alpha));
|
||||
given(this.resolver.resolve(Arrays.asList("charlie")))
|
||||
.willReturn(Arrays.asList(charlie, alpha));
|
||||
|
||||
this.installer.install(Arrays.asList("bravo"));
|
||||
this.installer.install(Arrays.asList("charlie"));
|
||||
assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "bravo.jar",
|
||||
"charlie.jar", ".installed"));
|
||||
|
||||
assertThat(getNamesOfFilesInLib()).containsOnly("alpha.jar", "bravo.jar",
|
||||
"charlie.jar", ".installed");
|
||||
this.installer.uninstallAll();
|
||||
assertThat(getNamesOfFilesInLib(), containsInAnyOrder(".installed"));
|
||||
assertThat(getNamesOfFilesInLib()).containsOnly(".installed");
|
||||
}
|
||||
|
||||
private Set<String> getNamesOfFilesInLib() {
|
||||
|
@ -19,8 +19,7 @@ package org.springframework.boot.cli.command.shell;
|
||||
import jline.console.completer.ArgumentCompleter.ArgumentList;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link EscapeAwareWhiteSpaceArgumentDelimiter}.
|
||||
@ -34,68 +33,63 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
|
||||
@Test
|
||||
public void simple() throws Exception {
|
||||
String s = "one two";
|
||||
assertThat(this.delimiter.delimit(s, 0).getArguments(),
|
||||
equalTo(new String[] { "one", "two" }));
|
||||
assertThat(this.delimiter.parseArguments(s),
|
||||
equalTo(new String[] { "one", "two" }));
|
||||
assertThat(this.delimiter.isDelimiter(s, 2), equalTo(false));
|
||||
assertThat(this.delimiter.isDelimiter(s, 3), equalTo(true));
|
||||
assertThat(this.delimiter.isDelimiter(s, 4), equalTo(false));
|
||||
assertThat(this.delimiter.delimit(s, 0).getArguments()).containsExactly("one",
|
||||
"two");
|
||||
assertThat(this.delimiter.parseArguments(s)).containsExactly("one", "two");
|
||||
assertThat(this.delimiter.isDelimiter(s, 2)).isFalse();
|
||||
assertThat(this.delimiter.isDelimiter(s, 3)).isTrue();
|
||||
assertThat(this.delimiter.isDelimiter(s, 4)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escaped() throws Exception {
|
||||
String s = "o\\ ne two";
|
||||
assertThat(this.delimiter.delimit(s, 0).getArguments(),
|
||||
equalTo(new String[] { "o\\ ne", "two" }));
|
||||
assertThat(this.delimiter.parseArguments(s),
|
||||
equalTo(new String[] { "o ne", "two" }));
|
||||
assertThat(this.delimiter.isDelimiter(s, 2), equalTo(false));
|
||||
assertThat(this.delimiter.isDelimiter(s, 3), equalTo(false));
|
||||
assertThat(this.delimiter.isDelimiter(s, 4), equalTo(false));
|
||||
assertThat(this.delimiter.isDelimiter(s, 5), equalTo(true));
|
||||
assertThat(this.delimiter.delimit(s, 0).getArguments()).containsExactly("o\\ ne",
|
||||
"two");
|
||||
assertThat(this.delimiter.parseArguments(s)).containsExactly("o ne", "two");
|
||||
assertThat(this.delimiter.isDelimiter(s, 2)).isFalse();
|
||||
assertThat(this.delimiter.isDelimiter(s, 3)).isFalse();
|
||||
assertThat(this.delimiter.isDelimiter(s, 4)).isFalse();
|
||||
assertThat(this.delimiter.isDelimiter(s, 5)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quoted() throws Exception {
|
||||
String s = "'o ne' 't w o'";
|
||||
assertThat(this.delimiter.delimit(s, 0).getArguments(),
|
||||
equalTo(new String[] { "'o ne'", "'t w o'" }));
|
||||
assertThat(this.delimiter.parseArguments(s),
|
||||
equalTo(new String[] { "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() throws Exception {
|
||||
String s = "\"o ne\" \"t w o\"";
|
||||
assertThat(this.delimiter.delimit(s, 0).getArguments(),
|
||||
equalTo(new String[] { "\"o ne\"", "\"t w o\"" }));
|
||||
assertThat(this.delimiter.parseArguments(s),
|
||||
equalTo(new String[] { "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() throws Exception {
|
||||
String s = "\"o 'n''e\" 't \"w o'";
|
||||
assertThat(this.delimiter.delimit(s, 0).getArguments(),
|
||||
equalTo(new String[] { "\"o 'n''e\"", "'t \"w o'" }));
|
||||
assertThat(this.delimiter.parseArguments(s),
|
||||
equalTo(new String[] { "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() throws Exception {
|
||||
String s = "\\'a b";
|
||||
ArgumentList argumentList = this.delimiter.delimit(s, 0);
|
||||
assertThat(argumentList.getArguments(), equalTo(new String[] { "\\'a", "b" }));
|
||||
assertThat(this.delimiter.parseArguments(s), equalTo(new String[] { "'a", "b" }));
|
||||
assertThat(argumentList.getArguments()).isEqualTo(new String[] { "\\'a", "b" });
|
||||
assertThat(this.delimiter.parseArguments(s)).containsExactly("'a", "b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapes() throws Exception {
|
||||
String s = "\\ \\\\.\\\\\\t";
|
||||
assertThat(this.delimiter.parseArguments(s),
|
||||
equalTo(new String[] { " \\.\\\t" }));
|
||||
|
||||
assertThat(this.delimiter.parseArguments(s)).containsExactly(" \\.\\\t");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,8 +33,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver;
|
||||
import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
@ -78,7 +77,7 @@ public class DependencyCustomizerTests {
|
||||
this.dependencyCustomizer.add("spring-boot-starter-logging");
|
||||
List<AnnotationNode> grabAnnotations = this.classNode
|
||||
.getAnnotations(new ClassNode(Grab.class));
|
||||
assertEquals(1, grabAnnotations.size());
|
||||
assertThat(grabAnnotations).hasSize(1);
|
||||
AnnotationNode annotationNode = grabAnnotations.get(0);
|
||||
assertGrabAnnotation(annotationNode, "org.springframework.boot",
|
||||
"spring-boot-starter-logging", "1.2.3", null, null, true);
|
||||
@ -89,7 +88,7 @@ public class DependencyCustomizerTests {
|
||||
this.dependencyCustomizer.add("spring-boot-starter-logging", false);
|
||||
List<AnnotationNode> grabAnnotations = this.classNode
|
||||
.getAnnotations(new ClassNode(Grab.class));
|
||||
assertEquals(1, grabAnnotations.size());
|
||||
assertThat(grabAnnotations).hasSize(1);
|
||||
AnnotationNode annotationNode = grabAnnotations.get(0);
|
||||
assertGrabAnnotation(annotationNode, "org.springframework.boot",
|
||||
"spring-boot-starter-logging", "1.2.3", null, null, false);
|
||||
@ -101,7 +100,7 @@ public class DependencyCustomizerTests {
|
||||
"my-type", false);
|
||||
List<AnnotationNode> grabAnnotations = this.classNode
|
||||
.getAnnotations(new ClassNode(Grab.class));
|
||||
assertEquals(1, grabAnnotations.size());
|
||||
assertThat(grabAnnotations).hasSize(1);
|
||||
AnnotationNode annotationNode = grabAnnotations.get(0);
|
||||
assertGrabAnnotation(annotationNode, "org.springframework.boot",
|
||||
"spring-boot-starter-logging", "1.2.3", "my-classifier", "my-type",
|
||||
@ -112,7 +111,7 @@ public class DependencyCustomizerTests {
|
||||
public void anyMissingClassesWithMissingClassesPerformsAdd() {
|
||||
this.dependencyCustomizer.ifAnyMissingClasses("does.not.Exist")
|
||||
.add("spring-boot-starter-logging");
|
||||
assertEquals(1, this.classNode.getAnnotations(new ClassNode(Grab.class)).size());
|
||||
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -120,21 +119,21 @@ public class DependencyCustomizerTests {
|
||||
this.dependencyCustomizer
|
||||
.ifAnyMissingClasses(getClass().getName(), "does.not.Exist")
|
||||
.add("spring-boot-starter-logging");
|
||||
assertEquals(1, this.classNode.getAnnotations(new ClassNode(Grab.class)).size());
|
||||
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anyMissingClassesWithNoMissingClassesDoesNotPerformAdd() {
|
||||
this.dependencyCustomizer.ifAnyMissingClasses(getClass().getName())
|
||||
.add("spring-boot-starter-logging");
|
||||
assertEquals(0, this.classNode.getAnnotations(new ClassNode(Grab.class)).size());
|
||||
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allMissingClassesWithNoMissingClassesDoesNotPerformAdd() {
|
||||
this.dependencyCustomizer.ifAllMissingClasses(getClass().getName())
|
||||
.add("spring-boot-starter-logging");
|
||||
assertEquals(0, this.classNode.getAnnotations(new ClassNode(Grab.class)).size());
|
||||
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -142,7 +141,7 @@ public class DependencyCustomizerTests {
|
||||
this.dependencyCustomizer
|
||||
.ifAllMissingClasses(getClass().getName(), "does.not.Exist")
|
||||
.add("spring-boot-starter-logging");
|
||||
assertEquals(0, this.classNode.getAnnotations(new ClassNode(Grab.class)).size());
|
||||
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -150,27 +149,28 @@ public class DependencyCustomizerTests {
|
||||
this.dependencyCustomizer
|
||||
.ifAllMissingClasses("does.not.Exist", "does.not.exist.Either")
|
||||
.add("spring-boot-starter-logging");
|
||||
assertEquals(1, this.classNode.getAnnotations(new ClassNode(Grab.class)).size());
|
||||
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
|
||||
}
|
||||
|
||||
private void assertGrabAnnotation(AnnotationNode annotationNode, String group,
|
||||
String module, String version, String classifier, String type,
|
||||
boolean transitive) {
|
||||
assertEquals(group, getMemberValue(annotationNode, "group"));
|
||||
assertEquals(module, getMemberValue(annotationNode, "module"));
|
||||
assertThat(getMemberValue(annotationNode, "group")).isEqualTo(group);
|
||||
assertThat(getMemberValue(annotationNode, "module")).isEqualTo(module);
|
||||
if (type == null) {
|
||||
assertNull(annotationNode.getMember("type"));
|
||||
assertThat(annotationNode.getMember("type")).isNull();
|
||||
}
|
||||
else {
|
||||
assertEquals(type, getMemberValue(annotationNode, "type"));
|
||||
assertThat(getMemberValue(annotationNode, "type")).isEqualTo(type);
|
||||
}
|
||||
if (classifier == null) {
|
||||
assertNull(annotationNode.getMember("classifier"));
|
||||
assertThat(annotationNode.getMember("classifier")).isNull();
|
||||
}
|
||||
else {
|
||||
assertEquals(classifier, getMemberValue(annotationNode, "classifier"));
|
||||
assertThat(getMemberValue(annotationNode, "classifier"))
|
||||
.isEqualTo(classifier);
|
||||
}
|
||||
assertEquals(transitive, getMemberValue(annotationNode, "transitive"));
|
||||
assertThat(getMemberValue(annotationNode, "transitive")).isEqualTo(transitive);
|
||||
}
|
||||
|
||||
private Object getMemberValue(AnnotationNode annotationNode, String member) {
|
||||
|
@ -21,8 +21,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ExtendedGroovyClassLoader}.
|
||||
@ -49,7 +48,7 @@ public class ExtendedGroovyClassLoaderTests {
|
||||
public void loadsGroovyFromSameClassLoader() throws Exception {
|
||||
Class<?> c1 = this.contextClassLoader.loadClass("groovy.lang.Script");
|
||||
Class<?> c2 = this.defaultScopeGroovyClassLoader.loadClass("groovy.lang.Script");
|
||||
assertThat(c1.getClassLoader(), sameInstance(c2.getClassLoader()));
|
||||
assertThat(c1.getClassLoader()).isSameAs(c2.getClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -35,7 +35,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.groovy.DependencyManagementBom;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ResolveDependencyCoordinatesTransformation}
|
||||
@ -68,14 +68,14 @@ public final class GenericBomAstTransformationTests {
|
||||
public void transformationOfEmptyPackage() {
|
||||
this.moduleNode.setPackage(new PackageNode("foo"));
|
||||
this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
|
||||
assertEquals("[test:child:1.0.0]", getValue().toString());
|
||||
assertThat(getValue().toString()).isEqualTo("[test:child:1.0.0]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transformationOfClass() {
|
||||
this.moduleNode.addClass(ClassHelper.make("MyClass"));
|
||||
this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
|
||||
assertEquals("[test:child:1.0.0]", getValue().toString());
|
||||
assertThat(getValue().toString()).isEqualTo("[test:child:1.0.0]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -88,7 +88,8 @@ public final class GenericBomAstTransformationTests {
|
||||
annotation.addMember("value", new ConstantExpression("test:parent:1.0.0"));
|
||||
cls.addAnnotation(annotation);
|
||||
this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
|
||||
assertEquals("[test:parent:1.0.0, test:child:1.0.0]", getValue().toString());
|
||||
assertThat(getValue().toString())
|
||||
.isEqualTo("[test:parent:1.0.0, test:child:1.0.0]");
|
||||
}
|
||||
|
||||
private List<String> getValue() {
|
||||
|
@ -25,9 +25,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
|
||||
import org.springframework.boot.cli.util.SystemProperties;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RepositoryConfigurationFactory}
|
||||
@ -107,11 +105,12 @@ public class RepositoryConfigurationFactoryTests {
|
||||
|
||||
private void assertRepositoryConfiguration(
|
||||
List<RepositoryConfiguration> configurations, String... expectedNames) {
|
||||
assertThat(configurations, hasSize(expectedNames.length));
|
||||
assertThat(configurations).hasSize(expectedNames.length);
|
||||
Set<String> actualNames = new HashSet<String>();
|
||||
for (RepositoryConfiguration configuration : configurations) {
|
||||
actualNames.add(configuration.getName());
|
||||
}
|
||||
assertThat(actualNames, hasItems(expectedNames));
|
||||
assertThat(actualNames).containsOnly(expectedNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver;
|
||||
import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@ -220,9 +220,9 @@ public final class ResolveDependencyCoordinatesTransformationTests {
|
||||
|
||||
private void assertGrabAnnotationHasBeenTransformed() {
|
||||
this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
|
||||
|
||||
assertEquals("org.springframework", getGrabAnnotationMemberAsString("group"));
|
||||
assertEquals("spring-core", getGrabAnnotationMemberAsString("module"));
|
||||
assertThat(getGrabAnnotationMemberAsString("group"))
|
||||
.isEqualTo("org.springframework");
|
||||
assertThat(getGrabAnnotationMemberAsString("module")).isEqualTo("spring-core");
|
||||
}
|
||||
|
||||
private Object getGrabAnnotationMemberAsString(String memberName) {
|
||||
|
@ -23,10 +23,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
@ -47,10 +44,8 @@ public class CompositeDependencyManagementTests {
|
||||
public void unknownSpringBootVersion() {
|
||||
given(this.dependencyManagement1.getSpringBootVersion()).willReturn(null);
|
||||
given(this.dependencyManagement2.getSpringBootVersion()).willReturn(null);
|
||||
assertThat(
|
||||
new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getSpringBootVersion(),
|
||||
is(nullValue()));
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getSpringBootVersion()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -58,7 +53,7 @@ public class CompositeDependencyManagementTests {
|
||||
given(this.dependencyManagement1.getSpringBootVersion()).willReturn("1.2.3");
|
||||
given(this.dependencyManagement2.getSpringBootVersion()).willReturn("1.2.4");
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getSpringBootVersion(), is("1.2.3"));
|
||||
this.dependencyManagement2).getSpringBootVersion()).isEqualTo("1.2.3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -66,7 +61,7 @@ public class CompositeDependencyManagementTests {
|
||||
given(this.dependencyManagement1.find("artifact")).willReturn(null);
|
||||
given(this.dependencyManagement2.find("artifact")).willReturn(null);
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).find("artifact"), is(nullValue()));
|
||||
this.dependencyManagement2).find("artifact")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -75,10 +70,9 @@ public class CompositeDependencyManagementTests {
|
||||
.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).find("artifact"),
|
||||
is(new Dependency("test", "artifact", "1.2.3")));
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).find("artifact"))
|
||||
.isEqualTo(new Dependency("test", "artifact", "1.2.3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -87,11 +81,10 @@ public class CompositeDependencyManagementTests {
|
||||
.willReturn(Arrays.asList(new Dependency("test", "artifact", "1.2.3")));
|
||||
given(this.dependencyManagement2.getDependencies())
|
||||
.willReturn(Arrays.asList(new Dependency("test", "artifact", "1.2.4")));
|
||||
assertThat(
|
||||
new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getDependencies(),
|
||||
contains(new Dependency("test", "artifact", "1.2.3"),
|
||||
new Dependency("test", "artifact", "1.2.4")));
|
||||
assertThat(new CompositeDependencyManagement(this.dependencyManagement1,
|
||||
this.dependencyManagement2).getDependencies()).containsOnly(
|
||||
new Dependency("test", "artifact", "1.2.3"),
|
||||
new Dependency("test", "artifact", "1.2.4"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,9 +19,7 @@ package org.springframework.boot.cli.compiler.dependencies;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -52,19 +50,19 @@ public class DependencyManagementArtifactCoordinatesResolverTests {
|
||||
|
||||
@Test
|
||||
public void getGroupIdForBootArtifact() throws Exception {
|
||||
assertThat(this.resolver.getGroupId("spring-boot-something"),
|
||||
equalTo("org.springframework.boot"));
|
||||
assertThat(this.resolver.getGroupId("spring-boot-something"))
|
||||
.isEqualTo("org.springframework.boot");
|
||||
verify(this.dependencyManagement, never()).find(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGroupIdFound() throws Exception {
|
||||
assertThat(this.resolver.getGroupId("a1"), equalTo("g1"));
|
||||
assertThat(this.resolver.getGroupId("a1")).isEqualTo("g1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGroupIdNotFound() throws Exception {
|
||||
assertThat(this.resolver.getGroupId("a2"), nullValue());
|
||||
assertThat(this.resolver.getGroupId("a2")).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,12 +18,8 @@ package org.springframework.boot.cli.compiler.dependencies;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringBootDependenciesDependencyManagement}
|
||||
@ -36,20 +32,20 @@ public class SpringBootDependenciesDependencyManagementTests {
|
||||
|
||||
@Test
|
||||
public void springBootVersion() {
|
||||
assertThat(this.dependencyManagement.getSpringBootVersion(), is(notNullValue()));
|
||||
assertThat(this.dependencyManagement.getSpringBootVersion()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void find() {
|
||||
Dependency dependency = this.dependencyManagement.find("spring-boot");
|
||||
assertThat(dependency, is(notNullValue()));
|
||||
assertThat(dependency.getGroupId(), is(equalTo("org.springframework.boot")));
|
||||
assertThat(dependency.getArtifactId(), is(equalTo("spring-boot")));
|
||||
assertThat(dependency).isNotNull();
|
||||
assertThat(dependency.getGroupId()).isEqualTo("org.springframework.boot");
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("spring-boot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDependencies() {
|
||||
assertThat(this.dependencyManagement.getDependencies(), is(not(empty())));
|
||||
assertThat(this.dependencyManagement.getDependencies()).isNotEqualTo(empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,9 +34,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link AetherGrapeEngine}.
|
||||
@ -63,11 +61,9 @@ public class AetherGrapeEngineTests {
|
||||
@Test
|
||||
public void dependencyResolution() {
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
|
||||
createGrapeEngine(this.springMilestones).grab(args,
|
||||
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
|
||||
|
||||
assertEquals(5, this.groovyClassLoader.getURLs().length);
|
||||
assertThat(this.groovyClassLoader.getURLs()).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -81,8 +77,10 @@ public class AetherGrapeEngineTests {
|
||||
DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) ReflectionTestUtils
|
||||
.getField(grapeEngine, "session");
|
||||
|
||||
assertTrue(session.getProxySelector() instanceof CompositeProxySelector);
|
||||
assertThat(session.getProxySelector() instanceof CompositeProxySelector)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -97,8 +95,8 @@ public class AetherGrapeEngineTests {
|
||||
|
||||
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils
|
||||
.getField(grapeEngine, "repositories");
|
||||
assertEquals(1, repositories.size());
|
||||
assertEquals("central-mirror", repositories.get(0).getId());
|
||||
assertThat(repositories).hasSize(1);
|
||||
assertThat(repositories.get(0).getId()).isEqualTo("central-mirror");
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -114,9 +112,9 @@ public class AetherGrapeEngineTests {
|
||||
|
||||
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils
|
||||
.getField(grapeEngine, "repositories");
|
||||
assertEquals(1, repositories.size());
|
||||
assertThat(repositories).hasSize(1);
|
||||
Authentication authentication = repositories.get(0).getAuthentication();
|
||||
assertNotNull(authentication);
|
||||
assertThat(authentication).isNotNull();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -131,7 +129,7 @@ public class AetherGrapeEngineTests {
|
||||
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"),
|
||||
createDependency("org.springframework", "spring-beans", "3.2.4.RELEASE"));
|
||||
|
||||
assertEquals(3, this.groovyClassLoader.getURLs().length);
|
||||
assertThat(this.groovyClassLoader.getURLs().length).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -141,7 +139,7 @@ public class AetherGrapeEngineTests {
|
||||
createGrapeEngine().grab(args, createDependency("org.springframework",
|
||||
"spring-jdbc", "3.2.4.RELEASE", false));
|
||||
|
||||
assertEquals(1, this.groovyClassLoader.getURLs().length);
|
||||
assertThat(this.groovyClassLoader.getURLs().length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -153,8 +151,8 @@ public class AetherGrapeEngineTests {
|
||||
createGrapeEngine(this.springMilestones).grab(args,
|
||||
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
|
||||
|
||||
assertEquals(0, this.groovyClassLoader.getURLs().length);
|
||||
assertEquals(5, customClassLoader.getURLs().length);
|
||||
assertThat(this.groovyClassLoader.getURLs().length).isEqualTo(0);
|
||||
assertThat(customClassLoader.getURLs().length).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -164,7 +162,7 @@ public class AetherGrapeEngineTests {
|
||||
grapeEngine
|
||||
.addResolver(createResolver("restlet.org", "http://maven.restlet.org"));
|
||||
grapeEngine.grab(args, createDependency("org.restlet", "org.restlet", "1.1.6"));
|
||||
assertEquals(1, this.groovyClassLoader.getURLs().length);
|
||||
assertThat(this.groovyClassLoader.getURLs().length).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@ -184,8 +182,8 @@ public class AetherGrapeEngineTests {
|
||||
dependency.put("type", "pom");
|
||||
createGrapeEngine().grab(args, dependency);
|
||||
URL[] urls = this.groovyClassLoader.getURLs();
|
||||
assertEquals(1, urls.length);
|
||||
assertTrue(urls[0].toExternalForm().endsWith(".pom"));
|
||||
assertThat(urls.length).isEqualTo(1);
|
||||
assertThat(urls[0].toExternalForm().endsWith(".pom")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -196,8 +194,8 @@ public class AetherGrapeEngineTests {
|
||||
dependency.put("ext", "pom");
|
||||
createGrapeEngine().grab(args, dependency);
|
||||
URL[] urls = this.groovyClassLoader.getURLs();
|
||||
assertEquals(1, urls.length);
|
||||
assertTrue(urls[0].toExternalForm().endsWith(".pom"));
|
||||
assertThat(urls.length).isEqualTo(1);
|
||||
assertThat(urls[0].toExternalForm().endsWith(".pom")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -210,8 +208,8 @@ public class AetherGrapeEngineTests {
|
||||
createGrapeEngine().grab(args, dependency);
|
||||
|
||||
URL[] urls = this.groovyClassLoader.getURLs();
|
||||
assertEquals(1, urls.length);
|
||||
assertTrue(urls[0].toExternalForm().endsWith("-sources.jar"));
|
||||
assertThat(urls.length).isEqualTo(1);
|
||||
assertThat(urls[0].toExternalForm().endsWith("-sources.jar")).isTrue();
|
||||
}
|
||||
|
||||
private Map<String, Object> createDependency(String group, String module,
|
||||
|
@ -26,11 +26,7 @@ import org.eclipse.aether.transfer.TransferResource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DetailedProgressReporter}.
|
||||
@ -62,9 +58,8 @@ public final class DetailedProgressReporterTests {
|
||||
TransferEvent startedEvent = new TransferEvent.Builder(this.session,
|
||||
this.resource).build();
|
||||
this.session.getTransferListener().transferStarted(startedEvent);
|
||||
|
||||
assertEquals(String.format("Downloading: %s%s%n", REPOSITORY, ARTIFACT),
|
||||
new String(this.baos.toByteArray()));
|
||||
assertThat(new String(this.baos.toByteArray()))
|
||||
.isEqualTo(String.format("Downloading: %s%s%n", REPOSITORY, ARTIFACT));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -75,9 +70,10 @@ public final class DetailedProgressReporterTests {
|
||||
this.resource).addTransferredBytes(4096).build();
|
||||
this.session.getTransferListener().transferSucceeded(completedEvent);
|
||||
String message = new String(this.baos.toByteArray()).replace("\\", "/");
|
||||
assertThat(message, startsWith("Downloaded: " + REPOSITORY + ARTIFACT));
|
||||
assertThat(message, containsString("4KB at"));
|
||||
assertThat(message, containsString("KB/sec"));
|
||||
assertThat(message, endsWith("\n"));
|
||||
assertThat(message).startsWith("Downloaded: " + REPOSITORY + ARTIFACT);
|
||||
assertThat(message).contains("4KB at");
|
||||
assertThat(message).contains("KB/sec");
|
||||
assertThat(message).endsWith("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,11 +31,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@ -72,15 +68,13 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
|
||||
GrapeRootRepositorySystemSessionAutoConfigurationTests.this.session,
|
||||
localRepository);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
new GrapeRootRepositorySystemSessionAutoConfiguration().apply(this.session,
|
||||
this.repositorySystem);
|
||||
|
||||
verify(this.repositorySystem, times(0))
|
||||
.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class));
|
||||
|
||||
assertThat(this.session.getLocalRepository(), is(nullValue()));
|
||||
assertThat(this.session.getLocalRepository()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -101,9 +95,9 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
|
||||
verify(this.repositorySystem, times(1))
|
||||
.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class));
|
||||
|
||||
assertThat(this.session.getLocalRepository(), is(notNullValue()));
|
||||
assertThat(this.session.getLocalRepository().getBasedir().getAbsolutePath(),
|
||||
endsWith(File.separatorChar + "foo" + File.separatorChar + "repository"));
|
||||
assertThat(this.session.getLocalRepository()).isNotNull();
|
||||
assertThat(this.session.getLocalRepository().getBasedir().getAbsolutePath())
|
||||
.endsWith(File.separatorChar + "foo" + File.separatorChar + "repository");
|
||||
}
|
||||
|
||||
private class LocalRepositoryManagerAnswer implements Answer<LocalRepositoryManager> {
|
||||
|
@ -40,10 +40,7 @@ import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.boot.cli.util.SystemProperties;
|
||||
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@ -99,14 +96,13 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
|
||||
}, "user.home:src/test/resources/maven-settings/property-interpolation",
|
||||
"foo:bar");
|
||||
|
||||
assertThat(session.getLocalRepository().getBasedir().getAbsolutePath(),
|
||||
endsWith(File.separatorChar + "bar" + File.separatorChar + "repository"));
|
||||
assertThat(session.getLocalRepository().getBasedir().getAbsolutePath())
|
||||
.endsWith(File.separatorChar + "bar" + File.separatorChar + "repository");
|
||||
}
|
||||
|
||||
private void assertSessionCustomization(String userHome) {
|
||||
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils
|
||||
.newSession();
|
||||
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -117,7 +113,6 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
|
||||
|
||||
RemoteRepository repository = new RemoteRepository.Builder("my-server", "default",
|
||||
"http://maven.example.com").build();
|
||||
|
||||
assertMirrorSelectorConfiguration(session, repository);
|
||||
assertProxySelectorConfiguration(session, repository);
|
||||
assertAuthenticationSelectorConfiguration(session, repository);
|
||||
@ -129,34 +124,33 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
|
||||
repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
|
||||
AuthenticationContext authenticationContext = AuthenticationContext
|
||||
.forProxy(session, repository);
|
||||
assertEquals("proxy.example.com", proxy.getHost());
|
||||
assertEquals("proxyuser",
|
||||
authenticationContext.get(AuthenticationContext.USERNAME));
|
||||
assertEquals("somepassword",
|
||||
authenticationContext.get(AuthenticationContext.PASSWORD));
|
||||
assertThat(proxy.getHost()).isEqualTo("proxy.example.com");
|
||||
assertThat(authenticationContext.get(AuthenticationContext.USERNAME))
|
||||
.isEqualTo("proxyuser");
|
||||
assertThat(authenticationContext.get(AuthenticationContext.PASSWORD))
|
||||
.isEqualTo("somepassword");
|
||||
}
|
||||
|
||||
private void assertMirrorSelectorConfiguration(DefaultRepositorySystemSession session,
|
||||
RemoteRepository repository) {
|
||||
RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);
|
||||
assertNotNull("No mirror configured for repository " + repository.getId(),
|
||||
mirror);
|
||||
assertEquals("maven.example.com", mirror.getHost());
|
||||
assertThat(mirror).as("Mirror configured for repository " + repository.getId())
|
||||
.isNotNull();
|
||||
assertThat(mirror.getHost()).isEqualTo("maven.example.com");
|
||||
}
|
||||
|
||||
private void assertAuthenticationSelectorConfiguration(
|
||||
DefaultRepositorySystemSession session, RemoteRepository repository) {
|
||||
Authentication authentication = session.getAuthenticationSelector()
|
||||
.getAuthentication(repository);
|
||||
|
||||
repository = new RemoteRepository.Builder(repository)
|
||||
.setAuthentication(authentication).build();
|
||||
|
||||
AuthenticationContext authenticationContext = AuthenticationContext
|
||||
.forRepository(session, repository);
|
||||
|
||||
assertEquals("tester", authenticationContext.get(AuthenticationContext.USERNAME));
|
||||
assertEquals("secret", authenticationContext.get(AuthenticationContext.PASSWORD));
|
||||
assertThat(authenticationContext.get(AuthenticationContext.USERNAME))
|
||||
.isEqualTo("tester");
|
||||
assertThat(authenticationContext.get(AuthenticationContext.PASSWORD))
|
||||
.isEqualTo("secret");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ResourceUtils}.
|
||||
@ -39,8 +38,8 @@ public class ResourceUtilsTests {
|
||||
public void explicitClasspathResource() {
|
||||
List<String> urls = ResourceUtils.getUrls("classpath:init.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -49,68 +48,68 @@ public class ResourceUtilsTests {
|
||||
new URL("file:./src/test/resources/"),
|
||||
new File("src/test/resources/").getAbsoluteFile().toURI().toURL() });
|
||||
List<String> urls = ResourceUtils.getUrls("classpath:init.groovy", loader);
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitClasspathResourceWithSlash() {
|
||||
List<String> urls = ResourceUtils.getUrls("classpath:/init.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void implicitClasspathResource() {
|
||||
List<String> urls = ResourceUtils.getUrls("init.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void implicitClasspathResourceWithSlash() {
|
||||
List<String> urls = ResourceUtils.getUrls("/init.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonexistentClasspathResource() {
|
||||
List<String> urls = ResourceUtils.getUrls("classpath:nonexistent.groovy", null);
|
||||
assertEquals(0, urls.size());
|
||||
assertThat(urls).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitFile() {
|
||||
List<String> urls = ResourceUtils.getUrls("file:src/test/resources/init.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void implicitFile() {
|
||||
List<String> urls = ResourceUtils.getUrls("src/test/resources/init.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonexistentFile() {
|
||||
List<String> urls = ResourceUtils.getUrls("file:nonexistent.groovy", null);
|
||||
assertEquals(0, urls.size());
|
||||
assertThat(urls).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recursiveFiles() {
|
||||
List<String> urls = ResourceUtils.getUrls("src/test/resources/dir-sample",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -118,8 +117,8 @@ public class ResourceUtilsTests {
|
||||
List<String> urls = ResourceUtils.getUrls(
|
||||
"file:src/test/resources/dir-sample/**/*.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -127,8 +126,8 @@ public class ResourceUtilsTests {
|
||||
List<String> urls = ResourceUtils.getUrls(
|
||||
"src/test/resources/dir-sample/**/*.groovy",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -136,16 +135,16 @@ public class ResourceUtilsTests {
|
||||
List<String> urls = ResourceUtils.getUrls(
|
||||
"file:src/test/resources/dir-sample/code/*",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directoryOfFiles() {
|
||||
List<String> urls = ResourceUtils.getUrls("src/test/resources/dir-sample/code/*",
|
||||
ClassUtils.getDefaultClassLoader());
|
||||
assertEquals(1, urls.size());
|
||||
assertTrue(urls.get(0).startsWith("file:"));
|
||||
assertThat(urls).hasSize(1);
|
||||
assertThat(urls.get(0).startsWith("file:")).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user