Migrate Hamcrest assertions to AssertJ

Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ
and add checkstyle rules to ensure they don't return.

See gh-23022
This commit is contained in:
Phillip Webb
2019-05-23 15:48:03 -07:00
parent 2294625cf0
commit 95a9d46a87
322 changed files with 4358 additions and 4814 deletions

View File

@@ -61,11 +61,6 @@ import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
@@ -98,7 +93,7 @@ public abstract class AbstractPropertyAccessorTests {
public void isReadableProperty() {
AbstractPropertyAccessor accessor = createAccessor(new Simple("John", 2));
assertThat(accessor.isReadableProperty("name"), is(true));
assertThat(accessor.isReadableProperty("name")).isTrue();
}
@Test
@@ -130,7 +125,7 @@ public abstract class AbstractPropertyAccessorTests {
public void isWritableProperty() {
AbstractPropertyAccessor accessor = createAccessor(new Simple("John", 2));
assertThat(accessor.isWritableProperty("name"), is(true));
assertThat(accessor.isWritableProperty("name")).isTrue();
}
@Test
@@ -198,21 +193,21 @@ public abstract class AbstractPropertyAccessorTests {
public void getSimpleProperty() {
Simple target = new Simple("John", 2);
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyValue("name"), is("John"));
assertThat(accessor.getPropertyValue("name")).isEqualTo("John");
}
@Test
public void getNestedProperty() {
Person target = createPerson("John", "London", "UK");
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyValue("address.city"), is("London"));
assertThat(accessor.getPropertyValue("address.city")).isEqualTo("London");
}
@Test
public void getNestedDeepProperty() {
Person target = createPerson("John", "London", "UK");
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyValue("address.country.name"), is("UK"));
assertThat(accessor.getPropertyValue("address.country.name")).isEqualTo("UK");
}
@Test
@@ -291,8 +286,8 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setPropertyValue("name", "SomeValue");
assertThat(target.name, is("SomeValue"));
assertThat(target.getName(), is("SomeValue"));
assertThat(target.name).isEqualTo("SomeValue");
assertThat(target.getName()).isEqualTo("SomeValue");
}
@Test
@@ -301,7 +296,7 @@ public abstract class AbstractPropertyAccessorTests {
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValue("address.city", "London");
assertThat(target.address.city, is("London"));
assertThat(target.address.city).isEqualTo("London");
}
@Test
@@ -364,7 +359,7 @@ public abstract class AbstractPropertyAccessorTests {
AbstractPropertyAccessor accessor = createAccessor(target);
accessor.setPropertyValue("address.country.name", "UK");
assertThat(target.address.country.name, is("UK"));
assertThat(target.address.country.name).isEqualTo("UK");
}
@Test
@@ -413,7 +408,7 @@ public abstract class AbstractPropertyAccessorTests {
accessor.setAutoGrowNestedPaths(true);
accessor.setPropertyValue("address.country.name", "UK");
assertThat(target.address.country.name, is("UK"));
assertThat(target.address.country.name).isEqualTo("UK");
}
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
@@ -1108,11 +1103,11 @@ public abstract class AbstractPropertyAccessorTests {
Object[] array = new Object[] {"1", "2"};
accessor.setPropertyValue("object", array);
assertThat(target.getObject(), equalTo((Object) array));
assertThat(target.getObject()).isEqualTo(array);
array = new Object[] {"1"};
accessor.setPropertyValue("object", array);
assertThat(target.getObject(), equalTo((Object) array));
assertThat(target.getObject()).isEqualTo(array);
}
@@ -1636,7 +1631,7 @@ public abstract class AbstractPropertyAccessorTests {
Simple target = new Simple("John", 2);
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyType("foo"), is(nullValue()));
assertThat(accessor.getPropertyType("foo")).isNull();
}
@Test
@@ -1644,7 +1639,7 @@ public abstract class AbstractPropertyAccessorTests {
Person target = createPerson("John", "Paris", "FR");
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyTypeDescriptor("address.city"), is(notNullValue()));
assertThat(accessor.getPropertyTypeDescriptor("address.city")).isNotNull();
}
@Test
@@ -1652,7 +1647,7 @@ public abstract class AbstractPropertyAccessorTests {
Simple target = new Simple("John", 2);
AbstractPropertyAccessor accessor = createAccessor(target);
assertThat(accessor.getPropertyTypeDescriptor("foo"), is(nullValue()));
assertThat(accessor.getPropertyTypeDescriptor("foo")).isNull();
}
@Test

View File

@@ -22,9 +22,8 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -67,7 +66,7 @@ public class BeanWrapperAutoGrowingTests {
public void getPropertyValueAutoGrowArray() {
assertNotNull(wrapper.getPropertyValue("array[0]"));
assertEquals(1, bean.getArray().length);
assertThat(bean.getArray()[0], instanceOf(Bean.class));
assertThat(bean.getArray()[0]).isInstanceOf(Bean.class);
}
@Test
@@ -80,11 +79,11 @@ public class BeanWrapperAutoGrowingTests {
public void getPropertyValueAutoGrowArrayBySeveralElements() {
assertNotNull(wrapper.getPropertyValue("array[4]"));
assertEquals(5, bean.getArray().length);
assertThat(bean.getArray()[0], instanceOf(Bean.class));
assertThat(bean.getArray()[1], instanceOf(Bean.class));
assertThat(bean.getArray()[2], instanceOf(Bean.class));
assertThat(bean.getArray()[3], instanceOf(Bean.class));
assertThat(bean.getArray()[4], instanceOf(Bean.class));
assertThat(bean.getArray()[0]).isInstanceOf(Bean.class);
assertThat(bean.getArray()[1]).isInstanceOf(Bean.class);
assertThat(bean.getArray()[2]).isInstanceOf(Bean.class);
assertThat(bean.getArray()[3]).isInstanceOf(Bean.class);
assertThat(bean.getArray()[4]).isInstanceOf(Bean.class);
assertNotNull(wrapper.getPropertyValue("array[0]"));
assertNotNull(wrapper.getPropertyValue("array[1]"));
assertNotNull(wrapper.getPropertyValue("array[2]"));
@@ -95,14 +94,14 @@ public class BeanWrapperAutoGrowingTests {
public void getPropertyValueAutoGrowMultiDimensionalArray() {
assertNotNull(wrapper.getPropertyValue("multiArray[0][0]"));
assertEquals(1, bean.getMultiArray()[0].length);
assertThat(bean.getMultiArray()[0][0], instanceOf(Bean.class));
assertThat(bean.getMultiArray()[0][0]).isInstanceOf(Bean.class);
}
@Test
public void getPropertyValueAutoGrowList() {
assertNotNull(wrapper.getPropertyValue("list[0]"));
assertEquals(1, bean.getList().size());
assertThat(bean.getList().get(0), instanceOf(Bean.class));
assertThat(bean.getList().get(0)).isInstanceOf(Bean.class);
}
@Test
@@ -115,11 +114,11 @@ public class BeanWrapperAutoGrowingTests {
public void getPropertyValueAutoGrowListBySeveralElements() {
assertNotNull(wrapper.getPropertyValue("list[4]"));
assertEquals(5, bean.getList().size());
assertThat(bean.getList().get(0), instanceOf(Bean.class));
assertThat(bean.getList().get(1), instanceOf(Bean.class));
assertThat(bean.getList().get(2), instanceOf(Bean.class));
assertThat(bean.getList().get(3), instanceOf(Bean.class));
assertThat(bean.getList().get(4), instanceOf(Bean.class));
assertThat(bean.getList().get(0)).isInstanceOf(Bean.class);
assertThat(bean.getList().get(1)).isInstanceOf(Bean.class);
assertThat(bean.getList().get(2)).isInstanceOf(Bean.class);
assertThat(bean.getList().get(3)).isInstanceOf(Bean.class);
assertThat(bean.getList().get(4)).isInstanceOf(Bean.class);
assertNotNull(wrapper.getPropertyValue("list[0]"));
assertNotNull(wrapper.getPropertyValue("list[1]"));
assertNotNull(wrapper.getPropertyValue("list[2]"));
@@ -138,7 +137,7 @@ public class BeanWrapperAutoGrowingTests {
public void getPropertyValueAutoGrowMultiDimensionalList() {
assertNotNull(wrapper.getPropertyValue("multiList[0][0]"));
assertEquals(1, bean.getMultiList().get(0).size());
assertThat(bean.getMultiList().get(0).get(0), instanceOf(Bean.class));
assertThat(bean.getMultiList().get(0).get(0)).isInstanceOf(Bean.class);
}
@Test
@@ -150,13 +149,13 @@ public class BeanWrapperAutoGrowingTests {
@Test
public void setPropertyValueAutoGrowMap() {
wrapper.setPropertyValue("map[A]", new Bean());
assertThat(bean.getMap().get("A"), instanceOf(Bean.class));
assertThat(bean.getMap().get("A")).isInstanceOf(Bean.class);
}
@Test
public void setNestedPropertyValueAutoGrowMap() {
wrapper.setPropertyValue("map[A].nested", new Bean());
assertThat(bean.getMap().get("A").getNested(), instanceOf(Bean.class));
assertThat(bean.getMap().get("A").getNested()).isInstanceOf(Bean.class);
}

View File

@@ -25,9 +25,7 @@ import org.junit.Test;
import org.springframework.core.OverridingClassLoader;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -87,13 +85,11 @@ public class CachedIntrospectionResultsTests {
}
// resulting in a property descriptor including the non-standard setFoo method
assertThat(pd, notNullValue());
assertThat(pd.getReadMethod(), equalTo(C.class.getMethod("getFoo")));
assertThat(
"No write method found for non-void returning 'setFoo' method. " +
"Check to see if CachedIntrospectionResults is delegating to " +
"ExtendedBeanInfo as expected",
pd.getWriteMethod(), equalTo(C.class.getMethod("setFoo", String.class)));
assertThat(pd).isNotNull();
assertThat(pd.getReadMethod()).isEqualTo(C.class.getMethod("getFoo"));
// No write method found for non-void returning 'setFoo' method.
// Check to see if CachedIntrospectionResults is delegating to ExtendedBeanInfo as expected
assertThat(pd.getWriteMethod()).isEqualTo(C.class.getMethod("setFoo", String.class));
}
}

View File

@@ -20,9 +20,8 @@ import java.beans.IntrospectionException;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link ExtendedBeanInfoTests}.
@@ -39,7 +38,7 @@ public class ExtendedBeanInfoFactoryTests {
class C {
public void setFoo(String s) { }
}
assertThat(factory.getBeanInfo(C.class), nullValue());
assertThat(factory.getBeanInfo(C.class)).isNull();
}
@Test
@@ -48,7 +47,7 @@ public class ExtendedBeanInfoFactoryTests {
class C {
public C setFoo(String s) { return this; }
}
assertThat(factory.getBeanInfo(C.class), notNullValue());
assertThat(factory.getBeanInfo(C.class)).isNotNull();
}
@Test
@@ -57,7 +56,7 @@ public class ExtendedBeanInfoFactoryTests {
class C {
public C setFoo(int i, String s) { return this; }
}
assertThat(factory.getBeanInfo(C.class), notNullValue());
assertThat(factory.getBeanInfo(C.class)).isNotNull();
}
@Test
@@ -66,7 +65,7 @@ public class ExtendedBeanInfoFactoryTests {
class C {
void setBar(String s) { }
}
assertThat(factory.getBeanInfo(C.class), nullValue());
assertThat(factory.getBeanInfo(C.class)).isNull();
}
@Test
@@ -75,7 +74,7 @@ public class ExtendedBeanInfoFactoryTests {
class C {
C setBar() { return this; }
}
assertThat(factory.getBeanInfo(C.class), nullValue());
assertThat(factory.getBeanInfo(C.class)).isNull();
}
@Test
@@ -84,7 +83,7 @@ public class ExtendedBeanInfoFactoryTests {
class C {
C set(String s) { return this; }
}
assertThat(factory.getBeanInfo(C.class), nullValue());
assertThat(factory.getBeanInfo(C.class)).isNull();
}
}

View File

@@ -27,11 +27,7 @@ import org.junit.Test;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -51,11 +47,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(false));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isFalse();
}
@Test
@@ -67,11 +63,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(true));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
}
@Test
@@ -84,11 +80,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(true));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
}
@Test
@@ -100,11 +96,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
}
@Test
@@ -116,16 +112,16 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
}
@Test
@@ -137,15 +133,15 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "foo")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(false));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foo")).isTrue();
}
@Test
@@ -158,20 +154,20 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
for (PropertyDescriptor pd : ebi.getPropertyDescriptors()) {
if (pd.getName().equals("foo")) {
assertThat(pd.getWriteMethod(), is(C.class.getMethod("setFoo", String.class)));
assertThat(pd.getWriteMethod()).isEqualTo(C.class.getMethod("setFoo", String.class));
return;
}
}
@@ -193,11 +189,11 @@ public class ExtendedBeanInfoTests {
}
{ // always passes
ExtendedBeanInfo bi = new ExtendedBeanInfo(Introspector.getBeanInfo(Parent.class));
assertThat(hasReadMethodForProperty(bi, "property1"), is(true));
assertThat(hasReadMethodForProperty(bi, "property1")).isTrue();
}
{ // failed prior to fix for SPR-9414
ExtendedBeanInfo bi = new ExtendedBeanInfo(Introspector.getBeanInfo(Child.class));
assertThat(hasReadMethodForProperty(bi, "property1"), is(true));
assertThat(hasReadMethodForProperty(bi, "property1")).isTrue();
}
}
@@ -211,11 +207,11 @@ public class ExtendedBeanInfoTests {
}
{ // always passes
BeanInfo info = Introspector.getBeanInfo(Bean.class);
assertThat(info.getPropertyDescriptors().length, equalTo(2));
assertThat(info.getPropertyDescriptors().length).isEqualTo(2);
}
{ // failed prior to fix for SPR-9453
BeanInfo info = new ExtendedBeanInfo(Introspector.getBeanInfo(Bean.class));
assertThat(info.getPropertyDescriptors().length, equalTo(2));
assertThat(info.getPropertyDescriptors().length).isEqualTo(2);
}
}
@@ -230,16 +226,16 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
}
@Test
@@ -268,30 +264,30 @@ public class ExtendedBeanInfoTests {
.setFoo("blue")
.setBar(42);
assertThat(c.getFoo(), is("blue"));
assertThat(c.getBar(), is(42));
assertThat(c.getFoo()).isEqualTo("blue");
assertThat(c.getBar()).isEqualTo(42);
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(bi, "bar"), is(true));
assertThat(hasWriteMethodForProperty(bi, "bar"), is(false));
assertThat(hasReadMethodForProperty(bi, "bar")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "bar")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(bi, "bar"), is(true));
assertThat(hasWriteMethodForProperty(bi, "bar"), is(false));
assertThat(hasReadMethodForProperty(bi, "bar")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "bar")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "bar"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "bar"), is(true));
assertThat(hasReadMethodForProperty(ebi, "bar")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "bar")).isTrue();
}
@Test
@@ -304,11 +300,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(false));
assertThat(hasReadMethodForProperty(ebi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isFalse();
}
/**
@@ -325,8 +321,8 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertEquals(hasWriteMethodForProperty(bi, "foo"), hasWriteMethodForProperty(ebi, "foo"));
}
@@ -340,8 +336,8 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertEquals(hasIndexedWriteMethodForProperty(bi, "foos"), hasIndexedWriteMethodForProperty(ebi, "foos"));
}
@@ -359,11 +355,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(false));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isFalse();
}
@Test
@@ -376,11 +372,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isFalse();
}
@Test
@@ -394,11 +390,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
assertThat(hasReadMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasReadMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
}
@Test
@@ -412,11 +408,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foos")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isTrue();
}
@Test
@@ -432,15 +428,15 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
assertThat(hasReadMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(true));
assertThat(hasReadMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foos")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isTrue();
}
@Test
@@ -460,15 +456,15 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
assertThat(hasReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foos"), is(true));
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(true));
assertThat(hasReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foos")).isTrue();
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isTrue();
}
@Test
@@ -483,14 +479,14 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
// interesting! standard Inspector picks up non-void return types on indexed write methods by default
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isTrue();
}
@Test
@@ -507,20 +503,20 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foos")).isFalse();
// again as above, standard Inspector picks up non-void return types on indexed write methods by default
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isTrue();
}
@Test
@@ -535,16 +531,16 @@ public class ExtendedBeanInfoTests {
}
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasReadMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isFalse();
BeanInfo ebi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(ebi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(false));
assertThat(hasReadMethodForProperty(ebi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isFalse();
}
{ // variant with non-standard write method
@SuppressWarnings("unused")
@@ -556,16 +552,16 @@ public class ExtendedBeanInfoTests {
}
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(false));
assertThat(hasReadMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foos")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "foos")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class));
assertThat(hasReadMethodForProperty(ebi, "foos"), is(false));
assertThat(hasIndexedReadMethodForProperty(ebi, "foos"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foos"), is(true));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(false));
assertThat(hasReadMethodForProperty(ebi, "foos")).isFalse();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foos")).isTrue();
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isFalse();
}
}
@@ -597,18 +593,18 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
assertThat(ebi.getPropertyDescriptors().length, equalTo(bi.getPropertyDescriptors().length));
assertThat(ebi.getPropertyDescriptors().length).isEqualTo(bi.getPropertyDescriptors().length);
}
@Test
@@ -621,11 +617,11 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(true));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
}
/**
@@ -642,7 +638,7 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(C.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(ebi.getPropertyDescriptors(), equalTo(bi.getPropertyDescriptors()));
assertThat(ebi.getPropertyDescriptors()).isEqualTo(bi.getPropertyDescriptors());
}
@Test
@@ -653,20 +649,20 @@ public class ExtendedBeanInfoTests {
}
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
for (PropertyDescriptor pd : ebi.getPropertyDescriptors()) {
if (pd.getName().equals("foo")) {
assertThat(pd.getWriteMethod(), is(C.class.getMethod("setFoo", String.class)));
assertThat(pd.getWriteMethod()).isEqualTo(C.class.getMethod("setFoo", String.class));
return;
}
}
@@ -681,20 +677,20 @@ public class ExtendedBeanInfoTests {
}
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(bi, "foo"), is(false));
assertThat(hasReadMethodForProperty(bi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "foo")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "foo"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true));
assertThat(hasReadMethodForProperty(ebi, "foo")).isFalse();
assertThat(hasWriteMethodForProperty(ebi, "foo")).isTrue();
for (PropertyDescriptor pd : ebi.getPropertyDescriptors()) {
if (pd.getName().equals("foo")) {
assertThat(pd.getWriteMethod(), is(C.class.getMethod("setFoo", String.class)));
assertThat(pd.getWriteMethod()).isEqualTo(C.class.getMethod("setFoo", String.class));
return;
}
}
@@ -717,22 +713,22 @@ public class ExtendedBeanInfoTests {
}
BeanInfo bi = Introspector.getBeanInfo(C.class);
assertThat(hasReadMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasWriteMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasReadMethodForProperty(bi, "dateFormat")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "dateFormat")).isFalse();
assertThat(hasIndexedReadMethodForProperty(bi, "dateFormat")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat")).isFalse();
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasWriteMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat"), is(false));
assertThat(hasReadMethodForProperty(bi, "dateFormat")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "dateFormat")).isFalse();
assertThat(hasIndexedReadMethodForProperty(bi, "dateFormat")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "dateFormat")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "dateFormat"), is(false));
assertThat(hasWriteMethodForProperty(ebi, "dateFormat"), is(true));
assertThat(hasIndexedReadMethodForProperty(ebi, "dateFormat"), is(false));
assertThat(hasIndexedWriteMethodForProperty(ebi, "dateFormat"), is(false));
assertThat(hasReadMethodForProperty(ebi, "dateFormat")).isFalse();
assertThat(hasWriteMethodForProperty(ebi, "dateFormat")).isTrue();
assertThat(hasIndexedReadMethodForProperty(ebi, "dateFormat")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(ebi, "dateFormat")).isFalse();
}
@Test
@@ -740,7 +736,7 @@ public class ExtendedBeanInfoTests {
BeanInfo bi = Introspector.getBeanInfo(TestBean.class);
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(ebi.getPropertyDescriptors().length, equalTo(bi.getPropertyDescriptors().length));
assertThat(ebi.getPropertyDescriptors().length).isEqualTo(bi.getPropertyDescriptors().length);
}
@Test
@@ -759,8 +755,8 @@ public class ExtendedBeanInfoTests {
break;
}
}
assertThat(found, is(true));
assertThat(ebi.getPropertyDescriptors().length, equalTo(bi.getPropertyDescriptors().length+1));
assertThat(found).isTrue();
assertThat(ebi.getPropertyDescriptors().length).isEqualTo(bi.getPropertyDescriptors().length+1);
}
/**
@@ -773,8 +769,7 @@ public class ExtendedBeanInfoTests {
BeanInfo ebi = new ExtendedBeanInfo(bi);
for (int i = 0; i < bi.getPropertyDescriptors().length; i++) {
assertThat("element " + i + " in BeanInfo and ExtendedBeanInfo propertyDescriptor arrays do not match",
ebi.getPropertyDescriptors()[i].getName(), equalTo(bi.getPropertyDescriptors()[i].getName()));
assertThat(ebi.getPropertyDescriptors()[i].getName()).isEqualTo(bi.getPropertyDescriptors()[i].getName());
}
}
@@ -782,19 +777,19 @@ public class ExtendedBeanInfoTests {
public void propertyDescriptorComparator() throws IntrospectionException {
ExtendedBeanInfo.PropertyDescriptorComparator c = new ExtendedBeanInfo.PropertyDescriptorComparator();
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("a", null, null)), equalTo(0));
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("abc", null, null)), equalTo(0));
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("b", null, null)), lessThan(0));
assertThat(c.compare(new PropertyDescriptor("b", null, null), new PropertyDescriptor("a", null, null)), greaterThan(0));
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("abd", null, null)), lessThan(0));
assertThat(c.compare(new PropertyDescriptor("xyz", null, null), new PropertyDescriptor("123", null, null)), greaterThan(0));
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("abc", null, null)), lessThan(0));
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("a", null, null)), greaterThan(0));
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("b", null, null)), lessThan(0));
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("a", null, null))).isEqualTo(0);
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("abc", null, null))).isEqualTo(0);
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("b", null, null))).isLessThan(0);
assertThat(c.compare(new PropertyDescriptor("b", null, null), new PropertyDescriptor("a", null, null))).isGreaterThan(0);
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("abd", null, null))).isLessThan(0);
assertThat(c.compare(new PropertyDescriptor("xyz", null, null), new PropertyDescriptor("123", null, null))).isGreaterThan(0);
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("abc", null, null))).isLessThan(0);
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("a", null, null))).isGreaterThan(0);
assertThat(c.compare(new PropertyDescriptor("abc", null, null), new PropertyDescriptor("b", null, null))).isLessThan(0);
assertThat(c.compare(new PropertyDescriptor(" ", null, null), new PropertyDescriptor("a", null, null)), lessThan(0));
assertThat(c.compare(new PropertyDescriptor("1", null, null), new PropertyDescriptor("a", null, null)), lessThan(0));
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("A", null, null)), greaterThan(0));
assertThat(c.compare(new PropertyDescriptor(" ", null, null), new PropertyDescriptor("a", null, null))).isLessThan(0);
assertThat(c.compare(new PropertyDescriptor("1", null, null), new PropertyDescriptor("a", null, null))).isLessThan(0);
assertThat(c.compare(new PropertyDescriptor("a", null, null), new PropertyDescriptor("A", null, null))).isGreaterThan(0);
}
@Test
@@ -830,11 +825,11 @@ public class ExtendedBeanInfoTests {
// helps out here, and is now put into use in ExtendedBeanInfo as well.
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertThat(hasReadMethodForProperty(bi, "targetMethod"), is(true));
assertThat(hasWriteMethodForProperty(bi, "targetMethod"), is(false));
assertThat(hasReadMethodForProperty(bi, "targetMethod")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "targetMethod")).isFalse();
assertThat(hasReadMethodForProperty(ebi, "targetMethod"), is(true));
assertThat(hasWriteMethodForProperty(ebi, "targetMethod"), is(false));
assertThat(hasReadMethodForProperty(ebi, "targetMethod")).isTrue();
assertThat(hasWriteMethodForProperty(ebi, "targetMethod")).isFalse();
}
@Test
@@ -864,27 +859,27 @@ public class ExtendedBeanInfoTests {
public void shouldSupportStaticWriteMethod() throws IntrospectionException {
{
BeanInfo bi = Introspector.getBeanInfo(WithStaticWriteMethod.class);
assertThat(hasReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasWriteMethodForProperty(bi, "prop1"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1"), is(false));
assertThat(hasReadMethodForProperty(bi, "prop1")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "prop1")).isFalse();
assertThat(hasIndexedReadMethodForProperty(bi, "prop1")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1")).isFalse();
}
{
BeanInfo bi = new ExtendedBeanInfo(Introspector.getBeanInfo(WithStaticWriteMethod.class));
assertThat(hasReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasWriteMethodForProperty(bi, "prop1"), is(true));
assertThat(hasIndexedReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1"), is(false));
assertThat(hasReadMethodForProperty(bi, "prop1")).isFalse();
assertThat(hasWriteMethodForProperty(bi, "prop1")).isTrue();
assertThat(hasIndexedReadMethodForProperty(bi, "prop1")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1")).isFalse();
}
}
@Test // SPR-12434
public void shouldDetectValidPropertiesAndIgnoreInvalidProperties() throws IntrospectionException {
BeanInfo bi = new ExtendedBeanInfo(Introspector.getBeanInfo(java.awt.Window.class));
assertThat(hasReadMethodForProperty(bi, "locationByPlatform"), is(true));
assertThat(hasWriteMethodForProperty(bi, "locationByPlatform"), is(true));
assertThat(hasIndexedReadMethodForProperty(bi, "locationByPlatform"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "locationByPlatform"), is(false));
assertThat(hasReadMethodForProperty(bi, "locationByPlatform")).isTrue();
assertThat(hasWriteMethodForProperty(bi, "locationByPlatform")).isTrue();
assertThat(hasIndexedReadMethodForProperty(bi, "locationByPlatform")).isFalse();
assertThat(hasIndexedWriteMethodForProperty(bi, "locationByPlatform")).isFalse();
}

View File

@@ -20,10 +20,8 @@ import java.util.Iterator;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -138,17 +136,17 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("foo", "bar");
assertThat(pvs.stream(), notNullValue());
assertThat(pvs.stream().count(), is(1L));
assertThat(pvs.stream().anyMatch(pv -> "foo".equals(pv.getName()) && "bar".equals(pv.getValue())), is(true));
assertThat(pvs.stream().anyMatch(pv -> "bar".equals(pv.getName()) && "foo".equals(pv.getValue())), is(false));
assertThat(pvs.stream()).isNotNull();
assertThat(pvs.stream().count()).isEqualTo(1L);
assertThat(pvs.stream().anyMatch(pv -> "foo".equals(pv.getName()) && "bar".equals(pv.getValue()))).isTrue();
assertThat(pvs.stream().anyMatch(pv -> "bar".equals(pv.getName()) && "foo".equals(pv.getValue()))).isFalse();
}
@Test
public void streamIsEmptyForEmptyValues() {
MutablePropertyValues pvs = new MutablePropertyValues();
assertThat(pvs.stream(), notNullValue());
assertThat(pvs.stream().count(), is(0L));
assertThat(pvs.stream()).isNotNull();
assertThat(pvs.stream().count()).isEqualTo(0L);
}
}

View File

@@ -18,11 +18,12 @@ package org.springframework.beans;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyArray;
import static org.hamcrest.Matchers.hasItemInArray;
import static org.hamcrest.Matchers.not;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link PropertyMatches}.
@@ -34,93 +35,93 @@ public class PropertyMatchesTests {
@Test
public void simpleBeanPropertyTypo() {
PropertyMatches matches = PropertyMatches.forProperty("naem", SampleBeanProperties.class);
assertThat(matches.getPossibleMatches(), hasItemInArray("name"));
assertThat(matches.getPossibleMatches()).contains("name");
}
@Test
public void complexBeanPropertyTypo() {
PropertyMatches matches = PropertyMatches.forProperty("desriptn", SampleBeanProperties.class);
assertThat(matches.getPossibleMatches(), emptyArray());
assertThat(matches.getPossibleMatches()).isEmpty();
}
@Test
public void unknownBeanProperty() {
PropertyMatches matches = PropertyMatches.forProperty("unknown", SampleBeanProperties.class);
assertThat(matches.getPossibleMatches(), emptyArray());
assertThat(matches.getPossibleMatches()).isEmpty();
}
@Test
public void severalMatchesBeanProperty() {
PropertyMatches matches = PropertyMatches.forProperty("counter", SampleBeanProperties.class);
assertThat(matches.getPossibleMatches(), hasItemInArray("counter1"));
assertThat(matches.getPossibleMatches(), hasItemInArray("counter2"));
assertThat(matches.getPossibleMatches(), hasItemInArray("counter3"));
assertThat(matches.getPossibleMatches()).contains("counter1");
assertThat(matches.getPossibleMatches()).contains("counter2");
assertThat(matches.getPossibleMatches()).contains("counter3");
}
@Test
public void simpleBeanPropertyErrorMessage() {
PropertyMatches matches = PropertyMatches.forProperty("naem", SampleBeanProperties.class);
String msg = matches.buildErrorMessage();
assertThat(msg, containsString("naem"));
assertThat(msg, containsString("name"));
assertThat(msg, containsString("setter"));
assertThat(msg, not(containsString("field")));
assertThat(msg).contains("naem");
assertThat(msg).contains("name");
assertThat(msg).contains("setter");
assertThat(msg).doesNotContain("field");
}
@Test
public void complexBeanPropertyErrorMessage() {
PropertyMatches matches = PropertyMatches.forProperty("counter", SampleBeanProperties.class);
String msg = matches.buildErrorMessage();
assertThat(msg, containsString("counter"));
assertThat(msg, containsString("counter1"));
assertThat(msg, containsString("counter2"));
assertThat(msg, containsString("counter3"));
assertThat(msg).contains("counter");
assertThat(msg).contains("counter1");
assertThat(msg).contains("counter2");
assertThat(msg).contains("counter3");
}
@Test
public void simpleFieldPropertyTypo() {
PropertyMatches matches = PropertyMatches.forField("naem", SampleFieldProperties.class);
assertThat(matches.getPossibleMatches(), hasItemInArray("name"));
assertThat(matches.getPossibleMatches()).contains("name");
}
@Test
public void complexFieldPropertyTypo() {
PropertyMatches matches = PropertyMatches.forField("desriptn", SampleFieldProperties.class);
assertThat(matches.getPossibleMatches(), emptyArray());
assertThat(matches.getPossibleMatches()).isEmpty();
}
@Test
public void unknownFieldProperty() {
PropertyMatches matches = PropertyMatches.forField("unknown", SampleFieldProperties.class);
assertThat(matches.getPossibleMatches(), emptyArray());
assertThat(matches.getPossibleMatches()).isEmpty();
}
@Test
public void severalMatchesFieldProperty() {
PropertyMatches matches = PropertyMatches.forField("counter", SampleFieldProperties.class);
assertThat(matches.getPossibleMatches(), hasItemInArray("counter1"));
assertThat(matches.getPossibleMatches(), hasItemInArray("counter2"));
assertThat(matches.getPossibleMatches(), hasItemInArray("counter3"));
assertThat(matches.getPossibleMatches()).contains("counter1");
assertThat(matches.getPossibleMatches()).contains("counter2");
assertThat(matches.getPossibleMatches()).contains("counter3");
}
@Test
public void simpleFieldPropertyErrorMessage() {
PropertyMatches matches = PropertyMatches.forField("naem", SampleFieldProperties.class);
String msg = matches.buildErrorMessage();
assertThat(msg, containsString("naem"));
assertThat(msg, containsString("name"));
assertThat(msg, containsString("field"));
assertThat(msg, not(containsString("setter")));
assertThat(msg).contains("naem");
assertThat(msg).contains("name");
assertThat(msg).contains("field");
assertThat(msg).doesNotContain("setter");
}
@Test
public void complexFieldPropertyErrorMessage() {
PropertyMatches matches = PropertyMatches.forField("counter", SampleFieldProperties.class);
String msg = matches.buildErrorMessage();
assertThat(msg, containsString("counter"));
assertThat(msg, containsString("counter1"));
assertThat(msg, containsString("counter2"));
assertThat(msg, containsString("counter3"));
assertThat(msg).contains("counter");
assertThat(msg).contains("counter1");
assertThat(msg).contains("counter2");
assertThat(msg).contains("counter3");
}

View File

@@ -23,11 +23,8 @@ import java.lang.reflect.Method;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Chris Beams
@@ -39,8 +36,8 @@ public class SimplePropertyDescriptorTests {
public void toStringOutput() throws IntrospectionException, SecurityException, NoSuchMethodException {
{
Object pd = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", null, null);
assertThat(pd.toString(), containsString(
"PropertyDescriptor[name=foo, propertyType=null, readMethod=null"));
assertThat(pd.toString()).contains(
"PropertyDescriptor[name=foo, propertyType=null, readMethod=null");
}
{
class C {
@@ -49,15 +46,15 @@ public class SimplePropertyDescriptorTests {
}
Method m = C.class.getMethod("setFoo", String.class);
Object pd = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", null, m);
assertThat(pd.toString(), allOf(
containsString("PropertyDescriptor[name=foo"),
containsString("propertyType=class java.lang.String"),
containsString("readMethod=null, writeMethod=public java.lang.Object")));
assertThat(pd.toString()).contains(
"PropertyDescriptor[name=foo",
"propertyType=class java.lang.String",
"readMethod=null, writeMethod=public java.lang.Object");
}
{
Object pd = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, null);
assertThat(pd.toString(), containsString(
"PropertyDescriptor[name=foo, propertyType=null, indexedPropertyType=null"));
assertThat(pd.toString()).contains(
"PropertyDescriptor[name=foo, propertyType=null, indexedPropertyType=null");
}
{
class C {
@@ -66,21 +63,21 @@ public class SimplePropertyDescriptorTests {
}
Method m = C.class.getMethod("setFoo", int.class, String.class);
Object pd = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, m);
assertThat(pd.toString(), allOf(
containsString("PropertyDescriptor[name=foo, propertyType=null"),
containsString("indexedPropertyType=class java.lang.String"),
containsString("indexedWriteMethod=public java.lang.Object")));
assertThat(pd.toString()).contains(
"PropertyDescriptor[name=foo, propertyType=null",
"indexedPropertyType=class java.lang.String",
"indexedWriteMethod=public java.lang.Object");
}
}
@Test
public void nonIndexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException {
Object pd1 = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", null, null);
assertThat(pd1, equalTo(pd1));
assertThat(pd1).isEqualTo(pd1);
Object pd2 = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", null, null);
assertThat(pd1, equalTo(pd2));
assertThat(pd2, equalTo(pd1));
assertThat(pd1).isEqualTo(pd2);
assertThat(pd2).isEqualTo(pd1);
@SuppressWarnings("unused")
class C {
@@ -89,35 +86,35 @@ public class SimplePropertyDescriptorTests {
}
Method wm1 = C.class.getMethod("setFoo", String.class);
Object pd3 = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", null, wm1);
assertThat(pd1, not(equalTo(pd3)));
assertThat(pd3, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd3);
assertThat(pd3).isNotEqualTo(pd1);
Method rm1 = C.class.getMethod("getFoo");
Object pd4 = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", rm1, null);
assertThat(pd1, not(equalTo(pd4)));
assertThat(pd4, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd4);
assertThat(pd4).isNotEqualTo(pd1);
Object pd5 = new PropertyDescriptor("foo", null, null);
assertThat(pd1, equalTo(pd5));
assertThat(pd5, equalTo(pd1));
assertThat(pd1).isEqualTo(pd5);
assertThat(pd5).isEqualTo(pd1);
Object pd6 = "not a PD";
assertThat(pd1, not(equalTo(pd6)));
assertThat(pd6, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd6);
assertThat(pd6).isNotEqualTo(pd1);
Object pd7 = null;
assertThat(pd1, not(equalTo(pd7)));
assertThat(pd7, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd7);
assertThat(pd7).isNotEqualTo(pd1);
}
@Test
public void indexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException {
Object pd1 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, null);
assertThat(pd1, equalTo(pd1));
assertThat(pd1).isEqualTo(pd1);
Object pd2 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, null);
assertThat(pd1, equalTo(pd2));
assertThat(pd2, equalTo(pd1));
assertThat(pd1).isEqualTo(pd2);
assertThat(pd2).isEqualTo(pd1);
@SuppressWarnings("unused")
class C {
@@ -126,25 +123,25 @@ public class SimplePropertyDescriptorTests {
}
Method wm1 = C.class.getMethod("setFoo", int.class, String.class);
Object pd3 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, wm1);
assertThat(pd1, not(equalTo(pd3)));
assertThat(pd3, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd3);
assertThat(pd3).isNotEqualTo(pd1);
Method rm1 = C.class.getMethod("getFoo", int.class);
Object pd4 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, rm1, null);
assertThat(pd1, not(equalTo(pd4)));
assertThat(pd4, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd4);
assertThat(pd4).isNotEqualTo(pd1);
Object pd5 = new IndexedPropertyDescriptor("foo", null, null, null, null);
assertThat(pd1, equalTo(pd5));
assertThat(pd5, equalTo(pd1));
assertThat(pd1).isEqualTo(pd5);
assertThat(pd5).isEqualTo(pd1);
Object pd6 = "not a PD";
assertThat(pd1, not(equalTo(pd6)));
assertThat(pd6, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd6);
assertThat(pd6).isNotEqualTo(pd1);
Object pd7 = null;
assertThat(pd1, not(equalTo(pd7)));
assertThat(pd7, not(equalTo(pd1)));
assertThat(pd1).isNotEqualTo(pd7);
assertThat(pd7).isNotEqualTo(pd1);
}
}

View File

@@ -103,8 +103,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -1380,7 +1378,7 @@ public class DefaultListableBeanFactoryTests {
parent.registerBeanDefinition("bd1", bd1);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(parent);
TestBean bean = lbf.getBean(TestBean.class);
assertThat(bean.getBeanName(), equalTo("bd1"));
assertThat(bean.getBeanName()).isEqualTo("bd1");
}
@Test
@@ -1404,7 +1402,7 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd1", bd1);
lbf.registerBeanDefinition("bd2", bd2);
TestBean bean = lbf.getBean(TestBean.class);
assertThat(bean.getBeanName(), equalTo("bd2"));
assertThat(bean.getBeanName()).isEqualTo("bd2");
assertFalse(lbf.containsSingleton("bd1"));
}
@@ -1453,7 +1451,7 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd3", bd3);
lbf.preInstantiateSingletons();
TestBean bean = lbf.getBean(TestBean.class);
assertThat(bean.getBeanName(), equalTo("bd1"));
assertThat(bean.getBeanName()).isEqualTo("bd1");
}
@Test
@@ -1470,7 +1468,7 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd4", bd4);
lbf.preInstantiateSingletons();
TestBean bean = lbf.getBean(TestBeanRecipient.class).testBean;
assertThat(bean.getBeanName(), equalTo("bd1"));
assertThat(bean.getBeanName()).isEqualTo("bd1");
}
@Test
@@ -1496,7 +1494,7 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd1", bd1);
lbf.registerBeanDefinition("bd2", bd2);
TestBean bean = lbf.getBean(TestBean.class);
assertThat(bean.getBeanName(), equalTo("bd1"));
assertThat(bean.getBeanName()).isEqualTo("bd1");
}
@Test
@@ -1509,7 +1507,7 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd1", bd1);
lbf.registerBeanDefinition("bd2", bd2);
TestBean bean = lbf.getBean(TestBean.class);
assertThat(bean.getBeanName(), equalTo("bd2"));
assertThat(bean.getBeanName()).isEqualTo("bd2");
}
@Test
@@ -1554,25 +1552,25 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(parent);
ConstructorDependency bean = lbf.getBean(ConstructorDependency.class);
assertThat(bean.beanName, equalTo("bd1"));
assertThat(bean.spouseAge, equalTo(99));
assertThat(bean.beanName).isEqualTo("bd1");
assertThat(bean.spouseAge).isEqualTo(99);
bean = lbf.getBean(ConstructorDependency.class, 42);
assertThat(bean.beanName, equalTo("bd1"));
assertThat(bean.spouseAge, equalTo(42));
assertThat(bean.beanName).isEqualTo("bd1");
assertThat(bean.spouseAge).isEqualTo(42);
ObjectProvider<ConstructorDependency> provider = lbf.getBeanProvider(ConstructorDependency.class);
bean = provider.getObject();
assertThat(bean.beanName, equalTo("bd1"));
assertThat(bean.spouseAge, equalTo(99));
assertThat(bean.beanName).isEqualTo("bd1");
assertThat(bean.spouseAge).isEqualTo(99);
bean = provider.getObject(42);
assertThat(bean.beanName, equalTo("bd1"));
assertThat(bean.spouseAge, equalTo(42));
assertThat(bean.beanName).isEqualTo("bd1");
assertThat(bean.spouseAge).isEqualTo(42);
bean = provider.getIfAvailable();
assertThat(bean.beanName, equalTo("bd1"));
assertThat(bean.spouseAge, equalTo(99));
assertThat(bean.beanName).isEqualTo("bd1");
assertThat(bean.spouseAge).isEqualTo(99);
bean = provider.getIfUnique();
assertThat(bean.beanName, equalTo("bd1"));
assertThat(bean.spouseAge, equalTo(99));
assertThat(bean.beanName).isEqualTo("bd1");
assertThat(bean.spouseAge).isEqualTo(99);
}
@Test
@@ -1627,25 +1625,25 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd2", bd2);
ConstructorDependency bean = lbf.getBean(ConstructorDependency.class);
assertThat(bean.beanName, equalTo("bd2"));
assertThat(bean.spouseAge, equalTo(43));
assertThat(bean.beanName).isEqualTo("bd2");
assertThat(bean.spouseAge).isEqualTo(43);
bean = lbf.getBean(ConstructorDependency.class, 42);
assertThat(bean.beanName, equalTo("bd2"));
assertThat(bean.spouseAge, equalTo(42));
assertThat(bean.beanName).isEqualTo("bd2");
assertThat(bean.spouseAge).isEqualTo(42);
ObjectProvider<ConstructorDependency> provider = lbf.getBeanProvider(ConstructorDependency.class);
bean = provider.getObject();
assertThat(bean.beanName, equalTo("bd2"));
assertThat(bean.spouseAge, equalTo(43));
assertThat(bean.beanName).isEqualTo("bd2");
assertThat(bean.spouseAge).isEqualTo(43);
bean = provider.getObject(42);
assertThat(bean.beanName, equalTo("bd2"));
assertThat(bean.spouseAge, equalTo(42));
assertThat(bean.beanName).isEqualTo("bd2");
assertThat(bean.spouseAge).isEqualTo(42);
bean = provider.getIfAvailable();
assertThat(bean.beanName, equalTo("bd2"));
assertThat(bean.spouseAge, equalTo(43));
assertThat(bean.beanName).isEqualTo("bd2");
assertThat(bean.spouseAge).isEqualTo(43);
bean = provider.getIfUnique();
assertThat(bean.beanName, equalTo("bd2"));
assertThat(bean.spouseAge, equalTo(43));
assertThat(bean.beanName).isEqualTo("bd2");
assertThat(bean.spouseAge).isEqualTo(43);
Set<Object> resolved = new HashSet<>();
for (ConstructorDependency instance : provider) {
@@ -1693,7 +1691,7 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd1", bd1);
lbf.registerBeanDefinition("na1", na1);
ConstructorDependency actual = lbf.getBean(ConstructorDependency.class, 42); // na1 was filtered
assertThat(actual.beanName, equalTo("bd1"));
assertThat(actual.beanName).isEqualTo("bd1");
lbf.registerBeanDefinition("bd2", bd2);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
@@ -1727,8 +1725,8 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("bd2", bd2);
ConstructorDependency bean = lbf.getBean(ConstructorDependency.class, 42);
assertThat(bean.beanName, equalTo("bd1"));
assertThat(bean.spouseAge, equalTo(42));
assertThat(bean.beanName).isEqualTo("bd1");
assertThat(bean.spouseAge).isEqualTo(42);
assertEquals(1, lbf.getBeanNamesForType(ConstructorDependency.class).length);
assertEquals(1, lbf.getBeanNamesForType(ConstructorDependencyFactoryBean.class).length);
@@ -1902,7 +1900,7 @@ public class DefaultListableBeanFactoryTests {
DependenciesBean bean = (DependenciesBean)
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(bean.getSpouse(), equalTo(lbf.getBean("test")));
assertThat(bean.getSpouse()).isEqualTo(lbf.getBean("test"));
}
@Test
@@ -1930,7 +1928,7 @@ public class DefaultListableBeanFactoryTests {
DependenciesBean bean = (DependenciesBean)
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(bean.getSpouse(), equalTo(lbf.getBean("test")));
assertThat(bean.getSpouse()).isEqualTo(lbf.getBean("test"));
}
@Test
@@ -1959,7 +1957,7 @@ public class DefaultListableBeanFactoryTests {
DependenciesBean bean = (DependenciesBean)
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(bean.getSpouse(), equalTo(lbf.getBean("spouse")));
assertThat(bean.getSpouse()).isEqualTo(lbf.getBean("spouse"));
}
@Test
@@ -2768,8 +2766,8 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("abs", BeanDefinitionBuilder
.rootBeanDefinition(TestBean.class).setAbstract(true).getBeanDefinition());
assertThat(bf.containsBean("abs"), equalTo(true));
assertThat(bf.containsBean("bogus"), equalTo(false));
assertThat(bf.containsBean("abs")).isEqualTo(true);
assertThat(bf.containsBean("bogus")).isEqualTo(false);
}
@Test

View File

@@ -25,8 +25,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/**
@@ -47,7 +46,7 @@ public class FactoryBeanLookupTests {
@Test
public void factoryBeanLookupByNameDereferencing() {
Object fooFactory = beanFactory.getBean("&fooFactory");
assertThat(fooFactory, instanceOf(FooFactoryBean.class));
assertThat(fooFactory).isInstanceOf(FooFactoryBean.class);
}
@Test
@@ -65,7 +64,7 @@ public class FactoryBeanLookupTests {
@Test
public void factoryBeanObjectLookupByName() {
Object fooFactory = beanFactory.getBean("fooFactory");
assertThat(fooFactory, instanceOf(Foo.class));
assertThat(fooFactory).isInstanceOf(Foo.class);
}
@Test

View File

@@ -28,10 +28,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
import static org.springframework.beans.factory.support.BeanDefinitionReaderUtils.registerWithGeneratedName;
@@ -101,8 +98,8 @@ public class PropertyPlaceholderConfigurerTests {
registerWithGeneratedName(p1BeanDef, bf);
ppc.postProcessBeanFactory(bf);
TestBean bean = bf.getBean(TestBean.class);
assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
assertThat(bean.getSex(), equalTo("systemValue"));
assertThat(bean.getName()).isEqualTo(P1_LOCAL_PROPS_VAL);
assertThat(bean.getSex()).isEqualTo("systemValue");
System.clearProperty("otherKey");
}
@@ -112,7 +109,7 @@ public class PropertyPlaceholderConfigurerTests {
registerWithGeneratedName(p1BeanDef, bf);
ppc.postProcessBeanFactory(bf);
TestBean bean = bf.getBean(TestBean.class);
assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
assertThat(bean.getName()).isEqualTo(P1_LOCAL_PROPS_VAL);
}
@Test
@@ -120,7 +117,7 @@ public class PropertyPlaceholderConfigurerTests {
registerWithGeneratedName(p1BeanDef, bf);
ppc.postProcessBeanFactory(bf);
TestBean bean = bf.getBean(TestBean.class);
assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
assertThat(bean.getName()).isEqualTo(P1_LOCAL_PROPS_VAL);
}
@Test
@@ -129,7 +126,7 @@ public class PropertyPlaceholderConfigurerTests {
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
ppc.postProcessBeanFactory(bf);
TestBean bean = bf.getBean(TestBean.class);
assertThat(bean.getName(), equalTo(P1_SYSTEM_PROPS_VAL));
assertThat(bean.getName()).isEqualTo(P1_SYSTEM_PROPS_VAL);
}
@Test
@@ -140,7 +137,7 @@ public class PropertyPlaceholderConfigurerTests {
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
ppc.postProcessBeanFactory(bf);
TestBean bean = bf.getBean(TestBean.class);
assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL)); // has to resort to local props
assertThat(bean.getName()).isEqualTo(P1_LOCAL_PROPS_VAL); // has to resort to local props
}
/**
@@ -177,11 +174,11 @@ public class PropertyPlaceholderConfigurerTests {
ppc2.postProcessBeanFactory(bf);
TestBean p1Bean = bf.getBean("p1Bean", TestBean.class);
assertThat(p1Bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
assertThat(p1Bean.getName()).isEqualTo(P1_LOCAL_PROPS_VAL);
TestBean p2Bean = bf.getBean("p2Bean", TestBean.class);
assertThat(p2Bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
assertThat(p2Bean.getCountry(), equalTo(P2_SYSTEM_PROPS_VAL));
assertThat(p2Bean.getName()).isEqualTo(P1_LOCAL_PROPS_VAL);
assertThat(p2Bean.getCountry()).isEqualTo(P2_SYSTEM_PROPS_VAL);
System.clearProperty(P2);
}
@@ -205,8 +202,8 @@ public class PropertyPlaceholderConfigurerTests {
System.clearProperty("key1");
System.clearProperty("key2");
assertThat(bf.getBean(TestBean.class).getName(), is("systemKey1Value"));
assertThat(bf.getBean(TestBean.class).getSex(), is("${key2}"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("systemKey1Value");
assertThat(bf.getBean(TestBean.class).getSex()).isEqualTo("${key2}");
}
@Test
@@ -219,7 +216,7 @@ public class PropertyPlaceholderConfigurerTests {
.addPropertyValue("name", "${my.name}")
.getBeanDefinition());
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), nullValue());
assertThat(bf.getBean(TestBean.class).getName()).isNull();
System.clearProperty("my.name");
}
@@ -232,7 +229,7 @@ public class PropertyPlaceholderConfigurerTests {
.addPropertyValue("name", "${my.name}")
.getBeanDefinition());
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo(" myValue "));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo(" myValue ");
System.clearProperty("my.name");
}
@@ -246,7 +243,7 @@ public class PropertyPlaceholderConfigurerTests {
.addPropertyValue("name", "${my.name}")
.getBeanDefinition());
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("myValue"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("myValue");
System.clearProperty("my.name");
}

View File

@@ -30,11 +30,12 @@ import org.springframework.beans.factory.config.YamlProcessor.ResolutionMethod;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
/**
* Tests for {@link YamlPropertiesFactoryBean}.
@@ -50,8 +51,8 @@ public class YamlPropertiesFactoryBeanTests {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bar"));
assertThat(properties.getProperty("spam.foo"), equalTo("baz"));
assertThat(properties.getProperty("foo")).isEqualTo("bar");
assertThat(properties.getProperty("spam.foo")).isEqualTo("baz");
}
@Test
@@ -71,9 +72,9 @@ public class YamlPropertiesFactoryBeanTests {
new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes()),
new ByteArrayResource("foo:\n bar: spam".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bar"));
assertThat(properties.getProperty("spam.foo"), equalTo("baz"));
assertThat(properties.getProperty("foo.bar"), equalTo("spam"));
assertThat(properties.getProperty("foo")).isEqualTo("bar");
assertThat(properties.getProperty("spam.foo")).isEqualTo("baz");
assertThat(properties.getProperty("foo.bar")).isEqualTo("spam");
}
@Test
@@ -100,8 +101,8 @@ public class YamlPropertiesFactoryBeanTests {
factory.setResources(new ByteArrayResource(
"foo: bar\nspam: baz\n---\nfoo: bag".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("baz"));
assertThat(properties.getProperty("foo")).isEqualTo("bag");
assertThat(properties.getProperty("spam")).isEqualTo("baz");
}
@Test
@@ -112,8 +113,8 @@ public class YamlPropertiesFactoryBeanTests {
factory.setDocumentMatchers(properties -> ("bag".equals(properties.getProperty("foo")) ?
MatchStatus.FOUND : MatchStatus.NOT_FOUND));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
assertThat(properties.getProperty("foo")).isEqualTo("bag");
assertThat(properties.getProperty("spam")).isEqualTo("bad");
}
@Test
@@ -130,9 +131,9 @@ public class YamlPropertiesFactoryBeanTests {
MatchStatus.FOUND : MatchStatus.NOT_FOUND);
});
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
assertThat(properties.getProperty("one"), equalTo("two"));
assertThat(properties.getProperty("foo")).isEqualTo("bag");
assertThat(properties.getProperty("spam")).isEqualTo("bad");
assertThat(properties.getProperty("one")).isEqualTo("two");
}
@Test
@@ -152,9 +153,9 @@ public class YamlPropertiesFactoryBeanTests {
}
});
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
assertThat(properties.getProperty("one"), nullValue());
assertThat(properties.getProperty("foo")).isEqualTo("bag");
assertThat(properties.getProperty("spam")).isEqualTo("bad");
assertThat(properties.getProperty("one")).isNull();
}
@Test
@@ -171,9 +172,9 @@ public class YamlPropertiesFactoryBeanTests {
MatchStatus.FOUND : MatchStatus.NOT_FOUND);
});
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bag"));
assertThat(properties.getProperty("spam"), equalTo("bad"));
assertThat(properties.getProperty("one"), equalTo("two"));
assertThat(properties.getProperty("foo")).isEqualTo("bag");
assertThat(properties.getProperty("spam")).isEqualTo("bad");
assertThat(properties.getProperty("one")).isEqualTo("two");
}
@Test
@@ -182,7 +183,7 @@ public class YamlPropertiesFactoryBeanTests {
factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE);
factory.setResources(new ClassPathResource("no-such-file.yml"));
Properties properties = factory.getObject();
assertThat(properties.size(), equalTo(0));
assertThat(properties.size()).isEqualTo(0);
}
@Test
@@ -190,8 +191,8 @@ public class YamlPropertiesFactoryBeanTests {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo: bar\nspam:".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo"), equalTo("bar"));
assertThat(properties.getProperty("spam"), equalTo(""));
assertThat(properties.getProperty("foo")).isEqualTo("bar");
assertThat(properties.getProperty("spam")).isEqualTo("");
}
@Test
@@ -199,8 +200,8 @@ public class YamlPropertiesFactoryBeanTests {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("a: alpha\ntest: []".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("a"), equalTo("alpha"));
assertThat(properties.getProperty("test"), equalTo(""));
assertThat(properties.getProperty("a")).isEqualTo("alpha");
assertThat(properties.getProperty("test")).isEqualTo("");
}
@Test
@@ -208,9 +209,9 @@ public class YamlPropertiesFactoryBeanTests {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo:\n- bar\n- baz".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo[0]"), equalTo("bar"));
assertThat(properties.getProperty("foo[1]"), equalTo("baz"));
assertThat(properties.get("foo"), is(nullValue()));
assertThat(properties.getProperty("foo[0]")).isEqualTo("bar");
assertThat(properties.getProperty("foo[1]")).isEqualTo("baz");
assertThat(properties.get("foo")).isNull();
}
@Test
@@ -218,9 +219,9 @@ public class YamlPropertiesFactoryBeanTests {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(new ByteArrayResource("foo:\n- 1\n- 2".getBytes()));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo[0]"), equalTo("1"));
assertThat(properties.getProperty("foo[1]"), equalTo("2"));
assertThat(properties.get("foo"), is(nullValue()));
assertThat(properties.getProperty("foo[0]")).isEqualTo("1");
assertThat(properties.getProperty("foo[1]")).isEqualTo("2");
assertThat(properties.get("foo")).isNull();
}
@Test
@@ -230,11 +231,11 @@ public class YamlPropertiesFactoryBeanTests {
"foo:\n- bar:\n spam: crap\n- baz\n- one: two\n three: four".getBytes()
));
Properties properties = factory.getObject();
assertThat(properties.getProperty("foo[0].bar.spam"), equalTo("crap"));
assertThat(properties.getProperty("foo[1]"), equalTo("baz"));
assertThat(properties.getProperty("foo[2].one"), equalTo("two"));
assertThat(properties.getProperty("foo[2].three"), equalTo("four"));
assertThat(properties.get("foo"), is(nullValue()));
assertThat(properties.getProperty("foo[0].bar.spam")).isEqualTo("crap");
assertThat(properties.getProperty("foo[1]")).isEqualTo("baz");
assertThat(properties.getProperty("foo[2].one")).isEqualTo("two");
assertThat(properties.getProperty("foo[2].three")).isEqualTo("four");
assertThat(properties.get("foo")).isNull();
}
@SuppressWarnings("unchecked")
@@ -242,8 +243,8 @@ public class YamlPropertiesFactoryBeanTests {
public void testYaml() {
Yaml yaml = new Yaml();
Map<String, ?> map = yaml.loadAs("foo: bar\nspam:\n foo: baz", Map.class);
assertThat(map.get("foo"), equalTo("bar"));
assertThat(((Map<String, Object>) map.get("spam")).get("foo"), equalTo("baz"));
assertThat(map.get("foo")).isEqualTo("bar");
assertThat(((Map<String, Object>) map.get("spam")).get("foo")).isEqualTo("baz");
}
}

View File

@@ -26,11 +26,8 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for SPR-8954, in which a custom {@link InstantiationAwareBeanPostProcessor}
@@ -56,32 +53,32 @@ public class Spr8954Tests {
@Test
public void repro() {
assertThat(bf.getBean("foo"), instanceOf(Foo.class));
assertThat(bf.getBean("&foo"), instanceOf(FooFactoryBean.class));
assertThat(bf.isTypeMatch("&foo", FactoryBean.class), is(true));
assertThat(bf.getBean("foo")).isInstanceOf(Foo.class);
assertThat(bf.getBean("&foo")).isInstanceOf(FooFactoryBean.class);
assertThat(bf.isTypeMatch("&foo", FactoryBean.class)).isTrue();
@SuppressWarnings("rawtypes")
Map<String, FactoryBean> fbBeans = bf.getBeansOfType(FactoryBean.class);
assertThat(fbBeans.size(), is(1));
assertThat(fbBeans.keySet(), hasItem("&foo"));
assertThat(fbBeans).hasSize(1);
assertThat(fbBeans.keySet()).contains("&foo");
Map<String, AnInterface> aiBeans = bf.getBeansOfType(AnInterface.class);
assertThat(aiBeans.size(), is(1));
assertThat(aiBeans.keySet(), hasItem("&foo"));
assertThat(aiBeans).hasSize(1);
assertThat(aiBeans.keySet()).contains("&foo");
}
@Test
public void findsBeansByTypeIfNotInstantiated() {
assertThat(bf.isTypeMatch("&foo", FactoryBean.class), is(true));
assertThat(bf.isTypeMatch("&foo", FactoryBean.class)).isTrue();
@SuppressWarnings("rawtypes")
Map<String, FactoryBean> fbBeans = bf.getBeansOfType(FactoryBean.class);
assertThat(1, equalTo(fbBeans.size()));
assertThat("&foo", equalTo(fbBeans.keySet().iterator().next()));
assertThat(1).isEqualTo(fbBeans.size());
assertThat("&foo").isEqualTo(fbBeans.keySet().iterator().next());
Map<String, AnInterface> aiBeans = bf.getBeansOfType(AnInterface.class);
assertThat(aiBeans.size(), is(1));
assertThat(aiBeans.keySet(), hasItem("&foo"));
assertThat(aiBeans).hasSize(1);
assertThat(aiBeans.keySet()).contains("&foo");
}
/**
@@ -90,11 +87,11 @@ public class Spr8954Tests {
@Test
public void findsFactoryBeanNameByTypeWithoutInstantiation() {
String[] names = bf.getBeanNamesForType(AnInterface.class, false, false);
assertThat(Arrays.asList(names), hasItem("&foo"));
assertThat(Arrays.asList(names)).contains("&foo");
Map<String, AnInterface> beans = bf.getBeansOfType(AnInterface.class, false, false);
assertThat(beans.size(), is(1));
assertThat(beans.keySet(), hasItem("&foo"));
assertThat(beans).hasSize(1);
assertThat(beans.keySet()).contains("&foo");
}

View File

@@ -22,9 +22,9 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* With Spring 3.1, bean id attributes (and all other id attributes across the
@@ -56,6 +56,6 @@ public class DuplicateBeanIdTests {
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
reader.loadBeanDefinitions(new ClassPathResource("DuplicateBeanIdTests-multiLevel-context.xml", this.getClass()));
TestBean testBean = bf.getBean(TestBean.class); // there should be only one
assertThat(testBean.getName(), equalTo("nested"));
assertThat(testBean.getName()).isEqualTo("nested");
}
}

View File

@@ -23,10 +23,9 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for propagating enclosing beans element defaults to nested beans elements.
@@ -62,11 +61,11 @@ public class NestedBeansElementAttributeRecursionTests {
BeanDefinition biz = bf.getBeanDefinition("biz");
BeanDefinition buz = bf.getBeanDefinition("buz");
assertThat(foo.isLazyInit(), is(false));
assertThat(bar.isLazyInit(), is(true));
assertThat(baz.isLazyInit(), is(false));
assertThat(biz.isLazyInit(), is(true));
assertThat(buz.isLazyInit(), is(true));
assertThat(foo.isLazyInit()).isFalse();
assertThat(bar.isLazyInit()).isTrue();
assertThat(baz.isLazyInit()).isFalse();
assertThat(biz.isLazyInit()).isTrue();
assertThat(buz.isLazyInit()).isTrue();
}
@Test
@@ -95,19 +94,19 @@ public class NestedBeansElementAttributeRecursionTests {
private void assertMerge(DefaultListableBeanFactory bf) {
TestBean topLevel = bf.getBean("topLevelConcreteTestBean", TestBean.class);
// has the concrete child bean values
assertThat((Iterable<String>) topLevel.getSomeList(), hasItems("charlie", "delta"));
assertThat((Iterable<String>) topLevel.getSomeList()).contains("charlie", "delta");
// but does not merge the parent values
assertThat((Iterable<String>) topLevel.getSomeList(), not(hasItems("alpha", "bravo")));
assertThat((Iterable<String>) topLevel.getSomeList()).doesNotContain("alpha", "bravo");
TestBean firstLevel = bf.getBean("firstLevelNestedTestBean", TestBean.class);
// merges all values
assertThat((Iterable<String>) firstLevel.getSomeList(),
hasItems("charlie", "delta", "echo", "foxtrot"));
assertThat((Iterable<String>) firstLevel.getSomeList()).contains(
"charlie", "delta", "echo", "foxtrot");
TestBean secondLevel = bf.getBean("secondLevelNestedTestBean", TestBean.class);
// merges all values
assertThat((Iterable<String>)secondLevel.getSomeList(),
hasItems("charlie", "delta", "echo", "foxtrot", "golf", "hotel"));
assertThat((Iterable<String>)secondLevel.getSomeList()).contains(
"charlie", "delta", "echo", "foxtrot", "golf", "hotel");
}
@Test
@@ -131,23 +130,23 @@ public class NestedBeansElementAttributeRecursionTests {
}
private void assertAutowireCandidates(DefaultListableBeanFactory bf) {
assertThat(bf.getBeanDefinition("fooService").isAutowireCandidate(), is(true));
assertThat(bf.getBeanDefinition("fooRepository").isAutowireCandidate(), is(true));
assertThat(bf.getBeanDefinition("other").isAutowireCandidate(), is(false));
assertThat(bf.getBeanDefinition("fooService").isAutowireCandidate()).isTrue();
assertThat(bf.getBeanDefinition("fooRepository").isAutowireCandidate()).isTrue();
assertThat(bf.getBeanDefinition("other").isAutowireCandidate()).isFalse();
assertThat(bf.getBeanDefinition("barService").isAutowireCandidate(), is(true));
assertThat(bf.getBeanDefinition("fooController").isAutowireCandidate(), is(false));
assertThat(bf.getBeanDefinition("barService").isAutowireCandidate()).isTrue();
assertThat(bf.getBeanDefinition("fooController").isAutowireCandidate()).isFalse();
assertThat(bf.getBeanDefinition("bizRepository").isAutowireCandidate(), is(true));
assertThat(bf.getBeanDefinition("bizService").isAutowireCandidate(), is(false));
assertThat(bf.getBeanDefinition("bizRepository").isAutowireCandidate()).isTrue();
assertThat(bf.getBeanDefinition("bizService").isAutowireCandidate()).isFalse();
assertThat(bf.getBeanDefinition("bazService").isAutowireCandidate(), is(true));
assertThat(bf.getBeanDefinition("random").isAutowireCandidate(), is(false));
assertThat(bf.getBeanDefinition("fooComponent").isAutowireCandidate(), is(false));
assertThat(bf.getBeanDefinition("fRepository").isAutowireCandidate(), is(false));
assertThat(bf.getBeanDefinition("bazService").isAutowireCandidate()).isTrue();
assertThat(bf.getBeanDefinition("random").isAutowireCandidate()).isFalse();
assertThat(bf.getBeanDefinition("fooComponent").isAutowireCandidate()).isFalse();
assertThat(bf.getBeanDefinition("fRepository").isAutowireCandidate()).isFalse();
assertThat(bf.getBeanDefinition("aComponent").isAutowireCandidate(), is(true));
assertThat(bf.getBeanDefinition("someService").isAutowireCandidate(), is(false));
assertThat(bf.getBeanDefinition("aComponent").isAutowireCandidate()).isTrue();
assertThat(bf.getBeanDefinition("someService").isAutowireCandidate()).isFalse();
}
@Test
@@ -161,17 +160,17 @@ public class NestedBeansElementAttributeRecursionTests {
InitDestroyBean beanC = bf.getBean("beanC", InitDestroyBean.class);
InitDestroyBean beanD = bf.getBean("beanD", InitDestroyBean.class);
assertThat(beanA.initMethod1Called, is(true));
assertThat(beanB.initMethod2Called, is(true));
assertThat(beanC.initMethod3Called, is(true));
assertThat(beanD.initMethod2Called, is(true));
assertThat(beanA.initMethod1Called).isTrue();
assertThat(beanB.initMethod2Called).isTrue();
assertThat(beanC.initMethod3Called).isTrue();
assertThat(beanD.initMethod2Called).isTrue();
bf.destroySingletons();
assertThat(beanA.destroyMethod1Called, is(true));
assertThat(beanB.destroyMethod2Called, is(true));
assertThat(beanC.destroyMethod3Called, is(true));
assertThat(beanD.destroyMethod2Called, is(true));
assertThat(beanA.destroyMethod1Called).isTrue();
assertThat(beanB.destroyMethod2Called).isTrue();
assertThat(beanC.destroyMethod3Called).isTrue();
assertThat(beanD.destroyMethod2Called).isTrue();
}
}

View File

@@ -24,8 +24,8 @@ import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for new nested beans element support in Spring XML
@@ -42,7 +42,7 @@ public class NestedBeansElementTests {
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(XML);
Object foo = bf.getBean("foo");
assertThat(foo, instanceOf(String.class));
assertThat(foo).isInstanceOf(String.class);
}
@Test
@@ -58,7 +58,7 @@ public class NestedBeansElementTests {
bf.getBean("devOnlyBean"); // should not throw NSBDE
Object foo = bf.getBean("foo");
assertThat(foo, instanceOf(Integer.class));
assertThat(foo).isInstanceOf(Integer.class);
bf.getBean("devOnlyBean");
}

View File

@@ -16,9 +16,7 @@
package org.springframework.beans.factory.xml;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.assertj.core.api.Condition;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -27,9 +25,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Tests various combinations of profile declarations against various profile
@@ -71,51 +68,51 @@ public class ProfileXmlBeanDefinitionTests {
@Test
public void testProfilePermutations() {
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, NONE_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, DEV_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, PROD_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, MULTI_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, NONE_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, DEV_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, PROD_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, MULTI_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, NONE_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, DEV_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, PROD_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, MULTI_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, NONE_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, DEV_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, PROD_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(DEV_ELIGIBLE_XML, MULTI_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, NONE_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, DEV_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, PROD_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, MULTI_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, NONE_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, DEV_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, PROD_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(NOT_DEV_ELIGIBLE_XML, MULTI_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, NONE_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, DEV_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, PROD_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, MULTI_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, NONE_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, DEV_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, PROD_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(ALL_ELIGIBLE_XML, MULTI_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, NONE_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, UNKNOWN_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, DEV_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, PROD_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, MULTI_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, NONE_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, UNKNOWN_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, DEV_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, PROD_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_XML, MULTI_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, NONE_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, UNKNOWN_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, DEV_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, PROD_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, MULTI_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(MULTI_NEGATED_XML, NONE_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, UNKNOWN_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, DEV_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, PROD_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NEGATED_XML, MULTI_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, NONE_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, UNKNOWN_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, DEV_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, PROD_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, MULTI_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, NONE_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, UNKNOWN_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, DEV_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, PROD_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_NOT_DEV_ELIGIBLE_XML, MULTI_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, NONE_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, UNKNOWN_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, DEV_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, PROD_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, MULTI_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, NONE_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, UNKNOWN_ACTIVE)).isNot(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, DEV_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, PROD_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(MULTI_ELIGIBLE_SPACE_DELIMITED_XML, MULTI_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(UNKNOWN_ELIGIBLE_XML, MULTI_ACTIVE), not(containsTargetBean()));
assertThat(beanFactoryFor(UNKNOWN_ELIGIBLE_XML, MULTI_ACTIVE)).isNot(containingTarget());
}
@Test
@@ -128,7 +125,7 @@ public class ProfileXmlBeanDefinitionTests {
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, not(containsTargetBean()));
assertThat(beanFactory).isNot(containingTarget());
}
{
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@@ -138,14 +135,14 @@ public class ProfileXmlBeanDefinitionTests {
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(CUSTOM_DEFAULT_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, containsTargetBean());
assertThat(beanFactory).is(containingTarget());
}
}
@Test
public void testDefaultAndNonDefaultProfile() {
assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, NONE_ACTIVE), containsTargetBean());
assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, "other"), not(containsTargetBean()));
assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, NONE_ACTIVE)).is(containingTarget());
assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, "other")).isNot(containingTarget());
{
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@@ -155,7 +152,7 @@ public class ProfileXmlBeanDefinitionTests {
env.setDefaultProfiles("default");
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, containsTargetBean());
assertThat(beanFactory).is(containingTarget());
}
{
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@@ -165,7 +162,7 @@ public class ProfileXmlBeanDefinitionTests {
env.setDefaultProfiles("default");
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, containsTargetBean());
assertThat(beanFactory).is(containingTarget());
}
{
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
@@ -175,7 +172,7 @@ public class ProfileXmlBeanDefinitionTests {
//env.setDefaultProfiles("default");
reader.setEnvironment(env);
reader.loadBeanDefinitions(new ClassPathResource(DEFAULT_AND_DEV_ELIGIBLE_XML, getClass()));
assertThat(beanFactory, containsTargetBean());
assertThat(beanFactory).is(containingTarget());
}
}
@@ -190,25 +187,8 @@ public class ProfileXmlBeanDefinitionTests {
return beanFactory;
}
private static Matcher<BeanDefinitionRegistry> containsBeanDefinition(final String beanName) {
return new TypeSafeMatcher<BeanDefinitionRegistry>() {
@Override
public void describeTo(Description desc) {
desc.appendText("a BeanDefinitionRegistry containing bean named ")
.appendValue(beanName);
}
@Override
public boolean matchesSafely(BeanDefinitionRegistry beanFactory) {
return beanFactory.containsBeanDefinition(beanName);
}
};
private Condition<BeanDefinitionRegistry> containingTarget() {
return new Condition<>(registry -> registry.containsBeanDefinition(TARGET_BEAN), "contains target");
}
private static Matcher<BeanDefinitionRegistry> containsTargetBean() {
return containsBeanDefinition(TARGET_BEAN);
}
}