Commit 962a5985 authored by Phillip Webb's avatar Phillip Webb

Use AssertJ in spring-boot-cli

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