Commit 00cfe1d0 authored by Phillip Webb's avatar Phillip Webb

Use AssertJ in spring-boot-tools

See gh-5083
parent 7f9358f4
...@@ -25,8 +25,7 @@ import org.junit.rules.ExpectedException; ...@@ -25,8 +25,7 @@ import org.junit.rules.ExpectedException;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/** /**
* Base for configuration meta-data tests. * Base for configuration meta-data tests.
...@@ -40,25 +39,25 @@ public abstract class AbstractConfigurationMetadataTests { ...@@ -40,25 +39,25 @@ public abstract class AbstractConfigurationMetadataTests {
protected void assertSource(ConfigurationMetadataSource actual, String groupId, protected void assertSource(ConfigurationMetadataSource actual, String groupId,
String type, String sourceType) { String type, String sourceType) {
assertNotNull(actual); assertThat(actual).isNotNull();
assertEquals(groupId, actual.getGroupId()); assertThat(actual.getGroupId()).isEqualTo(groupId);
assertEquals(type, actual.getType()); assertThat(actual.getType()).isEqualTo(type);
assertEquals(sourceType, actual.getSourceType()); assertThat(actual.getSourceType()).isEqualTo(sourceType);
} }
protected void assertProperty(ConfigurationMetadataProperty actual, String id, protected void assertProperty(ConfigurationMetadataProperty actual, String id,
String name, Class<?> type, Object defaultValue) { String name, Class<?> type, Object defaultValue) {
assertNotNull(actual); assertThat(actual).isNotNull();
assertEquals(id, actual.getId()); assertThat(actual.getId()).isEqualTo(id);
assertEquals(name, actual.getName()); assertThat(actual.getName()).isEqualTo(name);
String typeName = type != null ? type.getName() : null; String typeName = type != null ? type.getName() : null;
assertEquals(typeName, actual.getType()); assertThat(actual.getType()).isEqualTo(typeName);
assertEquals(defaultValue, actual.getDefaultValue()); assertThat(actual.getDefaultValue()).isEqualTo(defaultValue);
} }
protected void assertItem(ConfigurationMetadataItem actual, String sourceType) { protected void assertItem(ConfigurationMetadataItem actual, String sourceType) {
assertNotNull(actual); assertThat(actual).isNotNull();
assertEquals(sourceType, actual.getSourceType()); assertThat(actual.getSourceType()).isEqualTo(sourceType);
} }
protected InputStream getInputStreamFor(String name) throws IOException { protected InputStream getInputStreamFor(String name) throws IOException {
......
...@@ -22,9 +22,7 @@ import java.util.Map; ...@@ -22,9 +22,7 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link ConfigurationMetadataRepository}. * Tests for {@link ConfigurationMetadataRepository}.
...@@ -47,10 +45,10 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -47,10 +45,10 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
.create(foo).build(); .create(foo).build();
validateFoo(repo); validateFoo(repo);
assertEquals(1, repo.getAllGroups().size()); assertThat(repo.getAllGroups()).hasSize(1);
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
"spring.foo.counter"); "spring.foo.counter");
assertEquals(3, repo.getAllProperties().size()); assertThat(repo.getAllProperties()).hasSize(3);
} }
finally { finally {
foo.close(); foo.close();
...@@ -66,11 +64,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -66,11 +64,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
.create(foo, bar).build(); .create(foo, bar).build();
validateFoo(repo); validateFoo(repo);
validateBar(repo); validateBar(repo);
assertEquals(2, repo.getAllGroups().size()); assertThat(repo.getAllGroups()).hasSize(2);
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
"spring.foo.counter", "spring.bar.name", "spring.bar.description", "spring.foo.counter", "spring.bar.name", "spring.bar.description",
"spring.bar.counter"); "spring.bar.counter");
assertEquals(6, repo.getAllProperties().size()); assertThat(repo.getAllProperties()).hasSize(6);
} }
finally { finally {
foo.close(); foo.close();
...@@ -86,11 +84,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -86,11 +84,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
.create(foo, root).build(); .create(foo, root).build();
validateFoo(repo); validateFoo(repo);
assertEquals(2, repo.getAllGroups().size()); assertThat(repo.getAllGroups()).hasSize(2);
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
"spring.foo.counter", "spring.root.name", "spring.root2.name"); "spring.foo.counter", "spring.root.name", "spring.root2.name");
assertEquals(5, repo.getAllProperties().size()); assertThat(repo.getAllProperties()).hasSize(5);
} }
finally { finally {
foo.close(); foo.close();
...@@ -105,17 +103,17 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -105,17 +103,17 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
try { try {
ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder ConfigurationMetadataRepository repo = ConfigurationMetadataRepositoryJsonBuilder
.create(foo, foo2).build(); .create(foo, foo2).build();
assertEquals(1, repo.getAllGroups().size()); assertThat(repo.getAllGroups()).hasSize(1);
ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo"); ConfigurationMetadataGroup group = repo.getAllGroups().get("spring.foo");
contains(group.getSources(), "org.acme.Foo", "org.acme.Foo2", contains(group.getSources(), "org.acme.Foo", "org.acme.Foo2",
"org.springframework.boot.FooProperties"); "org.springframework.boot.FooProperties");
assertEquals(3, group.getSources().size()); assertThat(group.getSources()).hasSize(3);
contains(group.getProperties(), "spring.foo.name", "spring.foo.description", contains(group.getProperties(), "spring.foo.name", "spring.foo.description",
"spring.foo.counter", "spring.foo.enabled", "spring.foo.type"); "spring.foo.counter", "spring.foo.enabled", "spring.foo.type");
assertEquals(5, group.getProperties().size()); assertThat(group.getProperties()).hasSize(5);
contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description", contains(repo.getAllProperties(), "spring.foo.name", "spring.foo.description",
"spring.foo.counter", "spring.foo.enabled", "spring.foo.type"); "spring.foo.counter", "spring.foo.enabled", "spring.foo.type");
assertEquals(5, repo.getAllProperties().size()); assertThat(repo.getAllProperties()).hasSize(5);
} }
finally { finally {
foo.close(); foo.close();
...@@ -138,11 +136,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -138,11 +136,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
validateFoo(secondRepo); validateFoo(secondRepo);
validateBar(secondRepo); validateBar(secondRepo);
// first repo not impacted by second build // first repo not impacted by second build
assertNotEquals(firstRepo, secondRepo); assertThat(secondRepo).isNotEqualTo(firstRepo);
assertEquals(1, firstRepo.getAllGroups().size()); assertThat(firstRepo.getAllGroups()).hasSize(1);
assertEquals(3, firstRepo.getAllProperties().size()); assertThat(firstRepo.getAllProperties()).hasSize(3);
assertEquals(2, secondRepo.getAllGroups().size()); assertThat(secondRepo.getAllGroups()).hasSize(2);
assertEquals(6, secondRepo.getAllProperties().size()); assertThat(secondRepo.getAllProperties()).hasSize(6);
} }
finally { finally {
foo.close(); foo.close();
...@@ -156,11 +154,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -156,11 +154,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
"org.springframework.boot.FooProperties"); "org.springframework.boot.FooProperties");
ConfigurationMetadataSource source = group.getSources().get("org.acme.Foo"); ConfigurationMetadataSource source = group.getSources().get("org.acme.Foo");
contains(source.getProperties(), "spring.foo.name", "spring.foo.description"); contains(source.getProperties(), "spring.foo.name", "spring.foo.description");
assertEquals(2, source.getProperties().size()); assertThat(source.getProperties()).hasSize(2);
ConfigurationMetadataSource source2 = group.getSources() ConfigurationMetadataSource source2 = group.getSources()
.get("org.springframework.boot.FooProperties"); .get("org.springframework.boot.FooProperties");
contains(source2.getProperties(), "spring.foo.name", "spring.foo.counter"); contains(source2.getProperties(), "spring.foo.name", "spring.foo.counter");
assertEquals(2, source2.getProperties().size()); assertThat(source2.getProperties()).hasSize(2);
validatePropertyHints(repo.getAllProperties().get("spring.foo.name"), 0, 0); validatePropertyHints(repo.getAllProperties().get("spring.foo.name"), 0, 0);
validatePropertyHints(repo.getAllProperties().get("spring.foo.description"), 0, validatePropertyHints(repo.getAllProperties().get("spring.foo.description"), 0,
0); 0);
...@@ -173,11 +171,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -173,11 +171,11 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
"org.springframework.boot.BarProperties"); "org.springframework.boot.BarProperties");
ConfigurationMetadataSource source = group.getSources().get("org.acme.Bar"); ConfigurationMetadataSource source = group.getSources().get("org.acme.Bar");
contains(source.getProperties(), "spring.bar.name", "spring.bar.description"); contains(source.getProperties(), "spring.bar.name", "spring.bar.description");
assertEquals(2, source.getProperties().size()); assertThat(source.getProperties()).hasSize(2);
ConfigurationMetadataSource source2 = group.getSources() ConfigurationMetadataSource source2 = group.getSources()
.get("org.springframework.boot.BarProperties"); .get("org.springframework.boot.BarProperties");
contains(source2.getProperties(), "spring.bar.name", "spring.bar.counter"); contains(source2.getProperties(), "spring.bar.name", "spring.bar.counter");
assertEquals(2, source2.getProperties().size()); assertThat(source2.getProperties()).hasSize(2);
validatePropertyHints(repo.getAllProperties().get("spring.bar.name"), 0, 0); validatePropertyHints(repo.getAllProperties().get("spring.bar.name"), 0, 0);
validatePropertyHints(repo.getAllProperties().get("spring.bar.description"), 2, validatePropertyHints(repo.getAllProperties().get("spring.bar.description"), 2,
2); 2);
...@@ -186,14 +184,13 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests ...@@ -186,14 +184,13 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
private void validatePropertyHints(ConfigurationMetadataProperty property, private void validatePropertyHints(ConfigurationMetadataProperty property,
int valueHints, int valueProviders) { int valueHints, int valueProviders) {
assertEquals(valueHints, property.getValueHints().size()); assertThat(property.getValueHints().size()).isEqualTo(valueHints);
assertEquals(valueProviders, property.getValueHints().size()); assertThat(property.getValueHints().size()).isEqualTo(valueProviders);
} }
private void contains(Map<String, ?> source, String... keys) { private void contains(Map<String, ?> source, String... keys) {
for (String key : keys) { for (String key : keys) {
assertTrue("Item '" + key + "' not found. Got " + source.keySet(), assertThat(source).containsKey(key);
source.containsKey(key));
} }
} }
......
...@@ -18,7 +18,7 @@ package org.springframework.boot.configurationmetadata; ...@@ -18,7 +18,7 @@ package org.springframework.boot.configurationmetadata;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link DescriptionExtractor}. * Tests for {@link DescriptionExtractor}.
...@@ -35,39 +35,39 @@ public class DescriptionExtractorTests { ...@@ -35,39 +35,39 @@ public class DescriptionExtractorTests {
public void extractShortDescription() { public void extractShortDescription() {
String description = this.extractor String description = this.extractor
.getShortDescription("My short " + "description. More stuff."); .getShortDescription("My short " + "description. More stuff.");
assertEquals("My short description.", description); assertThat(description).isEqualTo("My short description.");
} }
@Test @Test
public void extractShortDescriptionNewLineBeforeDot() { public void extractShortDescriptionNewLineBeforeDot() {
String description = this.extractor.getShortDescription( String description = this.extractor.getShortDescription(
"My short" + NEW_LINE + "description." + NEW_LINE + "More stuff."); "My short" + NEW_LINE + "description." + NEW_LINE + "More stuff.");
assertEquals("My short description.", description); assertThat(description).isEqualTo("My short description.");
} }
@Test @Test
public void extractShortDescriptionNewLineBeforeDotWithSpaces() { public void extractShortDescriptionNewLineBeforeDotWithSpaces() {
String description = this.extractor.getShortDescription( String description = this.extractor.getShortDescription(
"My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff."); "My short " + NEW_LINE + " description. " + NEW_LINE + "More stuff.");
assertEquals("My short description.", description); assertThat(description).isEqualTo("My short description.");
} }
@Test @Test
public void extractShortDescriptionNoDot() { public void extractShortDescriptionNoDot() {
String description = this.extractor.getShortDescription("My short description"); String description = this.extractor.getShortDescription("My short description");
assertEquals("My short description", description); assertThat(description).isEqualTo("My short description");
} }
@Test @Test
public void extractShortDescriptionNoDotMultipleLines() { public void extractShortDescriptionNoDotMultipleLines() {
String description = this.extractor String description = this.extractor
.getShortDescription("My short description " + NEW_LINE + " More stuff"); .getShortDescription("My short description " + NEW_LINE + " More stuff");
assertEquals("My short description", description); assertThat(description).isEqualTo("My short description");
} }
@Test @Test
public void extractShortDescriptionNull() { public void extractShortDescriptionNull() {
assertEquals(null, this.extractor.getShortDescription(null)); assertThat(this.extractor.getShortDescription(null)).isEqualTo(null);
} }
} }
...@@ -23,10 +23,7 @@ import java.util.List; ...@@ -23,10 +23,7 @@ import java.util.List;
import org.json.JSONException; import org.json.JSONException;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link JsonReader} * Tests for {@link JsonReader}
...@@ -42,8 +39,8 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { ...@@ -42,8 +39,8 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
@Test @Test
public void emptyMetadata() throws IOException { public void emptyMetadata() throws IOException {
RawConfigurationMetadata rawMetadata = readFor("empty"); RawConfigurationMetadata rawMetadata = readFor("empty");
assertEquals(0, rawMetadata.getSources().size()); assertThat(rawMetadata.getSources()).isEmpty();
assertEquals(0, rawMetadata.getItems().size()); assertThat(rawMetadata.getItems()).isEmpty();
} }
@Test @Test
...@@ -56,17 +53,17 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { ...@@ -56,17 +53,17 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
public void simpleMetadata() throws IOException { public void simpleMetadata() throws IOException {
RawConfigurationMetadata rawMetadata = readFor("foo"); RawConfigurationMetadata rawMetadata = readFor("foo");
List<ConfigurationMetadataSource> sources = rawMetadata.getSources(); List<ConfigurationMetadataSource> sources = rawMetadata.getSources();
assertEquals(2, sources.size()); assertThat(sources).hasSize(2);
List<ConfigurationMetadataItem> items = rawMetadata.getItems(); List<ConfigurationMetadataItem> items = rawMetadata.getItems();
assertEquals(4, items.size()); assertThat(items).hasSize(4);
List<ConfigurationMetadataHint> hints = rawMetadata.getHints(); List<ConfigurationMetadataHint> hints = rawMetadata.getHints();
assertEquals(1, hints.size()); assertThat(hints).hasSize(1);
ConfigurationMetadataSource source = sources.get(0); ConfigurationMetadataSource source = sources.get(0);
assertSource(source, "spring.foo", "org.acme.Foo", "org.acme.config.FooApp"); assertSource(source, "spring.foo", "org.acme.Foo", "org.acme.config.FooApp");
assertEquals("foo()", source.getSourceMethod()); assertThat(source.getSourceMethod()).isEqualTo("foo()");
assertEquals("This is Foo.", source.getDescription()); assertThat(source.getDescription()).isEqualTo("This is Foo.");
assertEquals("This is Foo.", source.getShortDescription()); assertThat(source.getShortDescription()).isEqualTo("This is Foo.");
ConfigurationMetadataItem item = items.get(0); ConfigurationMetadataItem item = items.get(0);
assertProperty(item, "spring.foo.name", "name", String.class, null); assertProperty(item, "spring.foo.name", "name", String.class, null);
...@@ -74,61 +71,62 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { ...@@ -74,61 +71,62 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
ConfigurationMetadataItem item2 = items.get(1); ConfigurationMetadataItem item2 = items.get(1);
assertProperty(item2, "spring.foo.description", "description", String.class, assertProperty(item2, "spring.foo.description", "description", String.class,
"FooBar"); "FooBar");
assertEquals("Foo description.", item2.getDescription()); assertThat(item2.getDescription()).isEqualTo("Foo description.");
assertEquals("Foo description.", item2.getShortDescription()); assertThat(item2.getShortDescription()).isEqualTo("Foo description.");
assertNull(item2.getSourceMethod()); assertThat(item2.getSourceMethod()).isNull();
assertItem(item2, "org.acme.Foo"); assertItem(item2, "org.acme.Foo");
ConfigurationMetadataHint hint = hints.get(0); ConfigurationMetadataHint hint = hints.get(0);
assertEquals("spring.foo.counter", hint.getId()); assertThat(hint.getId()).isEqualTo("spring.foo.counter");
assertEquals(1, hint.getValueHints().size()); assertThat(hint.getValueHints()).hasSize(1);
ValueHint valueHint = hint.getValueHints().get(0); ValueHint valueHint = hint.getValueHints().get(0);
assertEquals(42, valueHint.getValue()); assertThat(valueHint.getValue()).isEqualTo(42);
assertEquals("Because that's the answer to any question, choose it. \nReally.", assertThat(valueHint.getDescription()).isEqualTo(
valueHint.getDescription()); "Because that's the answer to any question, choose it. \nReally.");
assertEquals("Because that's the answer to any question, choose it.", assertThat(valueHint.getShortDescription())
valueHint.getShortDescription()); .isEqualTo("Because that's the answer to any question, choose it.");
assertEquals(1, hint.getValueProviders().size()); assertThat(hint.getValueProviders()).hasSize(1);
ValueProvider valueProvider = hint.getValueProviders().get(0); ValueProvider valueProvider = hint.getValueProviders().get(0);
assertEquals("handle-as", valueProvider.getName()); assertThat(valueProvider.getName()).isEqualTo("handle-as");
assertEquals(1, valueProvider.getParameters().size()); assertThat(valueProvider.getParameters()).hasSize(1);
assertEquals(Integer.class.getName(), assertThat(valueProvider.getParameters().get("target"))
valueProvider.getParameters().get("target")); .isEqualTo(Integer.class.getName());
} }
@Test @Test
public void metadataHints() throws IOException { public void metadataHints() throws IOException {
RawConfigurationMetadata rawMetadata = readFor("bar"); RawConfigurationMetadata rawMetadata = readFor("bar");
List<ConfigurationMetadataHint> hints = rawMetadata.getHints(); List<ConfigurationMetadataHint> hints = rawMetadata.getHints();
assertEquals(1, hints.size()); assertThat(hints).hasSize(1);
ConfigurationMetadataHint hint = hints.get(0); ConfigurationMetadataHint hint = hints.get(0);
assertEquals("spring.bar.description", hint.getId()); assertThat(hint.getId()).isEqualTo("spring.bar.description");
assertEquals(2, hint.getValueHints().size()); assertThat(hint.getValueHints()).hasSize(2);
ValueHint valueHint = hint.getValueHints().get(0); ValueHint valueHint = hint.getValueHints().get(0);
assertEquals("one", valueHint.getValue()); assertThat(valueHint.getValue()).isEqualTo("one");
assertEquals("One.", valueHint.getDescription()); assertThat(valueHint.getDescription()).isEqualTo("One.");
ValueHint valueHint2 = hint.getValueHints().get(1); ValueHint valueHint2 = hint.getValueHints().get(1);
assertEquals("two", valueHint2.getValue()); assertThat(valueHint2.getValue()).isEqualTo("two");
assertEquals(null, valueHint2.getDescription()); assertThat(valueHint2.getDescription()).isEqualTo(null);
assertEquals(2, hint.getValueProviders().size()); assertThat(hint.getValueProviders()).hasSize(2);
ValueProvider valueProvider = hint.getValueProviders().get(0); ValueProvider valueProvider = hint.getValueProviders().get(0);
assertEquals("handle-as", valueProvider.getName()); assertThat(valueProvider.getName()).isEqualTo("handle-as");
assertEquals(1, valueProvider.getParameters().size()); assertThat(valueProvider.getParameters()).hasSize(1);
assertEquals(String.class.getName(), valueProvider.getParameters().get("target")); assertThat(valueProvider.getParameters().get("target"))
.isEqualTo(String.class.getName());
ValueProvider valueProvider2 = hint.getValueProviders().get(1); ValueProvider valueProvider2 = hint.getValueProviders().get(1);
assertEquals("any", valueProvider2.getName()); assertThat(valueProvider2.getName()).isEqualTo("any");
assertEquals(0, valueProvider2.getParameters().size()); assertThat(valueProvider2.getParameters()).isEmpty();
} }
@Test @Test
public void rootMetadata() throws IOException { public void rootMetadata() throws IOException {
RawConfigurationMetadata rawMetadata = readFor("root"); RawConfigurationMetadata rawMetadata = readFor("root");
List<ConfigurationMetadataSource> sources = rawMetadata.getSources(); List<ConfigurationMetadataSource> sources = rawMetadata.getSources();
assertEquals(0, sources.size()); assertThat(sources).isEmpty();
List<ConfigurationMetadataItem> items = rawMetadata.getItems(); List<ConfigurationMetadataItem> items = rawMetadata.getItems();
assertEquals(2, items.size()); assertThat(items).hasSize(2);
ConfigurationMetadataItem item = items.get(0); ConfigurationMetadataItem item = items.get(0);
assertProperty(item, "spring.root.name", "spring.root.name", String.class, null); assertProperty(item, "spring.root.name", "spring.root.name", String.class, null);
} }
...@@ -137,27 +135,28 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests { ...@@ -137,27 +135,28 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
public void deprecatedMetadata() throws IOException { public void deprecatedMetadata() throws IOException {
RawConfigurationMetadata rawMetadata = readFor("deprecated"); RawConfigurationMetadata rawMetadata = readFor("deprecated");
List<ConfigurationMetadataItem> items = rawMetadata.getItems(); List<ConfigurationMetadataItem> items = rawMetadata.getItems();
assertEquals(3, items.size()); assertThat(items).hasSize(3);
ConfigurationMetadataItem item = items.get(0); ConfigurationMetadataItem item = items.get(0);
assertProperty(item, "server.port", "server.port", Integer.class, null); assertProperty(item, "server.port", "server.port", Integer.class, null);
assertTrue(item.isDeprecated()); assertThat(item.isDeprecated()).isTrue();
assertEquals("Server namespace has moved to spring.server", assertThat(item.getDeprecation().getReason())
item.getDeprecation().getReason()); .isEqualTo("Server namespace has moved to spring.server");
assertEquals("server.spring.port", item.getDeprecation().getReplacement()); assertThat(item.getDeprecation().getReplacement())
.isEqualTo("server.spring.port");
ConfigurationMetadataItem item2 = items.get(1); ConfigurationMetadataItem item2 = items.get(1);
assertProperty(item2, "server.cluster-name", "server.cluster-name", String.class, assertProperty(item2, "server.cluster-name", "server.cluster-name", String.class,
null); null);
assertTrue(item2.isDeprecated()); assertThat(item2.isDeprecated()).isTrue();
assertEquals(null, item2.getDeprecation().getReason()); assertThat(item2.getDeprecation().getReason()).isEqualTo(null);
assertEquals(null, item2.getDeprecation().getReplacement()); assertThat(item2.getDeprecation().getReplacement()).isEqualTo(null);
ConfigurationMetadataItem item3 = items.get(2); ConfigurationMetadataItem item3 = items.get(2);
assertProperty(item3, "spring.server.name", "spring.server.name", String.class, assertProperty(item3, "spring.server.name", "spring.server.name", String.class,
null); null);
assertFalse(item3.isDeprecated()); assertThat(item3.isDeprecated()).isFalse();
assertEquals(null, item3.getDeprecation()); assertThat(item3.getDeprecation()).isEqualTo(null);
} }
RawConfigurationMetadata readFor(String path) throws IOException { RawConfigurationMetadata readFor(String path) throws IOException {
......
...@@ -28,6 +28,8 @@ import org.springframework.boot.configurationprocessor.metadata.ConfigurationMet ...@@ -28,6 +28,8 @@ import org.springframework.boot.configurationprocessor.metadata.ConfigurationMet
import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller; import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller;
/** /**
* Test {@link ConfigurationMetadataAnnotationProcessor}.
*
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson * @author Andy Wilkinson
......
...@@ -29,7 +29,6 @@ import javax.lang.model.SourceVersion; ...@@ -29,7 +29,6 @@ import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import org.hamcrest.Matcher;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
...@@ -37,9 +36,7 @@ import org.junit.rules.TemporaryFolder; ...@@ -37,9 +36,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.boot.configurationprocessor.TestCompiler; import org.springframework.boot.configurationprocessor.TestCompiler;
import org.springframework.boot.configurationsample.fieldvalues.FieldValues; import org.springframework.boot.configurationsample.fieldvalues.FieldValues;
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;
/** /**
* Abstract base class for {@link FieldValuesParser} tests. * Abstract base class for {@link FieldValuesParser} tests.
...@@ -60,43 +57,37 @@ public abstract class AbstractFieldValuesProcessorTests { ...@@ -60,43 +57,37 @@ public abstract class AbstractFieldValuesProcessorTests {
TestCompiler compiler = new TestCompiler(this.temporaryFolder); TestCompiler compiler = new TestCompiler(this.temporaryFolder);
compiler.getTask(FieldValues.class).call(processor); compiler.getTask(FieldValues.class).call(processor);
Map<String, Object> values = processor.getValues(); Map<String, Object> values = processor.getValues();
assertThat(values.get("string"), equalToObject("1")); assertThat(values.get("string")).isEqualTo("1");
assertThat(values.get("stringNone"), nullValue()); assertThat(values.get("stringNone")).isNull();
assertThat(values.get("stringConst"), equalToObject("c")); assertThat(values.get("stringConst")).isEqualTo("c");
assertThat(values.get("bool"), equalToObject(true)); assertThat(values.get("bool")).isEqualTo(true);
assertThat(values.get("boolNone"), equalToObject(false)); assertThat(values.get("boolNone")).isEqualTo(false);
assertThat(values.get("boolConst"), equalToObject(true)); assertThat(values.get("boolConst")).isEqualTo(true);
assertThat(values.get("boolObject"), equalToObject(true)); assertThat(values.get("boolObject")).isEqualTo(true);
assertThat(values.get("boolObjectNone"), nullValue()); assertThat(values.get("boolObjectNone")).isNull();
assertThat(values.get("boolObjectConst"), equalToObject(true)); assertThat(values.get("boolObjectConst")).isEqualTo(true);
assertThat(values.get("integer"), equalToObject(1)); assertThat(values.get("integer")).isEqualTo(1);
assertThat(values.get("integerNone"), equalToObject(0)); assertThat(values.get("integerNone")).isEqualTo(0);
assertThat(values.get("integerConst"), equalToObject(2)); assertThat(values.get("integerConst")).isEqualTo(2);
assertThat(values.get("integerObject"), equalToObject(3)); assertThat(values.get("integerObject")).isEqualTo(3);
assertThat(values.get("integerObjectNone"), nullValue()); assertThat(values.get("integerObjectNone")).isNull();
assertThat(values.get("integerObjectConst"), equalToObject(4)); assertThat(values.get("integerObjectConst")).isEqualTo(4);
assertThat(values.get("charset"), equalToObject("US-ASCII")); assertThat(values.get("charset")).isEqualTo("US-ASCII");
assertThat(values.get("charsetConst"), equalToObject("UTF-8")); assertThat(values.get("charsetConst")).isEqualTo("UTF-8");
assertThat(values.get("mimeType"), equalToObject("text/html")); assertThat(values.get("mimeType")).isEqualTo("text/html");
assertThat(values.get("mimeTypeConst"), equalToObject("text/plain")); assertThat(values.get("mimeTypeConst")).isEqualTo("text/plain");
assertThat(values.get("object"), equalToObject(123)); assertThat(values.get("object")).isEqualTo(123);
assertThat(values.get("objectNone"), nullValue()); assertThat(values.get("objectNone")).isNull();
assertThat(values.get("objectConst"), equalToObject("c")); assertThat(values.get("objectConst")).isEqualTo("c");
assertThat(values.get("objectInstance"), nullValue()); assertThat(values.get("objectInstance")).isNull();
assertThat(values.get("stringArray"), assertThat(values.get("stringArray")).isEqualTo(new Object[] { "FOO", "BAR" });
equalToObject(new Object[] { "FOO", "BAR" })); assertThat(values.get("stringArrayNone")).isNull();
assertThat(values.get("stringArrayNone"), nullValue()); assertThat(values.get("stringEmptyArray")).isEqualTo(new Object[0]);
assertThat(values.get("stringEmptyArray"), equalToObject(new Object[0])); assertThat(values.get("stringArrayConst")).isEqualTo(new Object[] { "OK", "KO" });
assertThat(values.get("stringArrayConst"), assertThat(values.get("stringArrayConstElements"))
equalToObject(new Object[] { "OK", "KO" })); .isEqualTo(new Object[] { "c" });
assertThat(values.get("stringArrayConstElements"), assertThat(values.get("integerArray")).isEqualTo(new Object[] { 42, 24 });
equalToObject(new Object[] { "c" })); assertThat(values.get("unknownArray")).isNull();
assertThat(values.get("integerArray"), equalToObject(new Object[] { 42, 24 }));
assertThat(values.get("unknownArray"), nullValue());
}
private Matcher<Object> equalToObject(Object object) {
return equalTo(object);
} }
@SupportedAnnotationTypes({ @SupportedAnnotationTypes({
......
...@@ -18,8 +18,7 @@ package org.springframework.boot.configurationprocessor.metadata; ...@@ -18,8 +18,7 @@ package org.springframework.boot.configurationprocessor.metadata;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link ConfigurationMetadata}. * Tests for {@link ConfigurationMetadata}.
...@@ -30,43 +29,44 @@ public class ConfigurationMetadataTests { ...@@ -30,43 +29,44 @@ public class ConfigurationMetadataTests {
@Test @Test
public void toDashedCaseCamelCase() { public void toDashedCaseCamelCase() {
assertThat(toDashedCase("simpleCamelCase"), is("simple-camel-case")); assertThat(toDashedCase("simpleCamelCase")).isEqualTo("simple-camel-case");
} }
@Test @Test
public void toDashedCaseWordsUnderscore() { public void toDashedCaseWordsUnderscore() {
assertThat(toDashedCase("Word_With_underscore"), is("word_with_underscore")); assertThat(toDashedCase("Word_With_underscore"))
.isEqualTo("word_with_underscore");
} }
@Test @Test
public void toDashedCaseWordsSeveralUnderscores() { public void toDashedCaseWordsSeveralUnderscores() {
assertThat(toDashedCase("Word___With__underscore"), assertThat(toDashedCase("Word___With__underscore"))
is("word___with__underscore")); .isEqualTo("word___with__underscore");
} }
@Test @Test
public void toDashedCaseLowerCaseUnderscore() { public void toDashedCaseLowerCaseUnderscore() {
assertThat(toDashedCase("lower_underscore"), is("lower_underscore")); assertThat(toDashedCase("lower_underscore")).isEqualTo("lower_underscore");
} }
@Test @Test
public void toDashedCaseUpperUnderscore() { public void toDashedCaseUpperUnderscore() {
assertThat(toDashedCase("UPPER_UNDERSCORE"), is("upper_underscore")); assertThat(toDashedCase("UPPER_UNDERSCORE")).isEqualTo("upper_underscore");
} }
@Test @Test
public void toDashedCaseMultipleUnderscores() { public void toDashedCaseMultipleUnderscores() {
assertThat(toDashedCase("super___crazy"), is("super___crazy")); assertThat(toDashedCase("super___crazy")).isEqualTo("super___crazy");
} }
@Test @Test
public void toDashedCaseUppercase() { public void toDashedCaseUppercase() {
assertThat(toDashedCase("UPPERCASE"), is("uppercase")); assertThat(toDashedCase("UPPERCASE")).isEqualTo("uppercase");
} }
@Test @Test
public void toDashedCaseLowercase() { public void toDashedCaseLowercase() {
assertThat(toDashedCase("lowercase"), is("lowercase")); assertThat(toDashedCase("lowercase")).isEqualTo("lowercase");
} }
private String toDashedCase(String name) { private String toDashedCase(String name) {
......
...@@ -25,11 +25,9 @@ import java.util.Collections; ...@@ -25,11 +25,9 @@ import java.util.Collections;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is; import org.springframework.boot.configurationprocessor.Metadata;
import static org.junit.Assert.assertThat;
import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsGroup; import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsHint;
import static org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.containsProperty;
/** /**
* Tests for {@link JsonMarshaller}. * Tests for {@link JsonMarshaller}.
...@@ -70,22 +68,21 @@ public class JsonMarshallerTests { ...@@ -70,22 +68,21 @@ public class JsonMarshallerTests {
marshaller.write(metadata, outputStream); marshaller.write(metadata, outputStream);
ConfigurationMetadata read = marshaller ConfigurationMetadata read = marshaller
.read(new ByteArrayInputStream(outputStream.toByteArray())); .read(new ByteArrayInputStream(outputStream.toByteArray()));
assertThat(read, assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class)
containsProperty("a.b", StringBuffer.class).fromSource(InputStream.class) .fromSource(InputStream.class).withDescription("desc")
.withDescription("desc").withDefaultValue(is("x")) .withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
.withDeprecation("Deprecation comment", "b.c.d")); assertThat(read).has(Metadata.withProperty("b.c.d"));
assertThat(read, containsProperty("b.c.d")); assertThat(read).has(Metadata.withProperty("c").withDefaultValue(123));
assertThat(read, containsProperty("c").withDefaultValue(is(123))); assertThat(read).has(Metadata.withProperty("d").withDefaultValue(true));
assertThat(read, containsProperty("d").withDefaultValue(is(true))); assertThat(read).has(
assertThat(read, Metadata.withProperty("e").withDefaultValue(new String[] { "y", "n" }));
containsProperty("e").withDefaultValue(is(new String[] { "y", "n" }))); assertThat(read).has(Metadata.withProperty("f")
assertThat(read, containsProperty("f") .withDefaultValue(new Object[] { true, false }));
.withDefaultValue(is(new boolean[] { true, false }))); assertThat(read).has(Metadata.withGroup("d"));
assertThat(read, containsGroup("d")); assertThat(read).has(Metadata.withHint("a.b"));
assertThat(read, containsHint("a.b")); assertThat(read).has(
assertThat(read, Metadata.withHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
containsHint("c").withValue(0, 123, "hey").withValue(1, 456, null)); assertThat(read).has(Metadata.withHint("d").withProvider("first", "target", "foo")
assertThat(read, containsHint("d").withProvider("first", "target", "foo")
.withProvider("second")); .withProvider("second"));
} }
......
...@@ -26,9 +26,7 @@ import org.junit.rules.TemporaryFolder; ...@@ -26,9 +26,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link DefaultLaunchScript}. * Tests for {@link DefaultLaunchScript}.
...@@ -45,7 +43,7 @@ public class DefaultLaunchScriptTests { ...@@ -45,7 +43,7 @@ public class DefaultLaunchScriptTests {
public void loadsDefaultScript() throws Exception { public void loadsDefaultScript() throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null, null); DefaultLaunchScript script = new DefaultLaunchScript(null, null);
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, containsString("Spring Boot Startup Script")); assertThat(content).contains("Spring Boot Startup Script");
} }
@Test @Test
...@@ -82,14 +80,14 @@ public class DefaultLaunchScriptTests { ...@@ -82,14 +80,14 @@ public class DefaultLaunchScriptTests {
public void defaultForUseStartStopDaemonIsTrue() throws Exception { public void defaultForUseStartStopDaemonIsTrue() throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null, null); DefaultLaunchScript script = new DefaultLaunchScript(null, null);
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, containsString("USE_START_STOP_DAEMON=\"true\"")); assertThat(content).contains("USE_START_STOP_DAEMON=\"true\"");
} }
@Test @Test
public void defaultForModeIsAuto() throws Exception { public void defaultForModeIsAuto() throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null, null); DefaultLaunchScript script = new DefaultLaunchScript(null, null);
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, containsString("MODE=\"auto\"")); assertThat(content).contains("MODE=\"auto\"");
} }
@Test @Test
...@@ -98,7 +96,7 @@ public class DefaultLaunchScriptTests { ...@@ -98,7 +96,7 @@ public class DefaultLaunchScriptTests {
FileCopyUtils.copy("ABC".getBytes(), file); FileCopyUtils.copy("ABC".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file, null); DefaultLaunchScript script = new DefaultLaunchScript(file, null);
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, equalTo("ABC")); assertThat(content).isEqualTo("ABC");
} }
@Test @Test
...@@ -108,7 +106,7 @@ public class DefaultLaunchScriptTests { ...@@ -108,7 +106,7 @@ public class DefaultLaunchScriptTests {
DefaultLaunchScript script = new DefaultLaunchScript(file, DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:e", "b:o")); createProperties("a:e", "b:o"));
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, equalTo("hello")); assertThat(content).isEqualTo("hello");
} }
@Test @Test
...@@ -118,7 +116,7 @@ public class DefaultLaunchScriptTests { ...@@ -118,7 +116,7 @@ public class DefaultLaunchScriptTests {
DefaultLaunchScript script = new DefaultLaunchScript(file, DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:e", "b:o")); createProperties("a:e", "b:o"));
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, equalTo("hel\nlo")); assertThat(content).isEqualTo("hel\nlo");
} }
@Test @Test
...@@ -127,7 +125,7 @@ public class DefaultLaunchScriptTests { ...@@ -127,7 +125,7 @@ public class DefaultLaunchScriptTests {
FileCopyUtils.copy("h{{a:e}}ll{{b:o}}".getBytes(), file); FileCopyUtils.copy("h{{a:e}}ll{{b:o}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file, null); DefaultLaunchScript script = new DefaultLaunchScript(file, null);
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, equalTo("hello")); assertThat(content).isEqualTo("hello");
} }
@Test @Test
...@@ -137,7 +135,7 @@ public class DefaultLaunchScriptTests { ...@@ -137,7 +135,7 @@ public class DefaultLaunchScriptTests {
DefaultLaunchScript script = new DefaultLaunchScript(file, DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:a")); createProperties("a:a"));
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, equalTo("hallo")); assertThat(content).isEqualTo("hallo");
} }
@Test @Test
...@@ -146,14 +144,14 @@ public class DefaultLaunchScriptTests { ...@@ -146,14 +144,14 @@ public class DefaultLaunchScriptTests {
FileCopyUtils.copy("h{{a}}ll{{b}}".getBytes(), file); FileCopyUtils.copy("h{{a}}ll{{b}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file, null); DefaultLaunchScript script = new DefaultLaunchScript(file, null);
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, equalTo("h{{a}}ll{{b}}")); assertThat(content).isEqualTo("h{{a}}ll{{b}}");
} }
private void assertThatPlaceholderCanBeReplaced(String placeholder) throws Exception { private void assertThatPlaceholderCanBeReplaced(String placeholder) throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null, DefaultLaunchScript script = new DefaultLaunchScript(null,
createProperties(placeholder + ":__test__")); createProperties(placeholder + ":__test__"));
String content = new String(script.toByteArray()); String content = new String(script.toByteArray());
assertThat(content, containsString("__test__")); assertThat(content).contains("__test__");
} }
private Map<?, ?> createProperties(String... pairs) { private Map<?, ?> createProperties(String... pairs) {
......
...@@ -28,10 +28,7 @@ import org.junit.rules.TemporaryFolder; ...@@ -28,10 +28,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.util.FileSystemUtils; import org.springframework.util.FileSystemUtils;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link FileUtils}. * Tests for {@link FileUtils}.
...@@ -65,31 +62,31 @@ public class FileUtilsTests { ...@@ -65,31 +62,31 @@ public class FileUtilsTests {
new File(this.originDirectory, "logback.xml").createNewFile(); new File(this.originDirectory, "logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory); this.originDirectory);
assertFalse(file.exists()); assertThat(file.exists()).isFalse();
} }
@Test @Test
public void nestedDuplicateFile() throws IOException { public void nestedDuplicateFile() throws IOException {
assertTrue(new File(this.outputDirectory, "sub").mkdirs()); assertThat(new File(this.outputDirectory, "sub").mkdirs()).isTrue();
assertTrue(new File(this.originDirectory, "sub").mkdirs()); assertThat(new File(this.originDirectory, "sub").mkdirs()).isTrue();
File file = new File(this.outputDirectory, "sub/logback.xml"); File file = new File(this.outputDirectory, "sub/logback.xml");
file.createNewFile(); file.createNewFile();
new File(this.originDirectory, "sub/logback.xml").createNewFile(); new File(this.originDirectory, "sub/logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory); this.originDirectory);
assertFalse(file.exists()); assertThat(file.exists()).isFalse();
} }
@Test @Test
public void nestedNonDuplicateFile() throws IOException { public void nestedNonDuplicateFile() throws IOException {
assertTrue(new File(this.outputDirectory, "sub").mkdirs()); assertThat(new File(this.outputDirectory, "sub").mkdirs()).isTrue();
assertTrue(new File(this.originDirectory, "sub").mkdirs()); assertThat(new File(this.originDirectory, "sub").mkdirs()).isTrue();
File file = new File(this.outputDirectory, "sub/logback.xml"); File file = new File(this.outputDirectory, "sub/logback.xml");
file.createNewFile(); file.createNewFile();
new File(this.originDirectory, "sub/different.xml").createNewFile(); new File(this.originDirectory, "sub/different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory); this.originDirectory);
assertTrue(file.exists()); assertThat(file.exists()).isTrue();
} }
@Test @Test
...@@ -99,7 +96,7 @@ public class FileUtilsTests { ...@@ -99,7 +96,7 @@ public class FileUtilsTests {
new File(this.originDirectory, "different.xml").createNewFile(); new File(this.originDirectory, "different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory); this.originDirectory);
assertTrue(file.exists()); assertThat(file.exists()).isTrue();
} }
@Test @Test
...@@ -112,8 +109,8 @@ public class FileUtilsTests { ...@@ -112,8 +109,8 @@ public class FileUtilsTests {
finally { finally {
outputStream.close(); outputStream.close();
} }
assertThat(FileUtils.sha1Hash(file), assertThat(FileUtils.sha1Hash(file))
equalTo("7037807198c22a7d2b0807371d763779a84fdfcf")); .isEqualTo("7037807198c22a7d2b0807371d763779a84fdfcf");
} }
} }
...@@ -21,9 +21,7 @@ import java.net.URL; ...@@ -21,9 +21,7 @@ import java.net.URL;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.endsWith; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link JvmUtils}. * Tests for {@link JvmUtils}.
...@@ -36,8 +34,8 @@ public class JvmUtilsTests { ...@@ -36,8 +34,8 @@ public class JvmUtilsTests {
public void getToolsJar() throws Exception { public void getToolsJar() throws Exception {
URL jarUrl = JvmUtils.getToolsJarUrl(); URL jarUrl = JvmUtils.getToolsJarUrl();
// System.out.println(jarUrl); // System.out.println(jarUrl);
assertThat(jarUrl.toString(), endsWith(".jar")); assertThat(jarUrl.toString()).endsWith(".jar");
assertThat(new File(jarUrl.toURI()).exists(), equalTo(true)); assertThat(new File(jarUrl.toURI()).exists()).isTrue();
} }
} }
...@@ -22,10 +22,7 @@ import org.junit.Rule; ...@@ -22,10 +22,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.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link Layouts}. * Tests for {@link Layouts}.
...@@ -40,18 +37,20 @@ public class LayoutsTests { ...@@ -40,18 +37,20 @@ public class LayoutsTests {
@Test @Test
public void jarFile() throws Exception { public void jarFile() throws Exception {
assertThat(Layouts.forFile(new File("test.jar")), instanceOf(Layouts.Jar.class)); assertThat(Layouts.forFile(new File("test.jar"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("test.JAR")), instanceOf(Layouts.Jar.class)); assertThat(Layouts.forFile(new File("test.JAR"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("test.jAr")), instanceOf(Layouts.Jar.class)); assertThat(Layouts.forFile(new File("test.jAr"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("te.st.jar")), instanceOf(Layouts.Jar.class)); assertThat(Layouts.forFile(new File("te.st.jar")))
.isInstanceOf(Layouts.Jar.class);
} }
@Test @Test
public void warFile() throws Exception { public void warFile() throws Exception {
assertThat(Layouts.forFile(new File("test.war")), instanceOf(Layouts.War.class)); assertThat(Layouts.forFile(new File("test.war"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("test.WAR")), instanceOf(Layouts.War.class)); assertThat(Layouts.forFile(new File("test.WAR"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("test.wAr")), instanceOf(Layouts.War.class)); assertThat(Layouts.forFile(new File("test.wAr"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("te.st.war")), instanceOf(Layouts.War.class)); assertThat(Layouts.forFile(new File("te.st.war")))
.isInstanceOf(Layouts.War.class);
} }
@Test @Test
...@@ -64,40 +63,40 @@ public class LayoutsTests { ...@@ -64,40 +63,40 @@ public class LayoutsTests {
@Test @Test
public void jarLayout() throws Exception { public void jarLayout() throws Exception {
Layout layout = new Layouts.Jar(); Layout layout = new Layouts.Jar();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
equalTo("lib/")); .isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
equalTo("lib/")); .isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
equalTo("lib/")); .isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
equalTo("lib/")); .isEqualTo("lib/");
} }
@Test @Test
public void warLayout() throws Exception { public void warLayout() throws Exception {
Layout layout = new Layouts.War(); Layout layout = new Layouts.War();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
equalTo("WEB-INF/lib/")); .isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
equalTo("WEB-INF/lib/")); .isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
equalTo("WEB-INF/lib-provided/")); .isEqualTo("WEB-INF/lib-provided/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
equalTo("WEB-INF/lib/")); .isEqualTo("WEB-INF/lib/");
} }
@Test @Test
public void moduleLayout() throws Exception { public void moduleLayout() throws Exception {
Layout layout = new Layouts.Module(); Layout layout = new Layouts.Module();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
equalTo("lib/")); .isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
nullValue()); .isNull();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
equalTo("lib/")); .isEqualTo("lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM), assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
equalTo("lib/")); .isEqualTo("lib/");
} }
} }
...@@ -30,8 +30,7 @@ import org.springframework.boot.loader.tools.MainClassFinder.ClassNameCallback; ...@@ -30,8 +30,7 @@ import org.springframework.boot.loader.tools.MainClassFinder.ClassNameCallback;
import org.springframework.boot.loader.tools.sample.ClassWithMainMethod; import org.springframework.boot.loader.tools.sample.ClassWithMainMethod;
import org.springframework.boot.loader.tools.sample.ClassWithoutMainMethod; import org.springframework.boot.loader.tools.sample.ClassWithoutMainMethod;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link MainClassFinder}. * Tests for {@link MainClassFinder}.
...@@ -58,7 +57,7 @@ public class MainClassFinderTests { ...@@ -58,7 +57,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("B.class", ClassWithMainMethod.class); this.testJarFile.addClass("B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("A.class", ClassWithoutMainMethod.class); this.testJarFile.addClass("A.class", ClassWithoutMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), ""); String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), "");
assertThat(actual, equalTo("B")); assertThat(actual).isEqualTo("B");
} }
@Test @Test
...@@ -67,7 +66,7 @@ public class MainClassFinderTests { ...@@ -67,7 +66,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/b/c/E.class", ClassWithoutMainMethod.class); this.testJarFile.addClass("a/b/c/E.class", ClassWithoutMainMethod.class);
this.testJarFile.addClass("a/b/F.class", ClassWithoutMainMethod.class); this.testJarFile.addClass("a/b/F.class", ClassWithoutMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), ""); String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), "");
assertThat(actual, equalTo("a.b.c.D")); assertThat(actual).isEqualTo("a.b.c.D");
} }
@Test @Test
...@@ -75,7 +74,7 @@ public class MainClassFinderTests { ...@@ -75,7 +74,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class); this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class); this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), ""); String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), "");
assertThat(actual, equalTo("a.B")); assertThat(actual).isEqualTo("a.B");
} }
@Test @Test
...@@ -94,7 +93,7 @@ public class MainClassFinderTests { ...@@ -94,7 +93,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class); this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(),
"a/"); "a/");
assertThat(actual, equalTo("B")); assertThat(actual).isEqualTo("B");
} }
...@@ -103,7 +102,7 @@ public class MainClassFinderTests { ...@@ -103,7 +102,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("B.class", ClassWithMainMethod.class); this.testJarFile.addClass("B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("A.class", ClassWithoutMainMethod.class); this.testJarFile.addClass("A.class", ClassWithoutMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource()); String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource());
assertThat(actual, equalTo("B")); assertThat(actual).isEqualTo("B");
} }
@Test @Test
...@@ -112,7 +111,7 @@ public class MainClassFinderTests { ...@@ -112,7 +111,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/b/c/E.class", ClassWithoutMainMethod.class); this.testJarFile.addClass("a/b/c/E.class", ClassWithoutMainMethod.class);
this.testJarFile.addClass("a/b/F.class", ClassWithoutMainMethod.class); this.testJarFile.addClass("a/b/F.class", ClassWithoutMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource()); String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource());
assertThat(actual, equalTo("a.b.c.D")); assertThat(actual).isEqualTo("a.b.c.D");
} }
@Test @Test
...@@ -120,7 +119,7 @@ public class MainClassFinderTests { ...@@ -120,7 +119,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class); this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class); this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource()); String actual = MainClassFinder.findMainClass(this.testJarFile.getJarSource());
assertThat(actual, equalTo("a.B")); assertThat(actual).isEqualTo("a.B");
} }
@Test @Test
...@@ -141,7 +140,7 @@ public class MainClassFinderTests { ...@@ -141,7 +140,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/b/G.class", ClassWithMainMethod.class); this.testJarFile.addClass("a/b/G.class", ClassWithMainMethod.class);
ClassNameCollector callback = new ClassNameCollector(); ClassNameCollector callback = new ClassNameCollector();
MainClassFinder.doWithMainClasses(this.testJarFile.getJarSource(), callback); MainClassFinder.doWithMainClasses(this.testJarFile.getJarSource(), callback);
assertThat(callback.getClassNames().toString(), equalTo("[a.b.G, a.b.c.D]")); assertThat(callback.getClassNames().toString()).isEqualTo("[a.b.G, a.b.c.D]");
} }
@Test @Test
...@@ -152,7 +151,7 @@ public class MainClassFinderTests { ...@@ -152,7 +151,7 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/b/G.class", ClassWithMainMethod.class); this.testJarFile.addClass("a/b/G.class", ClassWithMainMethod.class);
ClassNameCollector callback = new ClassNameCollector(); ClassNameCollector callback = new ClassNameCollector();
MainClassFinder.doWithMainClasses(this.testJarFile.getJarFile(), "", callback); MainClassFinder.doWithMainClasses(this.testJarFile.getJarFile(), "", callback);
assertThat(callback.getClassNames().toString(), equalTo("[a.b.G, a.b.c.D]")); assertThat(callback.getClassNames().toString()).isEqualTo("[a.b.G, a.b.c.D]");
} }
private static class ClassNameCollector implements ClassNameCallback<Object> { private static class ClassNameCollector implements ClassNameCallback<Object> {
......
...@@ -28,8 +28,7 @@ import org.mockito.MockitoAnnotations; ...@@ -28,8 +28,7 @@ import org.mockito.MockitoAnnotations;
import org.springframework.boot.loader.archive.Archive.Entry; import org.springframework.boot.loader.archive.Archive.Entry;
import static org.junit.Assert.assertArrayEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
/** /**
...@@ -87,8 +86,8 @@ public class ExecutableArchiveLauncherTests { ...@@ -87,8 +86,8 @@ public class ExecutableArchiveLauncherTests {
} }
private void assertClassLoaderUrls(ClassLoader classLoader, URL[] urls) { private void assertClassLoaderUrls(ClassLoader classLoader, URL[] urls) {
assertTrue(classLoader instanceof URLClassLoader); assertThat(classLoader).isInstanceOf(URLClassLoader.class);
assertArrayEquals(urls, ((URLClassLoader) classLoader).getURLs()); assertThat(((URLClassLoader) classLoader).getURLs()).isEqualTo(urls);
} }
private void doWithTccl(ClassLoader classLoader, Callable<?> action) private void doWithTccl(ClassLoader classLoader, Callable<?> action)
......
...@@ -23,8 +23,7 @@ import java.util.Arrays; ...@@ -23,8 +23,7 @@ import java.util.Arrays;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertFalse; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link InputArgumentsJavaAgentDetector} * Tests for {@link InputArgumentsJavaAgentDetector}
...@@ -38,24 +37,25 @@ public class InputArgumentsJavaAgentDetectorTests { ...@@ -38,24 +37,25 @@ public class InputArgumentsJavaAgentDetectorTests {
throws MalformedURLException, IOException { throws MalformedURLException, IOException {
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector( InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
Arrays.asList("-javaagent:my-agent.jar")); Arrays.asList("-javaagent:my-agent.jar"));
assertFalse(detector.isJavaAgentJar( assertThat(detector.isJavaAgentJar(
new File("something-else.jar").getCanonicalFile().toURI().toURL())); new File("something-else.jar").getCanonicalFile().toURI().toURL()))
.isFalse();
} }
@Test @Test
public void singleJavaAgent() throws MalformedURLException, IOException { public void singleJavaAgent() throws MalformedURLException, IOException {
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector( InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
Arrays.asList("-javaagent:my-agent.jar")); Arrays.asList("-javaagent:my-agent.jar"));
assertTrue(detector.isJavaAgentJar( assertThat(detector.isJavaAgentJar(
new File("my-agent.jar").getCanonicalFile().toURI().toURL())); new File("my-agent.jar").getCanonicalFile().toURI().toURL())).isTrue();
} }
@Test @Test
public void singleJavaAgentWithOptions() throws MalformedURLException, IOException { public void singleJavaAgentWithOptions() throws MalformedURLException, IOException {
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector( InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
Arrays.asList("-javaagent:my-agent.jar=a=alpha,b=bravo")); Arrays.asList("-javaagent:my-agent.jar=a=alpha,b=bravo"));
assertTrue(detector.isJavaAgentJar( assertThat(detector.isJavaAgentJar(
new File("my-agent.jar").getCanonicalFile().toURI().toURL())); new File("my-agent.jar").getCanonicalFile().toURI().toURL())).isTrue();
} }
@Test @Test
...@@ -63,10 +63,11 @@ public class InputArgumentsJavaAgentDetectorTests { ...@@ -63,10 +63,11 @@ public class InputArgumentsJavaAgentDetectorTests {
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector( InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
Arrays.asList("-javaagent:my-agent.jar", Arrays.asList("-javaagent:my-agent.jar",
"-javaagent:my-other-agent.jar")); "-javaagent:my-other-agent.jar"));
assertTrue(detector.isJavaAgentJar( assertThat(detector.isJavaAgentJar(
new File("my-agent.jar").getCanonicalFile().toURI().toURL())); new File("my-agent.jar").getCanonicalFile().toURI().toURL())).isTrue();
assertTrue(detector.isJavaAgentJar( assertThat(detector.isJavaAgentJar(
new File("my-other-agent.jar").getCanonicalFile().toURI().toURL())); new File("my-other-agent.jar").getCanonicalFile().toURI().toURL()))
.isTrue();
} }
} }
...@@ -25,11 +25,7 @@ import org.junit.rules.TemporaryFolder; ...@@ -25,11 +25,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.jar.JarFile; import org.springframework.boot.loader.jar.JarFile;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link LaunchedURLClassLoader}. * Tests for {@link LaunchedURLClassLoader}.
...@@ -47,13 +43,13 @@ public class LaunchedURLClassLoaderTests { ...@@ -47,13 +43,13 @@ public class LaunchedURLClassLoaderTests {
public void resolveResourceFromWindowsFilesystem() throws Exception { public void resolveResourceFromWindowsFilesystem() throws Exception {
// This path is invalid - it should return null even on Windows. // This path is invalid - it should return null even on Windows.
// A regular URLClassLoader will deal with it gracefully. // A regular URLClassLoader will deal with it gracefully.
assertNull(getClass().getClassLoader() assertThat(getClass().getClassLoader()
.getResource("c:\\Users\\user\\bar.properties")); .getResource("c:\\Users\\user\\bar.properties")).isNull();
LaunchedURLClassLoader loader = new LaunchedURLClassLoader( LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
getClass().getClassLoader()); getClass().getClassLoader());
// So we should too... // So we should too...
assertNull(loader.getResource("c:\\Users\\user\\bar.properties")); assertThat(loader.getResource("c:\\Users\\user\\bar.properties")).isNull();
} }
@Test @Test
...@@ -61,7 +57,7 @@ public class LaunchedURLClassLoaderTests { ...@@ -61,7 +57,7 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader loader = new LaunchedURLClassLoader( LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
getClass().getClassLoader()); getClass().getClassLoader());
assertNotNull(loader.getResource("demo/Application.java")); assertThat(loader.getResource("demo/Application.java")).isNotNull();
} }
@Test @Test
...@@ -69,7 +65,8 @@ public class LaunchedURLClassLoaderTests { ...@@ -69,7 +65,8 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader loader = new LaunchedURLClassLoader( LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
getClass().getClassLoader()); getClass().getClassLoader());
assertTrue(loader.getResources("demo/Application.java").hasMoreElements()); assertThat(loader.getResources("demo/Application.java").hasMoreElements())
.isTrue();
} }
@Test @Test
...@@ -77,7 +74,7 @@ public class LaunchedURLClassLoaderTests { ...@@ -77,7 +74,7 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader loader = new LaunchedURLClassLoader( LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
getClass().getClassLoader()); getClass().getClassLoader());
assertNotNull(loader.getResource("")); assertThat(loader.getResource("")).isNotNull();
} }
@Test @Test
...@@ -85,7 +82,7 @@ public class LaunchedURLClassLoaderTests { ...@@ -85,7 +82,7 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader loader = new LaunchedURLClassLoader( LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
getClass().getClassLoader()); getClass().getClassLoader());
assertTrue(loader.getResources("").hasMoreElements()); assertThat(loader.getResources("").hasMoreElements()).isTrue();
} }
@Test @Test
...@@ -97,8 +94,8 @@ public class LaunchedURLClassLoaderTests { ...@@ -97,8 +94,8 @@ public class LaunchedURLClassLoaderTests {
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url },
null); null);
URL resource = loader.getResource("nested.jar!/3.dat"); URL resource = loader.getResource("nested.jar!/3.dat");
assertThat(resource.toString(), equalTo(url + "nested.jar!/3.dat")); assertThat(resource.toString()).isEqualTo(url + "nested.jar!/3.dat");
assertThat(resource.openConnection().getInputStream().read(), equalTo(3)); assertThat(resource.openConnection().getInputStream().read()).isEqualTo(3);
} }
} }
...@@ -34,13 +34,7 @@ import org.mockito.MockitoAnnotations; ...@@ -34,13 +34,7 @@ import org.mockito.MockitoAnnotations;
import org.springframework.boot.loader.archive.Archive; import org.springframework.boot.loader.archive.Archive;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
...@@ -78,31 +72,32 @@ public class PropertiesLauncherTests { ...@@ -78,31 +72,32 @@ public class PropertiesLauncherTests {
@Test @Test
public void testDefaultHome() { public void testDefaultHome() {
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals(new File(System.getProperty("loader.home")), assertThat(launcher.getHomeDirectory())
launcher.getHomeDirectory()); .isEqualTo(new File(System.getProperty("loader.home")));
} }
@Test @Test
public void testUserSpecifiedMain() throws Exception { public void testUserSpecifiedMain() throws Exception {
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("demo.Application", launcher.getMainClass()); assertThat(launcher.getMainClass()).isEqualTo("demo.Application");
assertNull(System.getProperty("loader.main")); assertThat(System.getProperty("loader.main")).isNull();
} }
@Test @Test
public void testUserSpecifiedConfigName() throws Exception { public void testUserSpecifiedConfigName() throws Exception {
System.setProperty("loader.config.name", "foo"); System.setProperty("loader.config.name", "foo");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("my.Application", launcher.getMainClass()); assertThat(launcher.getMainClass()).isEqualTo("my.Application");
assertEquals("[etc/]", assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
ReflectionTestUtils.getField(launcher, "paths").toString()); .isEqualTo("[etc/]");
} }
@Test @Test
public void testUserSpecifiedDotPath() throws Exception { public void testUserSpecifiedDotPath() throws Exception {
System.setProperty("loader.path", "."); System.setProperty("loader.path", ".");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[.]", ReflectionTestUtils.getField(launcher, "paths").toString()); assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
.isEqualTo("[.]");
} }
@Test @Test
...@@ -110,8 +105,8 @@ public class PropertiesLauncherTests { ...@@ -110,8 +105,8 @@ public class PropertiesLauncherTests {
System.setProperty("loader.path", "jars/*"); System.setProperty("loader.path", "jars/*");
System.setProperty("loader.main", "demo.Application"); System.setProperty("loader.main", "demo.Application");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[jars/]", assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
ReflectionTestUtils.getField(launcher, "paths").toString()); .isEqualTo("[jars/]");
launcher.launch(new String[0]); launcher.launch(new String[0]);
waitFor("Hello World"); waitFor("Hello World");
} }
...@@ -121,8 +116,8 @@ public class PropertiesLauncherTests { ...@@ -121,8 +116,8 @@ public class PropertiesLauncherTests {
System.setProperty("loader.path", "jars/app.jar"); System.setProperty("loader.path", "jars/app.jar");
System.setProperty("loader.main", "demo.Application"); System.setProperty("loader.main", "demo.Application");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[jars/app.jar]", assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
ReflectionTestUtils.getField(launcher, "paths").toString()); .isEqualTo("[jars/app.jar]");
launcher.launch(new String[0]); launcher.launch(new String[0]);
waitFor("Hello World"); waitFor("Hello World");
} }
...@@ -132,8 +127,8 @@ public class PropertiesLauncherTests { ...@@ -132,8 +127,8 @@ public class PropertiesLauncherTests {
System.setProperty("loader.path", "./jars/app.jar"); System.setProperty("loader.path", "./jars/app.jar");
System.setProperty("loader.main", "demo.Application"); System.setProperty("loader.main", "demo.Application");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[jars/app.jar]", assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
ReflectionTestUtils.getField(launcher, "paths").toString()); .isEqualTo("[jars/app.jar]");
launcher.launch(new String[0]); launcher.launch(new String[0]);
waitFor("Hello World"); waitFor("Hello World");
} }
...@@ -143,8 +138,8 @@ public class PropertiesLauncherTests { ...@@ -143,8 +138,8 @@ public class PropertiesLauncherTests {
System.setProperty("loader.path", "jars/app.jar"); System.setProperty("loader.path", "jars/app.jar");
System.setProperty("loader.classLoader", URLClassLoader.class.getName()); System.setProperty("loader.classLoader", URLClassLoader.class.getName());
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[jars/app.jar]", assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
ReflectionTestUtils.getField(launcher, "paths").toString()); .isEqualTo("[jars/app.jar]");
launcher.launch(new String[0]); launcher.launch(new String[0]);
waitFor("Hello World"); waitFor("Hello World");
} }
...@@ -154,8 +149,8 @@ public class PropertiesLauncherTests { ...@@ -154,8 +149,8 @@ public class PropertiesLauncherTests {
System.setProperty("loader.path", "more-jars/app.jar,jars/app.jar"); System.setProperty("loader.path", "more-jars/app.jar,jars/app.jar");
System.setProperty("loader.classLoader", URLClassLoader.class.getName()); System.setProperty("loader.classLoader", URLClassLoader.class.getName());
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[more-jars/app.jar, jars/app.jar]", assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
ReflectionTestUtils.getField(launcher, "paths").toString()); .isEqualTo("[more-jars/app.jar, jars/app.jar]");
launcher.launch(new String[0]); launcher.launch(new String[0]);
waitFor("Hello Other World"); waitFor("Hello Other World");
} }
...@@ -165,8 +160,8 @@ public class PropertiesLauncherTests { ...@@ -165,8 +160,8 @@ public class PropertiesLauncherTests {
System.setProperty("loader.classLoader", TestLoader.class.getName()); System.setProperty("loader.classLoader", TestLoader.class.getName());
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
ClassLoader loader = launcher.createClassLoader(Collections.<Archive>emptyList()); ClassLoader loader = launcher.createClassLoader(Collections.<Archive>emptyList());
assertNotNull(loader); assertThat(loader).isNotNull();
assertEquals(TestLoader.class.getName(), loader.getClass().getName()); assertThat(loader.getClass().getName()).isEqualTo(TestLoader.class.getName());
} }
@Test @Test
...@@ -175,28 +170,29 @@ public class PropertiesLauncherTests { ...@@ -175,28 +170,29 @@ public class PropertiesLauncherTests {
System.setProperty("loader.config.name", "foo"); System.setProperty("loader.config.name", "foo");
System.setProperty("loader.config.location", "classpath:bar.properties"); System.setProperty("loader.config.location", "classpath:bar.properties");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("my.BarApplication", launcher.getMainClass()); assertThat(launcher.getMainClass()).isEqualTo("my.BarApplication");
} }
@Test @Test
public void testSystemPropertySpecifiedMain() throws Exception { public void testSystemPropertySpecifiedMain() throws Exception {
System.setProperty("loader.main", "foo.Bar"); System.setProperty("loader.main", "foo.Bar");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("foo.Bar", launcher.getMainClass()); assertThat(launcher.getMainClass()).isEqualTo("foo.Bar");
} }
@Test @Test
public void testSystemPropertiesSet() throws Exception { public void testSystemPropertiesSet() throws Exception {
System.setProperty("loader.system", "true"); System.setProperty("loader.system", "true");
new PropertiesLauncher(); new PropertiesLauncher();
assertEquals("demo.Application", System.getProperty("loader.main")); assertThat(System.getProperty("loader.main")).isEqualTo("demo.Application");
} }
@Test @Test
public void testArgsEnhanced() throws Exception { public void testArgsEnhanced() throws Exception {
System.setProperty("loader.args", "foo"); System.setProperty("loader.args", "foo");
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("[foo, bar]", Arrays.asList(launcher.getArgs("bar")).toString()); assertThat(Arrays.asList(launcher.getArgs("bar")).toString())
.isEqualTo("[foo, bar]");
} }
@Test @Test
...@@ -208,8 +204,7 @@ public class PropertiesLauncherTests { ...@@ -208,8 +204,7 @@ public class PropertiesLauncherTests {
} }
List<Archive> nonAgentArchives = new PropertiesLauncher(this.javaAgentDetector) List<Archive> nonAgentArchives = new PropertiesLauncher(this.javaAgentDetector)
.getClassPathArchives(); .getClassPathArchives();
assertThat(nonAgentArchives.size(), assertThat(nonAgentArchives).hasSize(allArchives.size() - parentUrls.length);
is(equalTo(allArchives.size() - parentUrls.length)));
for (URL url : parentUrls) { for (URL url : parentUrls) {
verify(this.javaAgentDetector).isJavaAgentJar(url); verify(this.javaAgentDetector).isJavaAgentJar(url);
} }
...@@ -223,7 +218,7 @@ public class PropertiesLauncherTests { ...@@ -223,7 +218,7 @@ public class PropertiesLauncherTests {
Thread.sleep(50L); Thread.sleep(50L);
timeout = this.output.toString().contains(value); timeout = this.output.toString().contains(value);
} }
assertTrue("Timed out waiting for (" + value + ")", timeout); assertThat(timeout).as("Timed out waiting for (" + value + ")").isTrue();
} }
public static class TestLoader extends URLClassLoader { public static class TestLoader extends URLClassLoader {
......
...@@ -38,9 +38,7 @@ import org.springframework.boot.loader.archive.ExplodedArchive; ...@@ -38,9 +38,7 @@ import org.springframework.boot.loader.archive.ExplodedArchive;
import org.springframework.boot.loader.archive.JarFileArchive; import org.springframework.boot.loader.archive.JarFileArchive;
import org.springframework.util.FileSystemUtils; import org.springframework.util.FileSystemUtils;
import static org.hamcrest.Matchers.hasItems; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link WarLauncher} * Tests for {@link WarLauncher}
...@@ -61,28 +59,23 @@ public class WarLauncherTests { ...@@ -61,28 +59,23 @@ public class WarLauncherTests {
webInfLib.mkdirs(); webInfLib.mkdirs();
File webInfLibFoo = new File(webInfLib, "foo.jar"); File webInfLibFoo = new File(webInfLib, "foo.jar");
new JarOutputStream(new FileOutputStream(webInfLibFoo)).close(); new JarOutputStream(new FileOutputStream(webInfLibFoo)).close();
WarLauncher launcher = new WarLauncher(new ExplodedArchive(warRoot, true)); WarLauncher launcher = new WarLauncher(new ExplodedArchive(warRoot, true));
List<Archive> archives = launcher.getClassPathArchives(); List<Archive> archives = launcher.getClassPathArchives();
assertEquals(2, archives.size()); assertThat(archives).hasSize(2);
assertThat(getUrls(archives)).containsOnly(webInfClasses.toURI().toURL(),
assertThat(getUrls(archives), hasItems(webInfClasses.toURI().toURL(), new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/"));
new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/")));
} }
@Test @Test
public void archivedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath() public void archivedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath()
throws Exception { throws Exception {
File warRoot = createWarArchive(); File warRoot = createWarArchive();
WarLauncher launcher = new WarLauncher(new JarFileArchive(warRoot)); WarLauncher launcher = new WarLauncher(new JarFileArchive(warRoot));
List<Archive> archives = launcher.getClassPathArchives(); List<Archive> archives = launcher.getClassPathArchives();
assertEquals(2, archives.size()); assertThat(archives).hasSize(2);
assertThat(getUrls(archives)).containsOnly(
assertThat(getUrls(archives), new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/classes!/"),
hasItems(new URL("jar:" + warRoot.toURI().toURL() new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/"));
+ "!/WEB-INF/classes!/"),
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/")));
} }
private Set<URL> getUrls(List<Archive> archives) throws MalformedURLException { private Set<URL> getUrls(List<Archive> archives) throws MalformedURLException {
...@@ -96,14 +89,11 @@ public class WarLauncherTests { ...@@ -96,14 +89,11 @@ public class WarLauncherTests {
private File createWarArchive() throws IOException, FileNotFoundException { private File createWarArchive() throws IOException, FileNotFoundException {
File warRoot = new File("target/archive.war"); File warRoot = new File("target/archive.war");
warRoot.delete(); warRoot.delete();
JarOutputStream jarOutputStream = new JarOutputStream( JarOutputStream jarOutputStream = new JarOutputStream(
new FileOutputStream(warRoot)); new FileOutputStream(warRoot));
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/")); jarOutputStream.putNextEntry(new JarEntry("WEB-INF/"));
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/classes/")); jarOutputStream.putNextEntry(new JarEntry("WEB-INF/classes/"));
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/lib/")); jarOutputStream.putNextEntry(new JarEntry("WEB-INF/lib/"));
JarEntry webInfLibFoo = new JarEntry("WEB-INF/lib/foo.jar"); JarEntry webInfLibFoo = new JarEntry("WEB-INF/lib/foo.jar");
webInfLibFoo.setMethod(ZipEntry.STORED); webInfLibFoo.setMethod(ZipEntry.STORED);
ByteArrayOutputStream fooJarStream = new ByteArrayOutputStream(); ByteArrayOutputStream fooJarStream = new ByteArrayOutputStream();
...@@ -114,7 +104,6 @@ public class WarLauncherTests { ...@@ -114,7 +104,6 @@ public class WarLauncherTests {
webInfLibFoo.setCrc(crc32.getValue()); webInfLibFoo.setCrc(crc32.getValue());
jarOutputStream.putNextEntry(webInfLibFoo); jarOutputStream.putNextEntry(webInfLibFoo);
jarOutputStream.write(fooJarStream.toByteArray()); jarOutputStream.write(fooJarStream.toByteArray());
jarOutputStream.close(); jarOutputStream.close();
return warRoot; return warRoot;
} }
......
...@@ -38,10 +38,7 @@ import org.junit.rules.TemporaryFolder; ...@@ -38,10 +38,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.TestJarCreator; import org.springframework.boot.loader.TestJarCreator;
import org.springframework.boot.loader.archive.Archive.Entry; import org.springframework.boot.loader.archive.Archive.Entry;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link ExplodedArchive}. * Tests for {@link ExplodedArchive}.
...@@ -93,29 +90,29 @@ public class ExplodedArchiveTests { ...@@ -93,29 +90,29 @@ public class ExplodedArchiveTests {
@Test @Test
public void getManifest() throws Exception { public void getManifest() throws Exception {
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"), assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"))
equalTo("j1")); .isEqualTo("j1");
} }
@Test @Test
public void getEntries() throws Exception { public void getEntries() throws Exception {
Map<String, Archive.Entry> entries = getEntriesMap(this.archive); Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
assertThat(entries.size(), equalTo(10)); assertThat(entries.size()).isEqualTo(10);
} }
@Test @Test
public void getUrl() throws Exception { public void getUrl() throws Exception {
URL url = this.archive.getUrl(); URL url = this.archive.getUrl();
assertThat(new File(URLDecoder.decode(url.getFile(), "UTF-8")), assertThat(new File(URLDecoder.decode(url.getFile(), "UTF-8")))
equalTo(this.rootFolder)); .isEqualTo(this.rootFolder);
} }
@Test @Test
public void getNestedArchive() throws Exception { public void getNestedArchive() throws Exception {
Entry entry = getEntriesMap(this.archive).get("nested.jar"); Entry entry = getEntriesMap(this.archive).get("nested.jar");
Archive nested = this.archive.getNestedArchive(entry); Archive nested = this.archive.getNestedArchive(entry);
assertThat(nested.getUrl().toString(), assertThat(nested.getUrl().toString())
equalTo("jar:" + this.rootFolder.toURI() + "nested.jar!/")); .isEqualTo("jar:" + this.rootFolder.toURI() + "nested.jar!/");
} }
@Test @Test
...@@ -123,43 +120,44 @@ public class ExplodedArchiveTests { ...@@ -123,43 +120,44 @@ public class ExplodedArchiveTests {
Entry entry = getEntriesMap(this.archive).get("d/"); Entry entry = getEntriesMap(this.archive).get("d/");
Archive nested = this.archive.getNestedArchive(entry); Archive nested = this.archive.getNestedArchive(entry);
Map<String, Entry> nestedEntries = getEntriesMap(nested); Map<String, Entry> nestedEntries = getEntriesMap(nested);
assertThat(nestedEntries.size(), equalTo(1)); assertThat(nestedEntries.size()).isEqualTo(1);
assertThat(nested.getUrl().toString(), assertThat(nested.getUrl().toString())
equalTo("file:" + this.rootFolder.toURI().getPath() + "d/")); .isEqualTo("file:" + this.rootFolder.toURI().getPath() + "d/");
} }
@Test @Test
public void getNonRecursiveEntriesForRoot() throws Exception { public void getNonRecursiveEntriesForRoot() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("/"), false); ExplodedArchive archive = new ExplodedArchive(new File("/"), false);
Map<String, Archive.Entry> entries = getEntriesMap(archive); Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), greaterThan(1)); assertThat(entries.size()).isGreaterThan(1);
} }
@Test @Test
public void getNonRecursiveManifest() throws Exception { public void getNonRecursiveManifest() throws Exception {
ExplodedArchive archive = new ExplodedArchive( ExplodedArchive archive = new ExplodedArchive(
new File("src/test/resources/root")); new File("src/test/resources/root"));
assertNotNull(archive.getManifest()); assertThat(archive.getManifest()).isNotNull();
Map<String, Archive.Entry> entries = getEntriesMap(archive); Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), equalTo(4)); assertThat(entries.size()).isEqualTo(4);
} }
@Test @Test
public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception { public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"), ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
false); false);
assertNotNull(archive.getManifest()); assertThat(archive.getManifest()).isNotNull();
Map<String, Archive.Entry> entries = getEntriesMap(archive); Map<String, Archive.Entry> entries = getEntriesMap(archive);
assertThat(entries.size(), equalTo(3)); assertThat(entries.size()).isEqualTo(3);
} }
@Test @Test
public void getResourceAsStream() throws Exception { public void getResourceAsStream() throws Exception {
ExplodedArchive archive = new ExplodedArchive( ExplodedArchive archive = new ExplodedArchive(
new File("src/test/resources/root")); new File("src/test/resources/root"));
assertNotNull(archive.getManifest()); assertThat(archive.getManifest()).isNotNull();
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() }); URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml")); assertThat(loader.getResourceAsStream("META-INF/spring/application.xml"))
.isNotNull();
loader.close(); loader.close();
} }
...@@ -167,9 +165,10 @@ public class ExplodedArchiveTests { ...@@ -167,9 +165,10 @@ public class ExplodedArchiveTests {
public void getResourceAsStreamNonRecursive() throws Exception { public void getResourceAsStreamNonRecursive() throws Exception {
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"), ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
false); false);
assertNotNull(archive.getManifest()); assertThat(archive.getManifest()).isNotNull();
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() }); URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml")); assertThat(loader.getResourceAsStream("META-INF/spring/application.xml"))
.isNotNull();
loader.close(); loader.close();
} }
...@@ -180,4 +179,5 @@ public class ExplodedArchiveTests { ...@@ -180,4 +179,5 @@ public class ExplodedArchiveTests {
} }
return entries; return entries;
} }
} }
...@@ -29,12 +29,7 @@ import org.junit.rules.TemporaryFolder; ...@@ -29,12 +29,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.TestJarCreator; import org.springframework.boot.loader.TestJarCreator;
import org.springframework.boot.loader.archive.Archive.Entry; import org.springframework.boot.loader.archive.Archive.Entry;
import static org.hamcrest.Matchers.endsWith; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link JarFileArchive}. * Tests for {@link JarFileArchive}.
...@@ -67,28 +62,28 @@ public class JarFileArchiveTests { ...@@ -67,28 +62,28 @@ public class JarFileArchiveTests {
@Test @Test
public void getManifest() throws Exception { public void getManifest() throws Exception {
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"), assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"))
equalTo("j1")); .isEqualTo("j1");
} }
@Test @Test
public void getEntries() throws Exception { public void getEntries() throws Exception {
Map<String, Archive.Entry> entries = getEntriesMap(this.archive); Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
assertThat(entries.size(), equalTo(10)); assertThat(entries.size()).isEqualTo(10);
} }
@Test @Test
public void getUrl() throws Exception { public void getUrl() throws Exception {
URL url = this.archive.getUrl(); URL url = this.archive.getUrl();
assertThat(url.toString(), equalTo("jar:" + this.rootJarFileUrl + "!/")); assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFileUrl + "!/");
} }
@Test @Test
public void getNestedArchive() throws Exception { public void getNestedArchive() throws Exception {
Entry entry = getEntriesMap(this.archive).get("nested.jar"); Entry entry = getEntriesMap(this.archive).get("nested.jar");
Archive nested = this.archive.getNestedArchive(entry); Archive nested = this.archive.getNestedArchive(entry);
assertThat(nested.getUrl().toString(), assertThat(nested.getUrl().toString())
equalTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/")); .isEqualTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/");
} }
@Test @Test
...@@ -96,8 +91,8 @@ public class JarFileArchiveTests { ...@@ -96,8 +91,8 @@ public class JarFileArchiveTests {
setup(true); setup(true);
Entry entry = getEntriesMap(this.archive).get("nested.jar"); Entry entry = getEntriesMap(this.archive).get("nested.jar");
Archive nested = this.archive.getNestedArchive(entry); Archive nested = this.archive.getNestedArchive(entry);
assertThat(nested.getUrl().toString(), startsWith("file:")); assertThat(nested.getUrl().toString()).startsWith("file:");
assertThat(nested.getUrl().toString(), endsWith("/nested.jar")); assertThat(nested.getUrl().toString()).endsWith("/nested.jar");
} }
@Test @Test
...@@ -108,7 +103,7 @@ public class JarFileArchiveTests { ...@@ -108,7 +103,7 @@ public class JarFileArchiveTests {
setup(true); setup(true);
entry = getEntriesMap(this.archive).get("nested.jar"); entry = getEntriesMap(this.archive).get("nested.jar");
URL secondNested = this.archive.getNestedArchive(entry).getUrl(); URL secondNested = this.archive.getNestedArchive(entry).getUrl();
assertThat(secondNested, is(not(equalTo(firstNested)))); assertThat(secondNested).isNotEqualTo(firstNested);
} }
@Test @Test
...@@ -122,7 +117,7 @@ public class JarFileArchiveTests { ...@@ -122,7 +117,7 @@ public class JarFileArchiveTests {
.getNestedArchive( .getNestedArchive(
getEntriesMap(this.archive).get("another-nested.jar")) getEntriesMap(this.archive).get("another-nested.jar"))
.getUrl().toURI()); .getUrl().toURI());
assertThat(nested.getParent(), is(equalTo(anotherNested.getParent()))); assertThat(nested.getParent()).isEqualTo(anotherNested.getParent());
} }
private Map<String, Archive.Entry> getEntriesMap(Archive archive) { private Map<String, Archive.Entry> getEntriesMap(Archive archive) {
...@@ -132,4 +127,5 @@ public class JarFileArchiveTests { ...@@ -132,4 +127,5 @@ public class JarFileArchiveTests {
} }
return entries; return entries;
} }
} }
...@@ -16,13 +16,14 @@ ...@@ -16,13 +16,14 @@
package org.springframework.boot.loader.data; package org.springframework.boot.loader.data;
import java.io.InputStream;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess; import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link ByteArrayRandomAccessData}. * Tests for {@link ByteArrayRandomAccessData}.
...@@ -35,9 +36,9 @@ public class ByteArrayRandomAccessDataTests { ...@@ -35,9 +36,9 @@ public class ByteArrayRandomAccessDataTests {
public void testGetInputStream() throws Exception { public void testGetInputStream() throws Exception {
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 }; byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
RandomAccessData data = new ByteArrayRandomAccessData(bytes); RandomAccessData data = new ByteArrayRandomAccessData(bytes);
assertThat(FileCopyUtils.copyToByteArray( InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
data.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes)); assertThat(FileCopyUtils.copyToByteArray(inputStream)).isEqualTo(bytes);
assertThat(data.getSize(), equalTo((long) bytes.length)); assertThat(data.getSize()).isEqualTo(bytes.length);
} }
@Test @Test
...@@ -45,10 +46,10 @@ public class ByteArrayRandomAccessDataTests { ...@@ -45,10 +46,10 @@ public class ByteArrayRandomAccessDataTests {
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 }; byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
RandomAccessData data = new ByteArrayRandomAccessData(bytes); RandomAccessData data = new ByteArrayRandomAccessData(bytes);
data = data.getSubsection(1, 4).getSubsection(1, 2); data = data.getSubsection(1, 4).getSubsection(1, 2);
assertThat( InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
FileCopyUtils assertThat(FileCopyUtils.copyToByteArray(inputStream))
.copyToByteArray(data.getInputStream(ResourceAccess.PER_READ)), .isEqualTo(new byte[] { 2, 3 });
equalTo(new byte[] { 2, 3 })); assertThat(data.getSize()).isEqualTo(2L);
assertThat(data.getSize(), equalTo(2L));
} }
} }
...@@ -29,7 +29,6 @@ import java.util.concurrent.ExecutorService; ...@@ -29,7 +29,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.hamcrest.Matcher;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -37,11 +36,9 @@ import org.junit.Test; ...@@ -37,11 +36,9 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.ByteArrayStartsWith;
import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess; import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link RandomAccessDataFile}. * Tests for {@link RandomAccessDataFile}.
...@@ -118,7 +115,7 @@ public class RandomAccessDataFileTests { ...@@ -118,7 +115,7 @@ public class RandomAccessDataFileTests {
@Test @Test
public void inputStreamRead() throws Exception { public void inputStreamRead() throws Exception {
for (int i = 0; i <= 255; i++) { for (int i = 0; i <= 255; i++) {
assertThat(this.inputStream.read(), equalTo(i)); assertThat(this.inputStream.read()).isEqualTo(i);
} }
} }
...@@ -140,8 +137,8 @@ public class RandomAccessDataFileTests { ...@@ -140,8 +137,8 @@ public class RandomAccessDataFileTests {
public void inputStreamReadBytes() throws Exception { public void inputStreamReadBytes() throws Exception {
byte[] b = new byte[256]; byte[] b = new byte[256];
int amountRead = this.inputStream.read(b); int amountRead = this.inputStream.read(b);
assertThat(b, equalTo(BYTES)); assertThat(b).isEqualTo(BYTES);
assertThat(amountRead, equalTo(256)); assertThat(amountRead).isEqualTo(256);
} }
@Test @Test
...@@ -149,54 +146,54 @@ public class RandomAccessDataFileTests { ...@@ -149,54 +146,54 @@ public class RandomAccessDataFileTests {
byte[] b = new byte[7]; byte[] b = new byte[7];
this.inputStream.skip(1); this.inputStream.skip(1);
int amountRead = this.inputStream.read(b, 2, 3); int amountRead = this.inputStream.read(b, 2, 3);
assertThat(b, equalTo(new byte[] { 0, 0, 1, 2, 3, 0, 0 })); assertThat(b).isEqualTo(new byte[] { 0, 0, 1, 2, 3, 0, 0 });
assertThat(amountRead, equalTo(3)); assertThat(amountRead).isEqualTo(3);
} }
@Test @Test
public void inputStreamReadMoreBytesThanAvailable() throws Exception { public void inputStreamReadMoreBytesThanAvailable() throws Exception {
byte[] b = new byte[257]; byte[] b = new byte[257];
int amountRead = this.inputStream.read(b); int amountRead = this.inputStream.read(b);
assertThat(b, startsWith(BYTES)); assertThat(b).startsWith(BYTES);
assertThat(amountRead, equalTo(256)); assertThat(amountRead).isEqualTo(256);
} }
@Test @Test
public void inputStreamReadPastEnd() throws Exception { public void inputStreamReadPastEnd() throws Exception {
this.inputStream.skip(255); this.inputStream.skip(255);
assertThat(this.inputStream.read(), equalTo(0xFF)); assertThat(this.inputStream.read()).isEqualTo(0xFF);
assertThat(this.inputStream.read(), equalTo(-1)); assertThat(this.inputStream.read()).isEqualTo(-1);
assertThat(this.inputStream.read(), equalTo(-1)); assertThat(this.inputStream.read()).isEqualTo(-1);
} }
@Test @Test
public void inputStreamReadZeroLength() throws Exception { public void inputStreamReadZeroLength() throws Exception {
byte[] b = new byte[] { 0x0F }; byte[] b = new byte[] { 0x0F };
int amountRead = this.inputStream.read(b, 0, 0); int amountRead = this.inputStream.read(b, 0, 0);
assertThat(b, equalTo(new byte[] { 0x0F })); assertThat(b).isEqualTo(new byte[] { 0x0F });
assertThat(amountRead, equalTo(0)); assertThat(amountRead).isEqualTo(0);
assertThat(this.inputStream.read(), equalTo(0)); assertThat(this.inputStream.read()).isEqualTo(0);
} }
@Test @Test
public void inputStreamSkip() throws Exception { public void inputStreamSkip() throws Exception {
long amountSkipped = this.inputStream.skip(4); long amountSkipped = this.inputStream.skip(4);
assertThat(this.inputStream.read(), equalTo(4)); assertThat(this.inputStream.read()).isEqualTo(4);
assertThat(amountSkipped, equalTo(4L)); assertThat(amountSkipped).isEqualTo(4L);
} }
@Test @Test
public void inputStreamSkipMoreThanAvailable() throws Exception { public void inputStreamSkipMoreThanAvailable() throws Exception {
long amountSkipped = this.inputStream.skip(257); long amountSkipped = this.inputStream.skip(257);
assertThat(this.inputStream.read(), equalTo(-1)); assertThat(this.inputStream.read()).isEqualTo(-1);
assertThat(amountSkipped, equalTo(256L)); assertThat(amountSkipped).isEqualTo(256L);
} }
@Test @Test
public void inputStreamSkipPastEnd() throws Exception { public void inputStreamSkipPastEnd() throws Exception {
this.inputStream.skip(256); this.inputStream.skip(256);
long amountSkipped = this.inputStream.skip(1); long amountSkipped = this.inputStream.skip(1);
assertThat(amountSkipped, equalTo(0L)); assertThat(amountSkipped).isEqualTo(0L);
} }
@Test @Test
...@@ -214,8 +211,8 @@ public class RandomAccessDataFileTests { ...@@ -214,8 +211,8 @@ public class RandomAccessDataFileTests {
@Test @Test
public void subsectionZeroLength() throws Exception { public void subsectionZeroLength() throws Exception {
RandomAccessData subsection = this.file.getSubsection(0, 0); RandomAccessData subsection = this.file.getSubsection(0, 0);
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(), assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read())
equalTo(-1)); .isEqualTo(-1);
} }
@Test @Test
...@@ -235,16 +232,17 @@ public class RandomAccessDataFileTests { ...@@ -235,16 +232,17 @@ public class RandomAccessDataFileTests {
@Test @Test
public void subsection() throws Exception { public void subsection() throws Exception {
RandomAccessData subsection = this.file.getSubsection(1, 1); RandomAccessData subsection = this.file.getSubsection(1, 1);
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(), equalTo(1)); assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read())
.isEqualTo(1);
} }
@Test @Test
public void inputStreamReadPastSubsection() throws Exception { public void inputStreamReadPastSubsection() throws Exception {
RandomAccessData subsection = this.file.getSubsection(1, 2); RandomAccessData subsection = this.file.getSubsection(1, 2);
InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ); InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
assertThat(inputStream.read(), equalTo(1)); assertThat(inputStream.read()).isEqualTo(1);
assertThat(inputStream.read(), equalTo(2)); assertThat(inputStream.read()).isEqualTo(2);
assertThat(inputStream.read(), equalTo(-1)); assertThat(inputStream.read()).isEqualTo(-1);
} }
@Test @Test
...@@ -253,26 +251,26 @@ public class RandomAccessDataFileTests { ...@@ -253,26 +251,26 @@ public class RandomAccessDataFileTests {
InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ); InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
byte[] b = new byte[3]; byte[] b = new byte[3];
int amountRead = inputStream.read(b); int amountRead = inputStream.read(b);
assertThat(b, equalTo(new byte[] { 1, 2, 0 })); assertThat(b).isEqualTo(new byte[] { 1, 2, 0 });
assertThat(amountRead, equalTo(2)); assertThat(amountRead).isEqualTo(2);
} }
@Test @Test
public void inputStreamSkipPastSubsection() throws Exception { public void inputStreamSkipPastSubsection() throws Exception {
RandomAccessData subsection = this.file.getSubsection(1, 2); RandomAccessData subsection = this.file.getSubsection(1, 2);
InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ); InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
assertThat(inputStream.skip(3), equalTo(2L)); assertThat(inputStream.skip(3)).isEqualTo(2L);
assertThat(inputStream.read(), equalTo(-1)); assertThat(inputStream.read()).isEqualTo(-1);
} }
@Test @Test
public void inputStreamSkipNegative() throws Exception { public void inputStreamSkipNegative() throws Exception {
assertThat(this.inputStream.skip(-1), equalTo(0L)); assertThat(this.inputStream.skip(-1)).isEqualTo(0L);
} }
@Test @Test
public void getFile() throws Exception { public void getFile() throws Exception {
assertThat(this.file.getFile(), equalTo(this.tempFile)); assertThat(this.file.getFile()).isEqualTo(this.tempFile);
} }
@Test @Test
...@@ -294,7 +292,7 @@ public class RandomAccessDataFileTests { ...@@ -294,7 +292,7 @@ public class RandomAccessDataFileTests {
})); }));
} }
for (Future<Boolean> future : results) { for (Future<Boolean> future : results) {
assertThat(future.get(), equalTo(true)); assertThat(future.get()).isTrue();
} }
} }
...@@ -308,11 +306,7 @@ public class RandomAccessDataFileTests { ...@@ -308,11 +306,7 @@ public class RandomAccessDataFileTests {
Field filesField = filePool.getClass().getDeclaredField("files"); Field filesField = filePool.getClass().getDeclaredField("files");
filesField.setAccessible(true); filesField.setAccessible(true);
Queue<?> queue = (Queue<?>) filesField.get(filePool); Queue<?> queue = (Queue<?>) filesField.get(filePool);
assertThat(queue.size(), equalTo(0)); assertThat(queue.size()).isEqualTo(0);
}
private static Matcher<? super byte[]> startsWith(byte[] bytes) {
return new ByteArrayStartsWith(bytes);
} }
} }
...@@ -20,9 +20,7 @@ import org.junit.Rule; ...@@ -20,9 +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.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link AsciiBytes}. * Tests for {@link AsciiBytes}.
...@@ -37,27 +35,27 @@ public class AsciiBytesTests { ...@@ -37,27 +35,27 @@ public class AsciiBytesTests {
@Test @Test
public void createFromBytes() throws Exception { public void createFromBytes() throws Exception {
AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66 }); AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66 });
assertThat(bytes.toString(), equalTo("AB")); assertThat(bytes.toString()).isEqualTo("AB");
} }
@Test @Test
public void createFromBytesWithOffset() throws Exception { public void createFromBytesWithOffset() throws Exception {
AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2); AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
assertThat(bytes.toString(), equalTo("BC")); assertThat(bytes.toString()).isEqualTo("BC");
} }
@Test @Test
public void createFromString() throws Exception { public void createFromString() throws Exception {
AsciiBytes bytes = new AsciiBytes("AB"); AsciiBytes bytes = new AsciiBytes("AB");
assertThat(bytes.toString(), equalTo("AB")); assertThat(bytes.toString()).isEqualTo("AB");
} }
@Test @Test
public void length() throws Exception { public void length() throws Exception {
AsciiBytes b1 = new AsciiBytes(new byte[] { 65, 66 }); AsciiBytes b1 = new AsciiBytes(new byte[] { 65, 66 });
AsciiBytes b2 = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2); AsciiBytes b2 = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
assertThat(b1.length(), equalTo(2)); assertThat(b1.length()).isEqualTo(2);
assertThat(b2.length(), equalTo(2)); assertThat(b2.length()).isEqualTo(2);
} }
@Test @Test
...@@ -66,10 +64,10 @@ public class AsciiBytesTests { ...@@ -66,10 +64,10 @@ public class AsciiBytesTests {
AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 }); AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 });
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2); AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2);
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 }); AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
assertThat(abc.startsWith(abc), equalTo(true)); assertThat(abc.startsWith(abc)).isTrue();
assertThat(abc.startsWith(ab), equalTo(true)); assertThat(abc.startsWith(ab)).isTrue();
assertThat(abc.startsWith(bc), equalTo(false)); assertThat(abc.startsWith(bc)).isFalse();
assertThat(abc.startsWith(abcd), equalTo(false)); assertThat(abc.startsWith(abcd)).isFalse();
} }
@Test @Test
...@@ -78,20 +76,20 @@ public class AsciiBytesTests { ...@@ -78,20 +76,20 @@ public class AsciiBytesTests {
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2); AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2);
AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 }); AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 });
AsciiBytes aabc = new AsciiBytes(new byte[] { 65, 65, 66, 67 }); AsciiBytes aabc = new AsciiBytes(new byte[] { 65, 65, 66, 67 });
assertThat(abc.endsWith(abc), equalTo(true)); assertThat(abc.endsWith(abc)).isTrue();
assertThat(abc.endsWith(bc), equalTo(true)); assertThat(abc.endsWith(bc)).isTrue();
assertThat(abc.endsWith(ab), equalTo(false)); assertThat(abc.endsWith(ab)).isFalse();
assertThat(abc.endsWith(aabc), equalTo(false)); assertThat(abc.endsWith(aabc)).isFalse();
} }
@Test @Test
public void substringFromBeingIndex() throws Exception { public void substringFromBeingIndex() throws Exception {
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 }); AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
assertThat(abcd.substring(0).toString(), equalTo("ABCD")); assertThat(abcd.substring(0).toString()).isEqualTo("ABCD");
assertThat(abcd.substring(1).toString(), equalTo("BCD")); assertThat(abcd.substring(1).toString()).isEqualTo("BCD");
assertThat(abcd.substring(2).toString(), equalTo("CD")); assertThat(abcd.substring(2).toString()).isEqualTo("CD");
assertThat(abcd.substring(3).toString(), equalTo("D")); assertThat(abcd.substring(3).toString()).isEqualTo("D");
assertThat(abcd.substring(4).toString(), equalTo("")); assertThat(abcd.substring(4).toString()).isEqualTo("");
this.thrown.expect(IndexOutOfBoundsException.class); this.thrown.expect(IndexOutOfBoundsException.class);
abcd.substring(5); abcd.substring(5);
} }
...@@ -99,10 +97,10 @@ public class AsciiBytesTests { ...@@ -99,10 +97,10 @@ public class AsciiBytesTests {
@Test @Test
public void substring() throws Exception { public void substring() throws Exception {
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 }); AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
assertThat(abcd.substring(0, 4).toString(), equalTo("ABCD")); assertThat(abcd.substring(0, 4).toString()).isEqualTo("ABCD");
assertThat(abcd.substring(1, 3).toString(), equalTo("BC")); assertThat(abcd.substring(1, 3).toString()).isEqualTo("BC");
assertThat(abcd.substring(3, 4).toString(), equalTo("D")); assertThat(abcd.substring(3, 4).toString()).isEqualTo("D");
assertThat(abcd.substring(3, 3).toString(), equalTo("")); assertThat(abcd.substring(3, 3).toString()).isEqualTo("");
this.thrown.expect(IndexOutOfBoundsException.class); this.thrown.expect(IndexOutOfBoundsException.class);
abcd.substring(3, 5); abcd.substring(3, 5);
} }
...@@ -111,16 +109,16 @@ public class AsciiBytesTests { ...@@ -111,16 +109,16 @@ public class AsciiBytesTests {
public void appendString() throws Exception { public void appendString() throws Exception {
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2); AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
AsciiBytes appended = bc.append("D"); AsciiBytes appended = bc.append("D");
assertThat(bc.toString(), equalTo("BC")); assertThat(bc.toString()).isEqualTo("BC");
assertThat(appended.toString(), equalTo("BCD")); assertThat(appended.toString()).isEqualTo("BCD");
} }
@Test @Test
public void appendBytes() throws Exception { public void appendBytes() throws Exception {
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2); AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
AsciiBytes appended = bc.append(new byte[] { 68 }); AsciiBytes appended = bc.append(new byte[] { 68 });
assertThat(bc.toString(), equalTo("BC")); assertThat(bc.toString()).isEqualTo("BC");
assertThat(appended.toString(), equalTo("BCD")); assertThat(appended.toString()).isEqualTo("BCD");
} }
@Test @Test
...@@ -130,28 +128,28 @@ public class AsciiBytesTests { ...@@ -130,28 +128,28 @@ public class AsciiBytesTests {
AsciiBytes bc_substring = new AsciiBytes(new byte[] { 65, 66, 67, 68 }) AsciiBytes bc_substring = new AsciiBytes(new byte[] { 65, 66, 67, 68 })
.substring(1, 3); .substring(1, 3);
AsciiBytes bc_string = new AsciiBytes("BC"); AsciiBytes bc_string = new AsciiBytes("BC");
assertThat(bc.hashCode(), equalTo(bc.hashCode())); assertThat(bc.hashCode()).isEqualTo(bc.hashCode());
assertThat(bc.hashCode(), equalTo(bc_substring.hashCode())); assertThat(bc.hashCode()).isEqualTo(bc_substring.hashCode());
assertThat(bc.hashCode(), equalTo(bc_string.hashCode())); assertThat(bc.hashCode()).isEqualTo(bc_string.hashCode());
assertThat(bc, equalTo(bc)); assertThat(bc).isEqualTo(bc);
assertThat(bc, equalTo(bc_substring)); assertThat(bc).isEqualTo(bc_substring);
assertThat(bc, equalTo(bc_string)); assertThat(bc).isEqualTo(bc_string);
assertThat(bc.hashCode(), not(equalTo(abcd.hashCode()))); assertThat(bc.hashCode()).isNotEqualTo(abcd.hashCode());
assertThat(bc, not(equalTo(abcd))); assertThat(bc).isNotEqualTo(abcd);
} }
@Test @Test
public void hashCodeSameAsString() throws Exception { public void hashCodeSameAsString() throws Exception {
String s = "abcABC123xyz!"; String s = "abcABC123xyz!";
AsciiBytes a = new AsciiBytes(s); AsciiBytes a = new AsciiBytes(s);
assertThat(s.hashCode(), equalTo(a.hashCode())); assertThat(s.hashCode()).isEqualTo(a.hashCode());
} }
@Test @Test
public void hashCodeSameAsStringWithSpecial() throws Exception { public void hashCodeSameAsStringWithSpecial() throws Exception {
String s = "special/\u00EB.dat"; String s = "special/\u00EB.dat";
AsciiBytes a = new AsciiBytes(s); AsciiBytes a = new AsciiBytes(s);
assertThat(s.hashCode(), equalTo(a.hashCode())); assertThat(s.hashCode()).isEqualTo(a.hashCode());
} }
} }
...@@ -31,8 +31,7 @@ import org.springframework.boot.loader.TestJarCreator; ...@@ -31,8 +31,7 @@ import org.springframework.boot.loader.TestJarCreator;
import org.springframework.boot.loader.data.RandomAccessData; import org.springframework.boot.loader.data.RandomAccessData;
import org.springframework.boot.loader.data.RandomAccessDataFile; import org.springframework.boot.loader.data.RandomAccessDataFile;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
...@@ -62,7 +61,7 @@ public class CentralDirectoryParserTests { ...@@ -62,7 +61,7 @@ public class CentralDirectoryParserTests {
@Test @Test
public void visitsInOrder() throws Exception { public void visitsInOrder() throws Exception {
CentralDirectoryVisitor visitor = mock(CentralDirectoryVisitor.class); CentralDirectoryVisitor visitor = mock(TestCentralDirectoryVisitor.class);
CentralDirectoryParser parser = new CentralDirectoryParser(); CentralDirectoryParser parser = new CentralDirectoryParser();
parser.addVisitor(visitor); parser.addVisitor(visitor);
parser.parse(this.jarData, false); parser.parse(this.jarData, false);
...@@ -81,17 +80,17 @@ public class CentralDirectoryParserTests { ...@@ -81,17 +80,17 @@ public class CentralDirectoryParserTests {
parser.addVisitor(collector); parser.addVisitor(collector);
parser.parse(this.jarData, false); parser.parse(this.jarData, false);
Iterator<CentralDirectoryFileHeader> headers = collector.getHeaders().iterator(); Iterator<CentralDirectoryFileHeader> headers = collector.getHeaders().iterator();
assertThat(headers.next().getName().toString(), equalTo("META-INF/")); assertThat(headers.next().getName().toString()).isEqualTo("META-INF/");
assertThat(headers.next().getName().toString(), equalTo("META-INF/MANIFEST.MF")); assertThat(headers.next().getName().toString()).isEqualTo("META-INF/MANIFEST.MF");
assertThat(headers.next().getName().toString(), equalTo("1.dat")); assertThat(headers.next().getName().toString()).isEqualTo("1.dat");
assertThat(headers.next().getName().toString(), equalTo("2.dat")); assertThat(headers.next().getName().toString()).isEqualTo("2.dat");
assertThat(headers.next().getName().toString(), equalTo("d/")); assertThat(headers.next().getName().toString()).isEqualTo("d/");
assertThat(headers.next().getName().toString(), equalTo("d/9.dat")); assertThat(headers.next().getName().toString()).isEqualTo("d/9.dat");
assertThat(headers.next().getName().toString(), equalTo("special/")); assertThat(headers.next().getName().toString()).isEqualTo("special/");
assertThat(headers.next().getName().toString(), equalTo("special/\u00EB.dat")); assertThat(headers.next().getName().toString()).isEqualTo("special/\u00EB.dat");
assertThat(headers.next().getName().toString(), equalTo("nested.jar")); assertThat(headers.next().getName().toString()).isEqualTo("nested.jar");
assertThat(headers.next().getName().toString(), equalTo("another-nested.jar")); assertThat(headers.next().getName().toString()).isEqualTo("another-nested.jar");
assertThat(headers.hasNext(), equalTo(false)); assertThat(headers.hasNext()).isFalse();
} }
private static class Collector implements CentralDirectoryVisitor { private static class Collector implements CentralDirectoryVisitor {
...@@ -119,4 +118,8 @@ public class CentralDirectoryParserTests { ...@@ -119,4 +118,8 @@ public class CentralDirectoryParserTests {
} }
public interface TestCentralDirectoryVisitor extends CentralDirectoryVisitor {
}
} }
...@@ -20,9 +20,11 @@ import org.junit.AfterClass; ...@@ -20,9 +20,11 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SystemPropertyUtils}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class SystemPropertyUtilsTests { public class SystemPropertyUtilsTests {
...@@ -39,23 +41,25 @@ public class SystemPropertyUtilsTests { ...@@ -39,23 +41,25 @@ public class SystemPropertyUtilsTests {
@Test @Test
public void testVanillaPlaceholder() { public void testVanillaPlaceholder() {
assertEquals("bar", SystemPropertyUtils.resolvePlaceholders("${foo}")); assertThat(SystemPropertyUtils.resolvePlaceholders("${foo}")).isEqualTo("bar");
} }
@Test @Test
public void testDefaultValue() { public void testDefaultValue() {
assertEquals("foo", SystemPropertyUtils.resolvePlaceholders("${bar:foo}")); assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:foo}"))
.isEqualTo("foo");
} }
@Test @Test
public void testNestedPlaceholder() { public void testNestedPlaceholder() {
assertEquals("foo", assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"))
SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}")); .isEqualTo("foo");
} }
@Test @Test
public void testEnvVar() { public void testEnvVar() {
assertEquals(System.getenv("LANG"), SystemPropertyUtils.getProperty("lang")); assertThat(SystemPropertyUtils.getProperty("lang"))
.isEqualTo(System.getenv("LANG"));
} }
} }
...@@ -36,8 +36,7 @@ import org.springframework.boot.loader.tools.Library; ...@@ -36,8 +36,7 @@ import org.springframework.boot.loader.tools.Library;
import org.springframework.boot.loader.tools.LibraryCallback; import org.springframework.boot.loader.tools.LibraryCallback;
import org.springframework.boot.loader.tools.LibraryScope; import org.springframework.boot.loader.tools.LibraryScope;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
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;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
...@@ -80,9 +79,9 @@ public class ArtifactsLibrariesTests { ...@@ -80,9 +79,9 @@ public class ArtifactsLibrariesTests {
this.libs.doWithLibraries(this.callback); this.libs.doWithLibraries(this.callback);
verify(this.callback).library(this.libraryCaptor.capture()); verify(this.callback).library(this.libraryCaptor.capture());
Library library = this.libraryCaptor.getValue(); Library library = this.libraryCaptor.getValue();
assertThat(library.getFile(), equalTo(this.file)); assertThat(library.getFile()).isEqualTo(this.file);
assertThat(library.getScope(), equalTo(LibraryScope.COMPILE)); assertThat(library.getScope()).isEqualTo(LibraryScope.COMPILE);
assertThat(library.isUnpackRequired(), equalTo(false)); assertThat(library.isUnpackRequired()).isFalse();
} }
@Test @Test
...@@ -98,7 +97,7 @@ public class ArtifactsLibrariesTests { ...@@ -98,7 +97,7 @@ public class ArtifactsLibrariesTests {
mock(Log.class)); mock(Log.class));
this.libs.doWithLibraries(this.callback); this.libs.doWithLibraries(this.callback);
verify(this.callback).library(this.libraryCaptor.capture()); verify(this.callback).library(this.libraryCaptor.capture());
assertThat(this.libraryCaptor.getValue().isUnpackRequired(), equalTo(true)); assertThat(this.libraryCaptor.getValue().isUnpackRequired()).isTrue();
} }
@Test @Test
...@@ -117,8 +116,8 @@ public class ArtifactsLibrariesTests { ...@@ -117,8 +116,8 @@ public class ArtifactsLibrariesTests {
this.libs = new ArtifactsLibraries(this.artifacts, null, mock(Log.class)); this.libs = new ArtifactsLibraries(this.artifacts, null, mock(Log.class));
this.libs.doWithLibraries(this.callback); this.libs.doWithLibraries(this.callback);
verify(this.callback, times(2)).library(this.libraryCaptor.capture()); verify(this.callback, times(2)).library(this.libraryCaptor.capture());
assertThat(this.libraryCaptor.getAllValues().get(0).getName(), equalTo("g1-a")); assertThat(this.libraryCaptor.getAllValues().get(0).getName()).isEqualTo("g1-a");
assertThat(this.libraryCaptor.getAllValues().get(1).getName(), equalTo("g2-a")); assertThat(this.libraryCaptor.getAllValues().get(1).getName()).isEqualTo("g2-a");
} }
} }
...@@ -27,8 +27,7 @@ import org.apache.maven.plugin.MojoExecutionException; ...@@ -27,8 +27,7 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -48,8 +47,8 @@ public class DependencyFilterMojoTests { ...@@ -48,8 +47,8 @@ public class DependencyFilterMojoTests {
Set<Artifact> artifacts = mojo.filterDependencies( Set<Artifact> artifacts = mojo.filterDependencies(
createArtifact("com.foo", "one"), createArtifact("com.foo", "two"), createArtifact("com.foo", "one"), createArtifact("com.foo", "two"),
createArtifact("com.bar", "exclude-id"), artifact); createArtifact("com.bar", "exclude-id"), artifact);
assertEquals("wrong filtering of artifacts", 1, artifacts.size()); assertThat(artifacts).hasSize(1);
assertSame("Wrong filtered artifact", artifact, artifacts.iterator().next()); assertThat(artifacts.iterator().next()).isSameAs(artifact);
} }
@Test @Test
...@@ -61,8 +60,8 @@ public class DependencyFilterMojoTests { ...@@ -61,8 +60,8 @@ public class DependencyFilterMojoTests {
Set<Artifact> artifacts = mojo.filterDependencies( Set<Artifact> artifacts = mojo.filterDependencies(
createArtifact("com.foo", "one"), createArtifact("com.foo", "two"), createArtifact("com.foo", "one"), createArtifact("com.foo", "two"),
artifact); artifact);
assertEquals("wrong filtering of artifacts", 1, artifacts.size()); assertThat(artifacts).hasSize(1);
assertSame("Wrong filtered artifact", artifact, artifacts.iterator().next()); assertThat(artifacts.iterator().next()).isSameAs(artifact);
} }
private Artifact createArtifact(String groupId, String artifactId) { private Artifact createArtifact(String groupId, String artifactId) {
......
...@@ -25,8 +25,7 @@ import org.apache.maven.artifact.Artifact; ...@@ -25,8 +25,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -36,7 +35,7 @@ import static org.mockito.Mockito.mock; ...@@ -36,7 +35,7 @@ import static org.mockito.Mockito.mock;
* @author Stephane Nicoll * @author Stephane Nicoll
* @author David Turanski * @author David Turanski
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings({ "rawtypes", "unchecked" })
public class ExcludeFilterTests { public class ExcludeFilterTests {
@Test @Test
...@@ -45,7 +44,7 @@ public class ExcludeFilterTests { ...@@ -45,7 +44,7 @@ public class ExcludeFilterTests {
Arrays.asList(createExclude("com.foo", "bar"))); Arrays.asList(createExclude("com.foo", "bar")));
Set result = filter Set result = filter
.filter(Collections.singleton(createArtifact("com.foo", "bar"))); .filter(Collections.singleton(createArtifact("com.foo", "bar")));
assertEquals("Should have been filtered", 0, result.size()); assertThat(result).isEmpty();
} }
@Test @Test
...@@ -54,8 +53,8 @@ public class ExcludeFilterTests { ...@@ -54,8 +53,8 @@ public class ExcludeFilterTests {
Arrays.asList(createExclude("com.foo", "bar"))); Arrays.asList(createExclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.baz", "bar"); Artifact artifact = createArtifact("com.baz", "bar");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertThat(result).hasSize(1);
assertSame(artifact, result.iterator().next()); assertThat(result.iterator().next()).isSameAs(artifact);
} }
@Test @Test
...@@ -64,8 +63,8 @@ public class ExcludeFilterTests { ...@@ -64,8 +63,8 @@ public class ExcludeFilterTests {
Arrays.asList(createExclude("com.foo", "bar"))); Arrays.asList(createExclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.foo", "biz"); Artifact artifact = createArtifact("com.foo", "biz");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertThat(result).hasSize(1);
assertSame(artifact, result.iterator().next()); assertThat(result.iterator().next()).isSameAs(artifact);
} }
@Test @Test
...@@ -74,7 +73,7 @@ public class ExcludeFilterTests { ...@@ -74,7 +73,7 @@ public class ExcludeFilterTests {
Arrays.asList(createExclude("com.foo", "bar", "jdk5"))); Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
Set result = filter Set result = filter
.filter(Collections.singleton(createArtifact("com.foo", "bar", "jdk5"))); .filter(Collections.singleton(createArtifact("com.foo", "bar", "jdk5")));
assertEquals("Should have been filtered", 0, result.size()); assertThat(result).isEmpty();
} }
@Test @Test
...@@ -83,8 +82,8 @@ public class ExcludeFilterTests { ...@@ -83,8 +82,8 @@ public class ExcludeFilterTests {
Arrays.asList(createExclude("com.foo", "bar", "jdk5"))); Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar"); Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertThat(result).hasSize(1);
assertSame(artifact, result.iterator().next()); assertThat(result.iterator().next()).isSameAs(artifact);
} }
@Test @Test
...@@ -93,8 +92,8 @@ public class ExcludeFilterTests { ...@@ -93,8 +92,8 @@ public class ExcludeFilterTests {
Arrays.asList(createExclude("com.foo", "bar", "jdk5"))); Arrays.asList(createExclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar", "jdk6"); Artifact artifact = createArtifact("com.foo", "bar", "jdk6");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertThat(result).hasSize(1);
assertSame(artifact, result.iterator().next()); assertThat(result.iterator().next()).isSameAs(artifact);
} }
@Test @Test
...@@ -108,8 +107,8 @@ public class ExcludeFilterTests { ...@@ -108,8 +107,8 @@ public class ExcludeFilterTests {
Artifact anotherAcme = createArtifact("org.acme", "another-app"); Artifact anotherAcme = createArtifact("org.acme", "another-app");
artifacts.add(anotherAcme); artifacts.add(anotherAcme);
Set result = filter.filter(artifacts); Set result = filter.filter(artifacts);
assertEquals("Two dependencies should have been filtered", 1, result.size()); assertThat(result).hasSize(1);
assertSame(anotherAcme, result.iterator().next()); assertThat(result.iterator().next()).isSameAs(anotherAcme);
} }
private Exclude createExclude(String groupId, String artifactId) { private Exclude createExclude(String groupId, String artifactId) {
......
...@@ -25,8 +25,7 @@ import org.apache.maven.artifact.Artifact; ...@@ -25,8 +25,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -35,7 +34,7 @@ import static org.mockito.Mockito.mock; ...@@ -35,7 +34,7 @@ import static org.mockito.Mockito.mock;
* *
* @author David Turanski * @author David Turanski
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings({ "rawtypes", "unchecked" })
public class IncludeFilterTests { public class IncludeFilterTests {
@Test @Test
...@@ -44,8 +43,8 @@ public class IncludeFilterTests { ...@@ -44,8 +43,8 @@ public class IncludeFilterTests {
Arrays.asList(createInclude("com.foo", "bar"))); Arrays.asList(createInclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.foo", "bar"); Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertThat(result).hasSize(1);
assertSame(artifact, result.iterator().next()); assertThat(result.iterator().next()).isSameAs(artifact);
} }
@Test @Test
...@@ -54,7 +53,7 @@ public class IncludeFilterTests { ...@@ -54,7 +53,7 @@ public class IncludeFilterTests {
Arrays.asList(createInclude("com.foo", "bar"))); Arrays.asList(createInclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.baz", "bar"); Artifact artifact = createArtifact("com.baz", "bar");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should have been filtered", 0, result.size()); assertThat(result).isEmpty();
} }
@Test @Test
...@@ -63,7 +62,7 @@ public class IncludeFilterTests { ...@@ -63,7 +62,7 @@ public class IncludeFilterTests {
Arrays.asList(createInclude("com.foo", "bar"))); Arrays.asList(createInclude("com.foo", "bar")));
Artifact artifact = createArtifact("com.foo", "biz"); Artifact artifact = createArtifact("com.foo", "biz");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should have been filtered", 0, result.size()); assertThat(result).isEmpty();
} }
@Test @Test
...@@ -72,8 +71,8 @@ public class IncludeFilterTests { ...@@ -72,8 +71,8 @@ public class IncludeFilterTests {
Arrays.asList(createInclude("com.foo", "bar", "jdk5"))); Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar", "jdk5"); Artifact artifact = createArtifact("com.foo", "bar", "jdk5");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should not have been filtered", 1, result.size()); assertThat(result).hasSize(1);
assertSame(artifact, result.iterator().next()); assertThat(result.iterator().next()).isSameAs(artifact);
} }
@Test @Test
...@@ -82,7 +81,7 @@ public class IncludeFilterTests { ...@@ -82,7 +81,7 @@ public class IncludeFilterTests {
Arrays.asList(createInclude("com.foo", "bar", "jdk5"))); Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar"); Artifact artifact = createArtifact("com.foo", "bar");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should have been filtered", 0, result.size()); assertThat(result).isEmpty();
} }
@Test @Test
...@@ -91,7 +90,7 @@ public class IncludeFilterTests { ...@@ -91,7 +90,7 @@ public class IncludeFilterTests {
Arrays.asList(createInclude("com.foo", "bar", "jdk5"))); Arrays.asList(createInclude("com.foo", "bar", "jdk5")));
Artifact artifact = createArtifact("com.foo", "bar", "jdk6"); Artifact artifact = createArtifact("com.foo", "bar", "jdk6");
Set result = filter.filter(Collections.singleton(artifact)); Set result = filter.filter(Collections.singleton(artifact));
assertEquals("Should have been filtered", 0, result.size()); assertThat(result).isEmpty();
} }
@Test @Test
...@@ -105,7 +104,7 @@ public class IncludeFilterTests { ...@@ -105,7 +104,7 @@ public class IncludeFilterTests {
Artifact anotherAcme = createArtifact("org.acme", "another-app"); Artifact anotherAcme = createArtifact("org.acme", "another-app");
artifacts.add(anotherAcme); artifacts.add(anotherAcme);
Set result = filter.filter(artifacts); Set result = filter.filter(artifacts);
assertEquals("One dependency should have been filtered", 2, result.size()); assertThat(result).hasSize(2);
} }
private Include createInclude(String groupId, String artifactId) { private Include createInclude(String groupId, String artifactId) {
......
...@@ -22,10 +22,7 @@ import java.util.jar.JarOutputStream; ...@@ -22,10 +22,7 @@ import java.util.jar.JarOutputStream;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link PropertiesMergingResourceTransformer}. * Tests for {@link PropertiesMergingResourceTransformer}.
...@@ -38,10 +35,10 @@ public class PropertiesMergingResourceTransformerTests { ...@@ -38,10 +35,10 @@ public class PropertiesMergingResourceTransformerTests {
@Test @Test
public void testProcess() throws Exception { public void testProcess() throws Exception {
assertFalse(this.transformer.hasTransformedResource()); assertThat(this.transformer.hasTransformedResource()).isFalse();
this.transformer.processResource("foo", this.transformer.processResource("foo",
new ByteArrayInputStream("foo=bar".getBytes()), null); new ByteArrayInputStream("foo=bar".getBytes()), null);
assertTrue(this.transformer.hasTransformedResource()); assertThat(this.transformer.hasTransformedResource()).isTrue();
} }
@Test @Test
...@@ -50,7 +47,7 @@ public class PropertiesMergingResourceTransformerTests { ...@@ -50,7 +47,7 @@ public class PropertiesMergingResourceTransformerTests {
new ByteArrayInputStream("foo=bar".getBytes()), null); new ByteArrayInputStream("foo=bar".getBytes()), null);
this.transformer.processResource("bar", this.transformer.processResource("bar",
new ByteArrayInputStream("foo=spam".getBytes()), null); new ByteArrayInputStream("foo=spam".getBytes()), null);
assertEquals("bar,spam", this.transformer.getData().getProperty("foo")); assertThat(this.transformer.getData().getProperty("foo")).isEqualTo("bar,spam");
} }
@Test @Test
...@@ -63,8 +60,8 @@ public class PropertiesMergingResourceTransformerTests { ...@@ -63,8 +60,8 @@ public class PropertiesMergingResourceTransformerTests {
this.transformer.modifyOutputStream(os); this.transformer.modifyOutputStream(os);
os.flush(); os.flush();
os.close(); os.close();
assertNotNull(out.toByteArray()); assertThat(out.toByteArray()).isNotNull();
assertTrue(out.toByteArray().length > 0); assertThat(out.toByteArray().length > 0).isTrue();
} }
} }
...@@ -18,8 +18,7 @@ package org.springframework.boot.maven; ...@@ -18,8 +18,7 @@ package org.springframework.boot.maven;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests for {@link RunArguments}. * Tests for {@link RunArguments}.
...@@ -31,48 +30,48 @@ public class RunArgumentsTests { ...@@ -31,48 +30,48 @@ public class RunArgumentsTests {
@Test @Test
public void parseNull() { public void parseNull() {
String[] args = parseArgs(null); String[] args = parseArgs(null);
assertNotNull(args); assertThat(args).isNotNull();
assertEquals(0, args.length); assertThat(args.length).isEqualTo(0);
} }
@Test @Test
public void parseEmpty() { public void parseEmpty() {
String[] args = parseArgs(" "); String[] args = parseArgs(" ");
assertNotNull(args); assertThat(args).isNotNull();
assertEquals(0, args.length); assertThat(args.length).isEqualTo(0);
} }
@Test @Test
public void parseDebugFlags() { public void parseDebugFlags() {
String[] args = parseArgs( String[] args = parseArgs(
"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"); "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
assertEquals(2, args.length); assertThat(args.length).isEqualTo(2);
assertEquals("-Xdebug", args[0]); assertThat(args[0]).isEqualTo("-Xdebug");
assertEquals("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005", assertThat(args[1]).isEqualTo(
args[1]); "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
} }
@Test @Test
public void parseWithExtraSpaces() { public void parseWithExtraSpaces() {
String[] args = parseArgs(" -Dfoo=bar -Dfoo2=bar2 "); String[] args = parseArgs(" -Dfoo=bar -Dfoo2=bar2 ");
assertEquals(2, args.length); assertThat(args.length).isEqualTo(2);
assertEquals("-Dfoo=bar", args[0]); assertThat(args[0]).isEqualTo("-Dfoo=bar");
assertEquals("-Dfoo2=bar2", args[1]); assertThat(args[1]).isEqualTo("-Dfoo2=bar2");
} }
@Test @Test
public void parseWithNewLinesAndTabs() { public void parseWithNewLinesAndTabs() {
String[] args = parseArgs(" -Dfoo=bar \n" + "\t\t -Dfoo2=bar2 "); String[] args = parseArgs(" -Dfoo=bar \n" + "\t\t -Dfoo2=bar2 ");
assertEquals(2, args.length); assertThat(args.length).isEqualTo(2);
assertEquals("-Dfoo=bar", args[0]); assertThat(args[0]).isEqualTo("-Dfoo=bar");
assertEquals("-Dfoo2=bar2", args[1]); assertThat(args[1]).isEqualTo("-Dfoo2=bar2");
} }
@Test @Test
public void quoteHandledProperly() { public void quoteHandledProperly() {
String[] args = parseArgs("-Dvalue=\"My Value\" "); String[] args = parseArgs("-Dvalue=\"My Value\" ");
assertEquals(1, args.length); assertThat(args.length).isEqualTo(1);
assertEquals("-Dvalue=My Value", args[0]); assertThat(args[0]).isEqualTo("-Dvalue=My Value");
} }
private String[] parseArgs(String args) { private String[] parseArgs(String args) {
......
...@@ -28,11 +28,7 @@ import java.util.zip.ZipFile; ...@@ -28,11 +28,7 @@ import java.util.zip.ZipFile;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
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.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Verification utility for use with maven-invoker-plugin verification scripts. * Verification utility for use with maven-invoker-plugin verification scripts.
...@@ -107,13 +103,15 @@ public final class Verify { ...@@ -107,13 +103,15 @@ public final class Verify {
} }
public void assertHasNonUnpackEntry(String entryName) { public void assertHasNonUnpackEntry(String entryName) {
assertTrue("Entry starting with " + entryName + " was an UNPACK entry", assertThat(hasNonUnpackEntry(entryName))
hasNonUnpackEntry(entryName)); .as("Entry starting with " + entryName + " was an UNPACK entry")
.isTrue();
} }
public void assertHasUnpackEntry(String entryName) { public void assertHasUnpackEntry(String entryName) {
assertTrue("Entry starting with " + entryName + " was not an UNPACK entry", assertThat(hasUnpackEntry(entryName))
hasUnpackEntry(entryName)); .as("Entry starting with " + entryName + " was not an UNPACK entry")
.isTrue();
} }
private boolean hasNonUnpackEntry(String entryName) { private boolean hasNonUnpackEntry(String entryName) {
...@@ -167,22 +165,21 @@ public final class Verify { ...@@ -167,22 +165,21 @@ public final class Verify {
public void verify(boolean executable, String... scriptContents) public void verify(boolean executable, String... scriptContents)
throws Exception { throws Exception {
assertTrue("Archive missing", this.file.exists()); assertThat(this.file).exists().isFile();
assertTrue("Archive not a file", this.file.isFile());
if (scriptContents.length > 0 && executable) { if (scriptContents.length > 0 && executable) {
String contents = new String(FileCopyUtils.copyToByteArray(this.file)); String contents = new String(FileCopyUtils.copyToByteArray(this.file));
contents = contents.substring(0, contents contents = contents.substring(0, contents
.indexOf(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 }))); .indexOf(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 })));
for (String content : scriptContents) { for (String content : scriptContents) {
assertThat(contents, containsString(content)); assertThat(contents).contains(content);
} }
} }
if (!executable) { if (!executable) {
String contents = new String(FileCopyUtils.copyToByteArray(this.file)); String contents = new String(FileCopyUtils.copyToByteArray(this.file));
assertTrue("Is executable", contents assertThat(contents).as("Is executable")
.startsWith(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 }))); .startsWith(new String(new byte[] { 0x50, 0x4b, 0x03, 0x04 }));
} }
ZipFile zipFile = new ZipFile(this.file); ZipFile zipFile = new ZipFile(this.file);
...@@ -224,18 +221,21 @@ public final class Verify { ...@@ -224,18 +221,21 @@ public final class Verify {
verifier.assertHasEntryNameStartingWith("lib/spring-context"); verifier.assertHasEntryNameStartingWith("lib/spring-context");
verifier.assertHasEntryNameStartingWith("lib/spring-core"); verifier.assertHasEntryNameStartingWith("lib/spring-core");
verifier.assertHasEntryNameStartingWith("lib/javax.servlet-api-3"); verifier.assertHasEntryNameStartingWith("lib/javax.servlet-api-3");
assertTrue("Unpacked launcher classes", verifier assertThat(verifier
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class")); .hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"))
assertTrue("Own classes", .as("Unpacked launcher classes").isTrue();
verifier.hasEntry("org/" + "test/SampleApplication.class")); assertThat(verifier.hasEntry("org/" + "test/SampleApplication.class"))
.as("Own classes").isTrue();
} }
@Override @Override
protected void verifyManifest(Manifest manifest) throws Exception { protected void verifyManifest(Manifest manifest) throws Exception {
assertEquals("org.springframework.boot.loader.JarLauncher", assertThat(manifest.getMainAttributes().getValue("Main-Class"))
manifest.getMainAttributes().getValue("Main-Class")); .isEqualTo("org.springframework.boot.loader.JarLauncher");
assertEquals(this.main, manifest.getMainAttributes().getValue("Start-Class")); assertThat(manifest.getMainAttributes().getValue("Start-Class"))
assertEquals("Foo", manifest.getMainAttributes().getValue("Not-Used")); .isEqualTo(this.main);
assertThat(manifest.getMainAttributes().getValue("Not-Used"))
.isEqualTo("Foo");
} }
} }
...@@ -252,20 +252,23 @@ public final class Verify { ...@@ -252,20 +252,23 @@ public final class Verify {
verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-core"); verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-core");
verifier.assertHasEntryNameStartingWith( verifier.assertHasEntryNameStartingWith(
"WEB-INF/lib-provided/javax.servlet-api-3"); "WEB-INF/lib-provided/javax.servlet-api-3");
assertTrue("Unpacked launcher classes", verifier assertThat(verifier
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class")); .hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"))
assertTrue("Own classes", verifier .as("Unpacked launcher classes").isTrue();
.hasEntry("WEB-INF/classes/org/" + "test/SampleApplication.class")); assertThat(verifier
assertTrue("Web content", verifier.hasEntry("index.html")); .hasEntry("WEB-INF/classes/org/" + "test/SampleApplication.class"))
.as("Own classes").isTrue();
assertThat(verifier.hasEntry("index.html")).as("Web content").isTrue();
} }
@Override @Override
protected void verifyManifest(Manifest manifest) throws Exception { protected void verifyManifest(Manifest manifest) throws Exception {
assertEquals("org.springframework.boot.loader.WarLauncher", assertThat(manifest.getMainAttributes().getValue("Main-Class"))
manifest.getMainAttributes().getValue("Main-Class")); .isEqualTo("org.springframework.boot.loader.WarLauncher");
assertEquals("org.test.SampleApplication", assertThat(manifest.getMainAttributes().getValue("Start-Class"))
manifest.getMainAttributes().getValue("Start-Class")); .isEqualTo("org.test.SampleApplication");
assertEquals("Foo", manifest.getMainAttributes().getValue("Not-Used")); assertThat(manifest.getMainAttributes().getValue("Not-Used"))
.isEqualTo("Foo");
} }
} }
...@@ -277,11 +280,12 @@ public final class Verify { ...@@ -277,11 +280,12 @@ public final class Verify {
@Override @Override
protected void verifyManifest(Manifest manifest) throws Exception { protected void verifyManifest(Manifest manifest) throws Exception {
assertEquals("org.springframework.boot.loader.PropertiesLauncher", assertThat(manifest.getMainAttributes().getValue("Main-Class"))
manifest.getMainAttributes().getValue("Main-Class")); .isEqualTo("org.springframework.boot.loader.PropertiesLauncher");
assertEquals("org.test.SampleApplication", assertThat(manifest.getMainAttributes().getValue("Start-Class"))
manifest.getMainAttributes().getValue("Start-Class")); .isEqualTo("org.test.SampleApplication");
assertEquals("Foo", manifest.getMainAttributes().getValue("Not-Used")); assertThat(manifest.getMainAttributes().getValue("Not-Used"))
.isEqualTo("Foo");
} }
} }
...@@ -297,10 +301,11 @@ public final class Verify { ...@@ -297,10 +301,11 @@ public final class Verify {
verifier.assertHasEntryNameStartingWith("lib/spring-context"); verifier.assertHasEntryNameStartingWith("lib/spring-context");
verifier.assertHasEntryNameStartingWith("lib/spring-core"); verifier.assertHasEntryNameStartingWith("lib/spring-core");
verifier.assertHasNoEntryNameStartingWith("lib/javax.servlet-api-3"); verifier.assertHasNoEntryNameStartingWith("lib/javax.servlet-api-3");
assertFalse("Unpacked launcher classes", verifier assertThat(verifier
.hasEntry("org/" + "springframework/boot/loader/JarLauncher.class")); .hasEntry("org/" + "springframework/boot/loader/JarLauncher.class"))
assertTrue("Own classes", .as("Unpacked launcher classes").isFalse();
verifier.hasEntry("org/" + "test/SampleModule.class")); assertThat(verifier.hasEntry("org/" + "test/SampleModule.class"))
.as("Own classes").isTrue();
} }
@Override @Override
......
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