Merge branch '6.0.x'

This commit is contained in:
Juergen Hoeller 2023-06-29 12:05:57 +02:00
commit ef4d93507d
22 changed files with 207 additions and 311 deletions

View File

@ -390,7 +390,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
@Override @Override
@Nullable @Nullable
public String getBeanClassName() { public String getBeanClassName() {
return (this.beanClass instanceof Class<?> clazz ? clazz.getName() : (String) this.beanClass); Object beanClassObject = this.beanClass; // defensive access to volatile beanClass field
return (beanClassObject instanceof Class<?> clazz ? clazz.getName() : (String) beanClassObject);
} }
/** /**
@ -423,7 +424,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @see #resolveBeanClass(ClassLoader) * @see #resolveBeanClass(ClassLoader)
*/ */
public Class<?> getBeanClass() throws IllegalStateException { public Class<?> getBeanClass() throws IllegalStateException {
Object beanClassObject = this.beanClass; Object beanClassObject = this.beanClass; // defensive access to volatile beanClass field
if (beanClassObject == null) { if (beanClassObject == null) {
throw new IllegalStateException("No bean class specified on bean definition"); throw new IllegalStateException("No bean class specified on bean definition");
} }

View File

@ -35,8 +35,7 @@ public abstract class AbstractPropertyValuesTests {
assertThat(pvs.contains("forname")).as("Contains forname").isTrue(); assertThat(pvs.contains("forname")).as("Contains forname").isTrue();
assertThat(pvs.contains("surname")).as("Contains surname").isTrue(); assertThat(pvs.contains("surname")).as("Contains surname").isTrue();
assertThat(pvs.contains("age")).as("Contains age").isTrue(); assertThat(pvs.contains("age")).as("Contains age").isTrue();
boolean condition1 = !pvs.contains("tory"); assertThat(!pvs.contains("tory")).as("Doesn't contain tory").isTrue();
assertThat(condition1).as("Doesn't contain tory").isTrue();
PropertyValue[] ps = pvs.getPropertyValues(); PropertyValue[] ps = pvs.getPropertyValues();
Map<String, String> m = new HashMap<>(); Map<String, String> m = new HashMap<>();
@ -46,8 +45,7 @@ public abstract class AbstractPropertyValuesTests {
for (PropertyValue element : ps) { for (PropertyValue element : ps) {
Object val = m.get(element.getName()); Object val = m.get(element.getName());
assertThat(val).as("Can't have unexpected value").isNotNull(); assertThat(val).as("Can't have unexpected value").isNotNull();
boolean condition = val instanceof String; assertThat(val instanceof String).as("Val i string").isTrue();
assertThat(condition).as("Val i string").isTrue();
assertThat(val.equals(element.getValue())).as("val matches expected").isTrue(); assertThat(val.equals(element.getValue())).as("val matches expected").isTrue();
m.remove(element.getName()); m.remove(element.getName());
} }

View File

@ -155,8 +155,7 @@ public class BeanFactoryUtilsTests {
assertThat(beans.get("t1")).isEqualTo(t1); assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2); assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject()); assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition = beans.get("t4") instanceof TestBean; assertThat(beans.get("t4") instanceof TestBean).isTrue();
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
assertThat(beans).hasSize(2); assertThat(beans).hasSize(2);
@ -192,8 +191,7 @@ public class BeanFactoryUtilsTests {
assertThat(beans.get("t1")).isEqualTo(t1); assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2); assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject()); assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition2 = beans.get("t4") instanceof TestBean; assertThat(beans.get("t4") instanceof TestBean).isTrue();
assertThat(condition2).isTrue();
// t3 and t4 are found here as of Spring 2.0, since they are pre-registered // t3 and t4 are found here as of Spring 2.0, since they are pre-registered
// singleton instances, while testFactory1 and testFactory are *not* found // singleton instances, while testFactory1 and testFactory are *not* found
// because they are FactoryBean definitions that haven't been initialized yet. // because they are FactoryBean definitions that haven't been initialized yet.
@ -212,13 +210,11 @@ public class BeanFactoryUtilsTests {
assertThat(beans.get("test3")).isEqualTo(test3); assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test); assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1); assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
boolean condition1 = beans.get("testFactory2") instanceof TestBean; assertThat(beans.get("testFactory2") instanceof TestBean).isTrue();
assertThat(condition1).isTrue();
assertThat(beans.get("t1")).isEqualTo(t1); assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2); assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject()); assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition = beans.get("t4") instanceof TestBean; assertThat(beans.get("t4") instanceof TestBean).isTrue();
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true);
assertThat(beans).hasSize(4); assertThat(beans).hasSize(4);
@ -261,8 +257,7 @@ public class BeanFactoryUtilsTests {
assertThat(beans.get("test3")).isEqualTo(test3); assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test); assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1); assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
boolean condition = beans.get("testFactory2") instanceof TestBean; assertThat(beans.get("testFactory2") instanceof TestBean).isTrue();
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true);
assertThat(beans).hasSize(2); assertThat(beans).hasSize(2);

View File

@ -85,8 +85,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.getBean("testBean"); bf.getBean("testBean");
} }
catch (BeanCreationException ex) { catch (BeanCreationException ex) {
boolean condition = ex.getRootCause() instanceof IllegalStateException; assertThat(ex.getRootCause() instanceof IllegalStateException).isTrue();
assertThat(condition).isTrue();
} }
} }

View File

@ -66,8 +66,7 @@ public class CustomScopeConfigurerTests {
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
figurer.setScopes(scopes); figurer.setScopes(scopes);
figurer.postProcessBeanFactory(factory); figurer.postProcessBeanFactory(factory);
boolean condition = factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope; assertThat(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope).isTrue();
assertThat(condition).isTrue();
} }
@Test @Test
@ -77,8 +76,7 @@ public class CustomScopeConfigurerTests {
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
figurer.setScopes(scopes); figurer.setScopes(scopes);
figurer.postProcessBeanFactory(factory); figurer.postProcessBeanFactory(factory);
boolean condition = factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope; assertThat(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope).isTrue();
assertThat(condition).isTrue();
} }
@Test @Test

View File

@ -49,8 +49,7 @@ public class PropertyPathFactoryBeanTests {
assertThat(xbf.getType("otb.spouse")).isEqualTo(ITestBean.class); assertThat(xbf.getType("otb.spouse")).isEqualTo(ITestBean.class);
Object result1 = xbf.getBean("otb.spouse"); Object result1 = xbf.getBean("otb.spouse");
Object result2 = xbf.getBean("otb.spouse"); Object result2 = xbf.getBean("otb.spouse");
boolean condition = result1 instanceof TestBean; assertThat(result1 instanceof TestBean).isTrue();
assertThat(condition).isTrue();
assertThat(result1).isSameAs(result2); assertThat(result1).isSameAs(result2);
assertThat(((TestBean) result1).getAge()).isEqualTo(99); assertThat(((TestBean) result1).getAge()).isEqualTo(99);
} }
@ -64,12 +63,9 @@ public class PropertyPathFactoryBeanTests {
Object result1 = xbf.getBean("tb.spouse"); Object result1 = xbf.getBean("tb.spouse");
Object result2 = xbf.getBean("propertyPath3"); Object result2 = xbf.getBean("propertyPath3");
Object result3 = xbf.getBean("propertyPath3"); Object result3 = xbf.getBean("propertyPath3");
boolean condition2 = result1 instanceof TestBean; assertThat(result1 instanceof TestBean).isTrue();
assertThat(condition2).isTrue(); assertThat(result2 instanceof TestBean).isTrue();
boolean condition1 = result2 instanceof TestBean; assertThat(result3 instanceof TestBean).isTrue();
assertThat(condition1).isTrue();
boolean condition = result3 instanceof TestBean;
assertThat(condition).isTrue();
assertThat(((TestBean) result1).getAge()).isEqualTo(11); assertThat(((TestBean) result1).getAge()).isEqualTo(11);
assertThat(((TestBean) result2).getAge()).isEqualTo(11); assertThat(((TestBean) result2).getAge()).isEqualTo(11);
assertThat(((TestBean) result3).getAge()).isEqualTo(11); assertThat(((TestBean) result3).getAge()).isEqualTo(11);
@ -93,8 +89,7 @@ public class PropertyPathFactoryBeanTests {
TestBean spouse = (TestBean) xbf.getBean("otb.spouse"); TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner"); TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
assertThat(tbWithInner.getSpouse()).isSameAs(spouse); assertThat(tbWithInner.getSpouse()).isSameAs(spouse);
boolean condition = !tbWithInner.getFriends().isEmpty(); assertThat(!tbWithInner.getFriends().isEmpty()).isTrue();
assertThat(condition).isTrue();
assertThat(tbWithInner.getFriends().iterator().next()).isSameAs(spouse); assertThat(tbWithInner.getFriends().iterator().next()).isSameAs(spouse);
} }

View File

@ -198,14 +198,10 @@ public class ServiceLocatorFactoryBeanTests {
assertThat(testBean3).isNotSameAs(testBean2); assertThat(testBean3).isNotSameAs(testBean2);
assertThat(testBean4).isNotSameAs(testBean2); assertThat(testBean4).isNotSameAs(testBean2);
assertThat(testBean4).isNotSameAs(testBean3); assertThat(testBean4).isNotSameAs(testBean3);
boolean condition3 = testBean1 instanceof ExtendedTestService; assertThat(testBean1 instanceof ExtendedTestService).isFalse();
assertThat(condition3).isFalse(); assertThat(testBean2 instanceof ExtendedTestService).isFalse();
boolean condition2 = testBean2 instanceof ExtendedTestService; assertThat(testBean3 instanceof ExtendedTestService).isFalse();
assertThat(condition2).isFalse(); assertThat(testBean4 instanceof ExtendedTestService).isTrue();
boolean condition1 = testBean3 instanceof ExtendedTestService;
assertThat(condition1).isFalse();
boolean condition = testBean4 instanceof ExtendedTestService;
assertThat(condition).isTrue();
} }
@Test @Test
@ -264,17 +260,14 @@ public class ServiceLocatorFactoryBeanTests {
public static class TestService { public static class TestService {
} }
public static class ExtendedTestService extends TestService { public static class ExtendedTestService extends TestService {
} }
public static class TestService2 { public static class TestService2 {
} }
@ -345,7 +338,6 @@ public class ServiceLocatorFactoryBeanTests {
@SuppressWarnings("serial") @SuppressWarnings("serial")
public static class ExceptionClassWithOnlyZeroArgCtor extends Exception { public static class ExceptionClassWithOnlyZeroArgCtor extends Exception {
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -99,8 +99,7 @@ public class YamlMapFactoryBeanTests {
assertThat(map).hasSize(1); assertThat(map).hasSize(1);
assertThat(map.containsKey("foo")).isTrue(); assertThat(map.containsKey("foo")).isTrue();
Object object = map.get("foo"); Object object = map.get("foo");
boolean condition = object instanceof LinkedHashMap; assertThat(object instanceof LinkedHashMap).isTrue();
assertThat(condition).isTrue();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> sub = (Map<String, Object>) object; Map<String, Object> sub = (Map<String, Object>) object;
assertThat(sub.containsKey("key1.key2")).isTrue(); assertThat(sub.containsKey("key1.key2")).isTrue();
@ -115,8 +114,7 @@ public class YamlMapFactoryBeanTests {
assertThat(map).hasSize(1); assertThat(map).hasSize(1);
assertThat(map.containsKey("foo")).isTrue(); assertThat(map.containsKey("foo")).isTrue();
Object object = map.get("foo"); Object object = map.get("foo");
boolean condition = object instanceof LinkedHashMap; assertThat(object instanceof LinkedHashMap).isTrue();
assertThat(condition).isTrue();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> sub = (Map<String, Object>) object; Map<String, Object> sub = (Map<String, Object>) object;
assertThat(sub).hasSize(1); assertThat(sub).hasSize(1);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,8 +48,7 @@ class ServiceLoaderTests {
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
bf.registerBeanDefinition("service", bd); bf.registerBeanDefinition("service", bd);
ServiceLoader<?> serviceLoader = (ServiceLoader<?>) bf.getBean("service"); ServiceLoader<?> serviceLoader = (ServiceLoader<?>) bf.getBean("service");
boolean condition = serviceLoader.iterator().next() instanceof DocumentBuilderFactory; assertThat(serviceLoader.iterator().next() instanceof DocumentBuilderFactory).isTrue();
assertThat(condition).isTrue();
} }
@Test @Test
@ -58,8 +57,7 @@ class ServiceLoaderTests {
RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class); RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class);
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
bf.registerBeanDefinition("service", bd); bf.registerBeanDefinition("service", bd);
boolean condition = bf.getBean("service") instanceof DocumentBuilderFactory; assertThat(bf.getBean("service") instanceof DocumentBuilderFactory).isTrue();
assertThat(condition).isTrue();
} }
@Test @Test
@ -69,8 +67,7 @@ class ServiceLoaderTests {
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
bf.registerBeanDefinition("service", bd); bf.registerBeanDefinition("service", bd);
List<?> serviceList = (List<?>) bf.getBean("service"); List<?> serviceList = (List<?>) bf.getBean("service");
boolean condition = serviceList.get(0) instanceof DocumentBuilderFactory; assertThat(serviceList.get(0) instanceof DocumentBuilderFactory).isTrue();
assertThat(condition).isTrue();
} }
} }

View File

@ -35,10 +35,8 @@ public class BeanDefinitionTests {
bd.setLazyInit(true); bd.setLazyInit(true);
bd.setScope("request"); bd.setScope("request");
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
boolean condition1 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition1).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition = !otherBd.equals(bd);
assertThat(condition).isTrue();
otherBd.setAbstract(true); otherBd.setAbstract(true);
otherBd.setLazyInit(true); otherBd.setLazyInit(true);
otherBd.setScope("request"); otherBd.setScope("request");
@ -54,15 +52,11 @@ public class BeanDefinitionTests {
bd.getPropertyValues().add("age", "99"); bd.getPropertyValues().add("age", "99");
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
otherBd.getPropertyValues().add("name", "myName"); otherBd.getPropertyValues().add("name", "myName");
boolean condition3 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition3).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition2 = !otherBd.equals(bd);
assertThat(condition2).isTrue();
otherBd.getPropertyValues().add("age", "11"); otherBd.getPropertyValues().add("age", "11");
boolean condition1 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition1).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition = !otherBd.equals(bd);
assertThat(condition).isTrue();
otherBd.getPropertyValues().add("age", "99"); otherBd.getPropertyValues().add("age", "99");
assertThat(bd.equals(otherBd)).isTrue(); assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue();
@ -76,15 +70,11 @@ public class BeanDefinitionTests {
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); bd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5);
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
otherBd.getConstructorArgumentValues().addGenericArgumentValue("test"); otherBd.getConstructorArgumentValues().addGenericArgumentValue("test");
boolean condition3 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition3).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition2 = !otherBd.equals(bd);
assertThat(condition2).isTrue();
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 9); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 9);
boolean condition1 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition1).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition = !otherBd.equals(bd);
assertThat(condition).isTrue();
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5);
assertThat(bd.equals(otherBd)).isTrue(); assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue();
@ -99,15 +89,11 @@ public class BeanDefinitionTests {
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
otherBd.getConstructorArgumentValues().addGenericArgumentValue("test", "int"); otherBd.getConstructorArgumentValues().addGenericArgumentValue("test", "int");
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5);
boolean condition3 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition3).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition2 = !otherBd.equals(bd);
assertThat(condition2).isTrue();
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "int"); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "int");
boolean condition1 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition1).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition = !otherBd.equals(bd);
assertThat(condition).isTrue();
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "long"); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "long");
assertThat(bd.equals(otherBd)).isTrue(); assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue();
@ -125,10 +111,8 @@ public class BeanDefinitionTests {
otherBd.setScope("request"); otherBd.setScope("request");
otherBd.setAbstract(true); otherBd.setAbstract(true);
otherBd.setLazyInit(true); otherBd.setLazyInit(true);
boolean condition1 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition1).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition = !otherBd.equals(bd);
assertThat(condition).isTrue();
otherBd.setParentName("parent"); otherBd.setParentName("parent");
assertThat(bd.equals(otherBd)).isTrue(); assertThat(bd.equals(otherBd)).isTrue();
assertThat(otherBd.equals(bd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue();
@ -153,10 +137,8 @@ public class BeanDefinitionTests {
bd.setScope("request"); bd.setScope("request");
BeanDefinitionHolder holder = new BeanDefinitionHolder(bd, "bd"); BeanDefinitionHolder holder = new BeanDefinitionHolder(bd, "bd");
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
boolean condition1 = !bd.equals(otherBd); assertThat(!bd.equals(otherBd)).isTrue();
assertThat(condition1).isTrue(); assertThat(!otherBd.equals(bd)).isTrue();
boolean condition = !otherBd.equals(bd);
assertThat(condition).isTrue();
otherBd.setAbstract(true); otherBd.setAbstract(true);
otherBd.setLazyInit(true); otherBd.setLazyInit(true);
otherBd.setScope("request"); otherBd.setScope("request");

View File

@ -422,10 +422,8 @@ class BeanFactoryGenericsTests {
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
boolean condition1 = gb.getCollectionMap().get(1) instanceof HashSet; assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
assertThat(condition1).isTrue(); assertThat(gb.getCollectionMap().get(2) instanceof ArrayList).isTrue();
boolean condition = gb.getCollectionMap().get(2) instanceof ArrayList;
assertThat(condition).isTrue();
} }
@ -577,10 +575,8 @@ class BeanFactoryGenericsTests {
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
boolean condition1 = gb.getCollectionMap().get(1) instanceof HashSet; assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
assertThat(condition1).isTrue(); assertThat(gb.getCollectionMap().get(2) instanceof ArrayList).isTrue();
boolean condition = gb.getCollectionMap().get(2) instanceof ArrayList;
assertThat(condition).isTrue();
} }
@Test @Test

View File

@ -337,16 +337,14 @@ public class FactoryMethodTests {
// Check that listInstance is not considered a bean of type FactoryMethods. // Check that listInstance is not considered a bean of type FactoryMethods.
assertThat(List.class.isAssignableFrom(xbf.getType("listInstance"))).isTrue(); assertThat(List.class.isAssignableFrom(xbf.getType("listInstance"))).isTrue();
String[] names = xbf.getBeanNamesForType(FactoryMethods.class); String[] names = xbf.getBeanNamesForType(FactoryMethods.class);
boolean condition1 = !Arrays.asList(names).contains("listInstance"); assertThat(Arrays.asList(names).contains("listInstance")).isFalse();
assertThat(condition1).isTrue();
names = xbf.getBeanNamesForType(List.class); names = xbf.getBeanNamesForType(List.class);
assertThat(Arrays.asList(names).contains("listInstance")).isTrue(); assertThat(Arrays.asList(names).contains("listInstance")).isTrue();
xbf.preInstantiateSingletons(); xbf.preInstantiateSingletons();
assertThat(List.class.isAssignableFrom(xbf.getType("listInstance"))).isTrue(); assertThat(List.class.isAssignableFrom(xbf.getType("listInstance"))).isTrue();
names = xbf.getBeanNamesForType(FactoryMethods.class); names = xbf.getBeanNamesForType(FactoryMethods.class);
boolean condition = !Arrays.asList(names).contains("listInstance"); assertThat(Arrays.asList(names).contains("listInstance")).isFalse();
assertThat(condition).isTrue();
names = xbf.getBeanNamesForType(List.class); names = xbf.getBeanNamesForType(List.class);
assertThat(Arrays.asList(names).contains("listInstance")).isTrue(); assertThat(Arrays.asList(names).contains("listInstance")).isTrue();
List<?> list = (List<?>) xbf.getBean("listInstance"); List<?> list = (List<?>) xbf.getBean("listInstance");

View File

@ -70,24 +70,21 @@ public class XmlBeanCollectionTests {
ListFactoryBean listFactory = new ListFactoryBean(); ListFactoryBean listFactory = new ListFactoryBean();
listFactory.setSourceList(new LinkedList()); listFactory.setSourceList(new LinkedList());
listFactory.afterPropertiesSet(); listFactory.afterPropertiesSet();
boolean condition2 = listFactory.getObject() instanceof ArrayList; assertThat(listFactory.getObject() instanceof ArrayList).isTrue();
assertThat(condition2).isTrue();
SetFactoryBean setFactory = new SetFactoryBean(); SetFactoryBean setFactory = new SetFactoryBean();
setFactory.setSourceSet(new TreeSet()); setFactory.setSourceSet(new TreeSet());
setFactory.afterPropertiesSet(); setFactory.afterPropertiesSet();
boolean condition1 = setFactory.getObject() instanceof LinkedHashSet; assertThat(setFactory.getObject() instanceof LinkedHashSet).isTrue();
assertThat(condition1).isTrue();
MapFactoryBean mapFactory = new MapFactoryBean(); MapFactoryBean mapFactory = new MapFactoryBean();
mapFactory.setSourceMap(new TreeMap()); mapFactory.setSourceMap(new TreeMap());
mapFactory.afterPropertiesSet(); mapFactory.afterPropertiesSet();
boolean condition = mapFactory.getObject() instanceof LinkedHashMap; assertThat(mapFactory.getObject() instanceof LinkedHashMap).isTrue();
assertThat(condition).isTrue();
} }
@Test @Test
public void testRefSubelement() throws Exception { public void testRefSubelement() {
//assertTrue("5 beans in reftypes, not " + this.beanFactory.getBeanDefinitionCount(), this.beanFactory.getBeanDefinitionCount() == 5); //assertTrue("5 beans in reftypes, not " + this.beanFactory.getBeanDefinitionCount(), this.beanFactory.getBeanDefinitionCount() == 5);
TestBean jen = (TestBean) this.beanFactory.getBean("jenny"); TestBean jen = (TestBean) this.beanFactory.getBean("jenny");
TestBean dave = (TestBean) this.beanFactory.getBean("david"); TestBean dave = (TestBean) this.beanFactory.getBean("david");
@ -95,25 +92,25 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testPropertyWithLiteralValueSubelement() throws Exception { public void testPropertyWithLiteralValueSubelement() {
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose"); TestBean verbose = (TestBean) this.beanFactory.getBean("verbose");
assertThat(verbose.getName()).isEqualTo("verbose"); assertThat(verbose.getName()).isEqualTo("verbose");
} }
@Test @Test
public void testPropertyWithIdRefLocalAttrSubelement() throws Exception { public void testPropertyWithIdRefLocalAttrSubelement() {
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose2"); TestBean verbose = (TestBean) this.beanFactory.getBean("verbose2");
assertThat(verbose.getName()).isEqualTo("verbose"); assertThat(verbose.getName()).isEqualTo("verbose");
} }
@Test @Test
public void testPropertyWithIdRefBeanAttrSubelement() throws Exception { public void testPropertyWithIdRefBeanAttrSubelement() {
TestBean verbose = (TestBean) this.beanFactory.getBean("verbose3"); TestBean verbose = (TestBean) this.beanFactory.getBean("verbose3");
assertThat(verbose.getName()).isEqualTo("verbose"); assertThat(verbose.getName()).isEqualTo("verbose");
} }
@Test @Test
public void testRefSubelementsBuildCollection() throws Exception { public void testRefSubelementsBuildCollection() {
TestBean jen = (TestBean) this.beanFactory.getBean("jenny"); TestBean jen = (TestBean) this.beanFactory.getBean("jenny");
TestBean dave = (TestBean) this.beanFactory.getBean("david"); TestBean dave = (TestBean) this.beanFactory.getBean("david");
TestBean rod = (TestBean) this.beanFactory.getBean("rod"); TestBean rod = (TestBean) this.beanFactory.getBean("rod");
@ -130,7 +127,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testRefSubelementsBuildCollectionWithPrototypes() throws Exception { public void testRefSubelementsBuildCollectionWithPrototypes() {
TestBean jen = (TestBean) this.beanFactory.getBean("pJenny"); TestBean jen = (TestBean) this.beanFactory.getBean("pJenny");
TestBean dave = (TestBean) this.beanFactory.getBean("pDavid"); TestBean dave = (TestBean) this.beanFactory.getBean("pDavid");
TestBean rod = (TestBean) this.beanFactory.getBean("pRod"); TestBean rod = (TestBean) this.beanFactory.getBean("pRod");
@ -153,7 +150,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testRefSubelementsBuildCollectionFromSingleElement() throws Exception { public void testRefSubelementsBuildCollectionFromSingleElement() {
TestBean loner = (TestBean) this.beanFactory.getBean("loner"); TestBean loner = (TestBean) this.beanFactory.getBean("loner");
TestBean dave = (TestBean) this.beanFactory.getBean("david"); TestBean dave = (TestBean) this.beanFactory.getBean("david");
assertThat(loner.getFriends().size()).isEqualTo(1); assertThat(loner.getFriends().size()).isEqualTo(1);
@ -161,7 +158,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception { public void testBuildCollectionFromMixtureOfReferencesAndValues() {
MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble"); MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble");
assertThat(jumble.getJumble().size()).as("Expected 5 elements, not " + jumble.getJumble().size()).isEqualTo(5); assertThat(jumble.getJumble().size()).as("Expected 5 elements, not " + jumble.getJumble().size()).isEqualTo(5);
List l = (List) jumble.getJumble(); List l = (List) jumble.getJumble();
@ -175,7 +172,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testInvalidBeanNameReference() throws Exception { public void testInvalidBeanNameReference() {
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
this.beanFactory.getBean("jumble2")) this.beanFactory.getBean("jumble2"))
.withCauseInstanceOf(BeanDefinitionStoreException.class) .withCauseInstanceOf(BeanDefinitionStoreException.class)
@ -183,13 +180,13 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testEmptyMap() throws Exception { public void testEmptyMap() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyMap"); HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyMap");
assertThat(hasMap.getMap().size()).isEqualTo(0); assertThat(hasMap.getMap().size()).isEqualTo(0);
} }
@Test @Test
public void testMapWithLiteralsOnly() throws Exception { public void testMapWithLiteralsOnly() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("literalMap"); HasMap hasMap = (HasMap) this.beanFactory.getBean("literalMap");
assertThat(hasMap.getMap().size()).isEqualTo(3); assertThat(hasMap.getMap().size()).isEqualTo(3);
assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue(); assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue();
@ -198,23 +195,21 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testMapWithLiteralsAndReferences() throws Exception { public void testMapWithLiteralsAndReferences() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap"); HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap");
assertThat(hasMap.getMap().size()).isEqualTo(5); assertThat(hasMap.getMap().size()).isEqualTo(5);
assertThat(hasMap.getMap().get("foo").equals(10)).isTrue(); assertThat(hasMap.getMap().get("foo").equals(10)).isTrue();
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny"); TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
assertThat(hasMap.getMap().get("jenny")).isSameAs(jenny); assertThat(hasMap.getMap().get("jenny")).isSameAs(jenny);
assertThat(hasMap.getMap().get(5).equals("david")).isTrue(); assertThat(hasMap.getMap().get(5).equals("david")).isTrue();
boolean condition1 = hasMap.getMap().get("bar") instanceof Long; assertThat(hasMap.getMap().get("bar") instanceof Long).isTrue();
assertThat(condition1).isTrue();
assertThat(hasMap.getMap().get("bar").equals(100L)).isTrue(); assertThat(hasMap.getMap().get("bar").equals(100L)).isTrue();
boolean condition = hasMap.getMap().get("baz") instanceof Integer; assertThat(hasMap.getMap().get("baz") instanceof Integer).isTrue();
assertThat(condition).isTrue();
assertThat(hasMap.getMap().get("baz").equals(200)).isTrue(); assertThat(hasMap.getMap().get("baz").equals(200)).isTrue();
} }
@Test @Test
public void testMapWithLiteralsAndPrototypeReferences() throws Exception { public void testMapWithLiteralsAndPrototypeReferences() {
TestBean jenny = (TestBean) this.beanFactory.getBean("pJenny"); TestBean jenny = (TestBean) this.beanFactory.getBean("pJenny");
HasMap hasMap = (HasMap) this.beanFactory.getBean("pMixedMap"); HasMap hasMap = (HasMap) this.beanFactory.getBean("pMixedMap");
assertThat(hasMap.getMap().size()).isEqualTo(2); assertThat(hasMap.getMap().size()).isEqualTo(2);
@ -230,7 +225,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testMapWithLiteralsReferencesAndList() throws Exception { public void testMapWithLiteralsReferencesAndList() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMapWithList"); HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMapWithList");
assertThat(hasMap.getMap().size()).isEqualTo(4); assertThat(hasMap.getMap().size()).isEqualTo(4);
assertThat(hasMap.getMap().get(null).equals("bar")).isTrue(); assertThat(hasMap.getMap().get(null).equals("bar")).isTrue();
@ -267,13 +262,13 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testEmptySet() throws Exception { public void testEmptySet() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptySet"); HasMap hasMap = (HasMap) this.beanFactory.getBean("emptySet");
assertThat(hasMap.getSet().size()).isEqualTo(0); assertThat(hasMap.getSet().size()).isEqualTo(0);
} }
@Test @Test
public void testPopulatedSet() throws Exception { public void testPopulatedSet() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("set"); HasMap hasMap = (HasMap) this.beanFactory.getBean("set");
assertThat(hasMap.getSet().size()).isEqualTo(3); assertThat(hasMap.getSet().size()).isEqualTo(3);
assertThat(hasMap.getSet().contains("bar")).isTrue(); assertThat(hasMap.getSet().contains("bar")).isTrue();
@ -287,7 +282,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testPopulatedConcurrentSet() throws Exception { public void testPopulatedConcurrentSet() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("concurrentSet"); HasMap hasMap = (HasMap) this.beanFactory.getBean("concurrentSet");
assertThat(hasMap.getConcurrentSet().size()).isEqualTo(3); assertThat(hasMap.getConcurrentSet().size()).isEqualTo(3);
assertThat(hasMap.getConcurrentSet().contains("bar")).isTrue(); assertThat(hasMap.getConcurrentSet().contains("bar")).isTrue();
@ -297,7 +292,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testPopulatedIdentityMap() throws Exception { public void testPopulatedIdentityMap() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("identityMap"); HasMap hasMap = (HasMap) this.beanFactory.getBean("identityMap");
assertThat(hasMap.getIdentityMap().size()).isEqualTo(2); assertThat(hasMap.getIdentityMap().size()).isEqualTo(2);
HashSet set = new HashSet(hasMap.getIdentityMap().keySet()); HashSet set = new HashSet(hasMap.getIdentityMap().keySet());
@ -306,14 +301,14 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testEmptyProps() throws Exception { public void testEmptyProps() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyProps"); HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyProps");
assertThat(hasMap.getProps().size()).isEqualTo(0); assertThat(hasMap.getProps().size()).isEqualTo(0);
assertThat(Properties.class).isEqualTo(hasMap.getProps().getClass()); assertThat(Properties.class).isEqualTo(hasMap.getProps().getClass());
} }
@Test @Test
public void testPopulatedProps() throws Exception { public void testPopulatedProps() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("props"); HasMap hasMap = (HasMap) this.beanFactory.getBean("props");
assertThat(hasMap.getProps().size()).isEqualTo(2); assertThat(hasMap.getProps().size()).isEqualTo(2);
assertThat(hasMap.getProps().get("foo").equals("bar")).isTrue(); assertThat(hasMap.getProps().get("foo").equals("bar")).isTrue();
@ -321,7 +316,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testObjectArray() throws Exception { public void testObjectArray() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("objectArray"); HasMap hasMap = (HasMap) this.beanFactory.getBean("objectArray");
assertThat(hasMap.getObjectArray().length).isEqualTo(2); assertThat(hasMap.getObjectArray().length).isEqualTo(2);
assertThat(hasMap.getObjectArray()[0].equals("one")).isTrue(); assertThat(hasMap.getObjectArray()[0].equals("one")).isTrue();
@ -329,7 +324,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testIntegerArray() throws Exception { public void testIntegerArray() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray"); HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray");
assertThat(hasMap.getIntegerArray().length).isEqualTo(3); assertThat(hasMap.getIntegerArray().length).isEqualTo(3);
assertThat(hasMap.getIntegerArray()[0]).isEqualTo(0); assertThat(hasMap.getIntegerArray()[0]).isEqualTo(0);
@ -338,7 +333,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testClassArray() throws Exception { public void testClassArray() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("classArray"); HasMap hasMap = (HasMap) this.beanFactory.getBean("classArray");
assertThat(hasMap.getClassArray().length).isEqualTo(2); assertThat(hasMap.getClassArray().length).isEqualTo(2);
assertThat(hasMap.getClassArray()[0].equals(String.class)).isTrue(); assertThat(hasMap.getClassArray()[0].equals(String.class)).isTrue();
@ -346,7 +341,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testClassList() throws Exception { public void testClassList() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("classList"); HasMap hasMap = (HasMap) this.beanFactory.getBean("classList");
assertThat(hasMap.getClassList().size()).isEqualTo(2); assertThat(hasMap.getClassList().size()).isEqualTo(2);
assertThat(hasMap.getClassList().get(0).equals(String.class)).isTrue(); assertThat(hasMap.getClassList().get(0).equals(String.class)).isTrue();
@ -354,7 +349,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testProps() throws Exception { public void testProps() {
HasMap hasMap = (HasMap) this.beanFactory.getBean("props"); HasMap hasMap = (HasMap) this.beanFactory.getBean("props");
assertThat(hasMap.getProps()).hasSize(2); assertThat(hasMap.getProps()).hasSize(2);
assertThat(hasMap.getProps().getProperty("foo")).isEqualTo("bar"); assertThat(hasMap.getProps().getProperty("foo")).isEqualTo("bar");
@ -367,60 +362,54 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testListFactory() throws Exception { public void testListFactory() {
List list = (List) this.beanFactory.getBean("listFactory"); List list = (List) this.beanFactory.getBean("listFactory");
boolean condition = list instanceof LinkedList; assertThat(list instanceof LinkedList).isTrue();
assertThat(condition).isTrue();
assertThat(list.size()).isEqualTo(2); assertThat(list.size()).isEqualTo(2);
assertThat(list.get(0)).isEqualTo("bar"); assertThat(list.get(0)).isEqualTo("bar");
assertThat(list.get(1)).isEqualTo("jenny"); assertThat(list.get(1)).isEqualTo("jenny");
} }
@Test @Test
public void testPrototypeListFactory() throws Exception { public void testPrototypeListFactory() {
List list = (List) this.beanFactory.getBean("pListFactory"); List list = (List) this.beanFactory.getBean("pListFactory");
boolean condition = list instanceof LinkedList; assertThat(list instanceof LinkedList).isTrue();
assertThat(condition).isTrue();
assertThat(list.size()).isEqualTo(2); assertThat(list.size()).isEqualTo(2);
assertThat(list.get(0)).isEqualTo("bar"); assertThat(list.get(0)).isEqualTo("bar");
assertThat(list.get(1)).isEqualTo("jenny"); assertThat(list.get(1)).isEqualTo("jenny");
} }
@Test @Test
public void testSetFactory() throws Exception { public void testSetFactory() {
Set set = (Set) this.beanFactory.getBean("setFactory"); Set set = (Set) this.beanFactory.getBean("setFactory");
boolean condition = set instanceof TreeSet; assertThat(set instanceof TreeSet).isTrue();
assertThat(condition).isTrue();
assertThat(set.size()).isEqualTo(2); assertThat(set.size()).isEqualTo(2);
assertThat(set.contains("bar")).isTrue(); assertThat(set.contains("bar")).isTrue();
assertThat(set.contains("jenny")).isTrue(); assertThat(set.contains("jenny")).isTrue();
} }
@Test @Test
public void testPrototypeSetFactory() throws Exception { public void testPrototypeSetFactory() {
Set set = (Set) this.beanFactory.getBean("pSetFactory"); Set set = (Set) this.beanFactory.getBean("pSetFactory");
boolean condition = set instanceof TreeSet; assertThat(set instanceof TreeSet).isTrue();
assertThat(condition).isTrue();
assertThat(set.size()).isEqualTo(2); assertThat(set.size()).isEqualTo(2);
assertThat(set.contains("bar")).isTrue(); assertThat(set.contains("bar")).isTrue();
assertThat(set.contains("jenny")).isTrue(); assertThat(set.contains("jenny")).isTrue();
} }
@Test @Test
public void testMapFactory() throws Exception { public void testMapFactory() {
Map map = (Map) this.beanFactory.getBean("mapFactory"); Map map = (Map) this.beanFactory.getBean("mapFactory");
boolean condition = map instanceof TreeMap; assertThat(map instanceof TreeMap).isTrue();
assertThat(condition).isTrue();
assertThat(map.size()).isEqualTo(2); assertThat(map.size()).isEqualTo(2);
assertThat(map.get("foo")).isEqualTo("bar"); assertThat(map.get("foo")).isEqualTo("bar");
assertThat(map.get("jen")).isEqualTo("jenny"); assertThat(map.get("jen")).isEqualTo("jenny");
} }
@Test @Test
public void testPrototypeMapFactory() throws Exception { public void testPrototypeMapFactory() {
Map map = (Map) this.beanFactory.getBean("pMapFactory"); Map map = (Map) this.beanFactory.getBean("pMapFactory");
boolean condition = map instanceof TreeMap; assertThat(map instanceof TreeMap).isTrue();
assertThat(condition).isTrue();
assertThat(map.size()).isEqualTo(2); assertThat(map.size()).isEqualTo(2);
assertThat(map.get("foo")).isEqualTo("bar"); assertThat(map.get("foo")).isEqualTo("bar");
assertThat(map.get("jen")).isEqualTo("jenny"); assertThat(map.get("jen")).isEqualTo("jenny");
@ -429,8 +418,7 @@ public class XmlBeanCollectionTests {
@Test @Test
public void testChoiceBetweenSetAndMap() { public void testChoiceBetweenSetAndMap() {
MapAndSet sam = (MapAndSet) this.beanFactory.getBean("setAndMap"); MapAndSet sam = (MapAndSet) this.beanFactory.getBean("setAndMap");
boolean condition = sam.getObject() instanceof Map; assertThat(sam.getObject() instanceof Map).as("Didn't choose constructor with Map argument").isTrue();
assertThat(condition).as("Didn't choose constructor with Map argument").isTrue();
Map map = (Map) sam.getObject(); Map map = (Map) sam.getObject();
assertThat(map).hasSize(3); assertThat(map).hasSize(3);
assertThat(map.get("key1")).isEqualTo("val1"); assertThat(map.get("key1")).isEqualTo("val1");
@ -439,7 +427,7 @@ public class XmlBeanCollectionTests {
} }
@Test @Test
public void testEnumSetFactory() throws Exception { public void testEnumSetFactory() {
Set set = (Set) this.beanFactory.getBean("enumSetFactory"); Set set = (Set) this.beanFactory.getBean("enumSetFactory");
assertThat(set.size()).isEqualTo(2); assertThat(set.size()).isEqualTo(2);
assertThat(set.contains("ONE")).isTrue(); assertThat(set.contains("ONE")).isTrue();

View File

@ -34,33 +34,32 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
public class CustomCollectionEditorTests { public class CustomCollectionEditorTests {
@Test @Test
public void testCtorWithNullCollectionType() throws Exception { public void testCtorWithNullCollectionType() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new CustomCollectionEditor(null)); new CustomCollectionEditor(null));
} }
@Test @Test
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public void testCtorWithNonCollectionType() throws Exception { public void testCtorWithNonCollectionType() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new CustomCollectionEditor((Class) String.class)); new CustomCollectionEditor((Class) String.class));
} }
@Test @Test
public void testWithCollectionTypeThatDoesNotExposeAPublicNoArgCtor() throws Exception { public void testWithCollectionTypeThatDoesNotExposeAPublicNoArgCtor() {
CustomCollectionEditor editor = new CustomCollectionEditor(CollectionTypeWithNoNoArgCtor.class); CustomCollectionEditor editor = new CustomCollectionEditor(CollectionTypeWithNoNoArgCtor.class);
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
editor.setValue("1")); editor.setValue("1"));
} }
@Test @Test
public void testSunnyDaySetValue() throws Exception { public void testSunnyDaySetValue() {
CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class); CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class);
editor.setValue(new int[] {0, 1, 2}); editor.setValue(new int[] {0, 1, 2});
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).isNotNull(); assertThat(value).isNotNull();
boolean condition = value instanceof ArrayList; assertThat(value instanceof ArrayList).isTrue();
assertThat(condition).isTrue();
List<?> list = (List<?>) value; List<?> list = (List<?>) value;
assertThat(list).as("There must be 3 elements in the converted collection").hasSize(3); assertThat(list).as("There must be 3 elements in the converted collection").hasSize(3);
assertThat(list.get(0)).isEqualTo(0); assertThat(list.get(0)).isEqualTo(0);
@ -69,7 +68,7 @@ public class CustomCollectionEditorTests {
} }
@Test @Test
public void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() throws Exception { public void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() {
CustomCollectionEditor editor = new CustomCollectionEditor(Collection.class); CustomCollectionEditor editor = new CustomCollectionEditor(Collection.class);
editor.setValue("0, 1, 2"); editor.setValue("0, 1, 2");
Collection<?> value = (Collection<?>) editor.getValue(); Collection<?> value = (Collection<?>) editor.getValue();
@ -79,13 +78,12 @@ public class CustomCollectionEditorTests {
} }
@Test @Test
public void testSunnyDaySetAsTextYieldsSingleValue() throws Exception { public void testSunnyDaySetAsTextYieldsSingleValue() {
CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class); CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class);
editor.setValue("0, 1, 2"); editor.setValue("0, 1, 2");
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).isNotNull(); assertThat(value).isNotNull();
boolean condition = value instanceof ArrayList; assertThat(value instanceof ArrayList).isTrue();
assertThat(condition).isTrue();
List<?> list = (List<?>) value; List<?> list = (List<?>) value;
assertThat(list).as("There must be 1 element in the converted collection").hasSize(1); assertThat(list).as("There must be 1 element in the converted collection").hasSize(1);
assertThat(list.get(0)).isEqualTo("0, 1, 2"); assertThat(list.get(0)).isEqualTo("0, 1, 2");

View File

@ -193,36 +193,31 @@ class CustomEditorTests {
bw.setPropertyValue("bool1", "false"); bw.setPropertyValue("bool1", "false");
assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool1"))).as("Correct bool1 value").isTrue(); assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool1"))).as("Correct bool1 value").isTrue();
boolean condition4 = !tb.isBool1(); assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue();
assertThat(condition4).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", " true "); bw.setPropertyValue("bool1", " true ");
assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", " false "); bw.setPropertyValue("bool1", " false ");
boolean condition3 = !tb.isBool1(); assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue();
assertThat(condition3).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", "on"); bw.setPropertyValue("bool1", "on");
assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", "off"); bw.setPropertyValue("bool1", "off");
boolean condition2 = !tb.isBool1(); assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue();
assertThat(condition2).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", "yes"); bw.setPropertyValue("bool1", "yes");
assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", "no"); bw.setPropertyValue("bool1", "no");
boolean condition1 = !tb.isBool1(); assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue();
assertThat(condition1).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", "1"); bw.setPropertyValue("bool1", "1");
assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue();
bw.setPropertyValue("bool1", "0"); bw.setPropertyValue("bool1", "0");
boolean condition = !tb.isBool1(); assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue();
assertThat(condition).as("Correct bool1 value").isTrue();
assertThatExceptionOfType(BeansException.class).isThrownBy(() -> assertThatExceptionOfType(BeansException.class).isThrownBy(() ->
bw.setPropertyValue("bool1", "argh")); bw.setPropertyValue("bool1", "argh"));
@ -239,29 +234,25 @@ class CustomEditorTests {
bw.setPropertyValue("bool2", "false"); bw.setPropertyValue("bool2", "false");
assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue(); assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
boolean condition3 = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition3).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "on"); bw.setPropertyValue("bool2", "on");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "off"); bw.setPropertyValue("bool2", "off");
boolean condition2 = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition2).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "yes"); bw.setPropertyValue("bool2", "yes");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "no"); bw.setPropertyValue("bool2", "no");
boolean condition1 = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition1).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "1"); bw.setPropertyValue("bool2", "1");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "0"); bw.setPropertyValue("bool2", "0");
boolean condition = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", ""); bw.setPropertyValue("bool2", "");
assertThat(tb.getBool2()).as("Correct bool2 value").isNull(); assertThat(tb.getBool2()).as("Correct bool2 value").isNull();
@ -279,29 +270,25 @@ class CustomEditorTests {
bw.setPropertyValue("bool2", "false"); bw.setPropertyValue("bool2", "false");
assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue(); assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
boolean condition3 = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition3).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "on"); bw.setPropertyValue("bool2", "on");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "off"); bw.setPropertyValue("bool2", "off");
boolean condition2 = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition2).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "yes"); bw.setPropertyValue("bool2", "yes");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "no"); bw.setPropertyValue("bool2", "no");
boolean condition1 = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition1).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "1"); bw.setPropertyValue("bool2", "1");
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", "0"); bw.setPropertyValue("bool2", "0");
boolean condition = !tb.getBool2(); assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue();
assertThat(condition).as("Correct bool2 value").isTrue();
bw.setPropertyValue("bool2", ""); bw.setPropertyValue("bool2", "");
assertThat(bw.getPropertyValue("bool2")).as("Correct bool2 value").isNull(); assertThat(bw.getPropertyValue("bool2")).as("Correct bool2 value").isNull();
@ -309,7 +296,7 @@ class CustomEditorTests {
} }
@Test @Test
void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Exception { void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() {
String trueString = "pechorin"; String trueString = "pechorin";
String falseString = "nash"; String falseString = "nash";
@ -458,7 +445,7 @@ class CustomEditorTests {
} }
@Test @Test
void testCustomNumberEditorWithFrenchBigDecimal() throws Exception { void testCustomNumberEditorWithFrenchBigDecimal() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH); NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
NumberTestBean tb = new NumberTestBean(); NumberTestBean tb = new NumberTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb); BeanWrapper bw = new BeanWrapperImpl(tb);
@ -542,14 +529,14 @@ class CustomEditorTests {
} }
@Test @Test
void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() throws Exception { void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() {
PropertyEditor charEditor = new CharacterEditor(false); PropertyEditor charEditor = new CharacterEditor(false);
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
charEditor.setAsText("ColdWaterCanyon")); charEditor.setAsText("ColdWaterCanyon"));
} }
@Test @Test
void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception { void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() {
PropertyEditor charEditor = new CharacterEditor(false); PropertyEditor charEditor = new CharacterEditor(false);
assertThat(charEditor.getAsText()).isEmpty(); assertThat(charEditor.getAsText()).isEmpty();
charEditor = new CharacterEditor(true); charEditor = new CharacterEditor(true);
@ -562,7 +549,7 @@ class CustomEditorTests {
} }
@Test @Test
void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() throws Exception { void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() {
PropertyEditor charEditor = new CharacterEditor(false); PropertyEditor charEditor = new CharacterEditor(false);
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
charEditor.setAsText(null)); charEditor.setAsText(null));
@ -584,7 +571,7 @@ class CustomEditorTests {
} }
@Test @Test
void testClassEditorWithNonExistentClass() throws Exception { void testClassEditorWithNonExistentClass() {
PropertyEditor classEditor = new ClassEditor(); PropertyEditor classEditor = new ClassEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
classEditor.setAsText("hairdresser.on.Fire")); classEditor.setAsText("hairdresser.on.Fire"));
@ -602,7 +589,7 @@ class CustomEditorTests {
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays * SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
*/ */
@Test @Test
void testGetAsTextWithTwoDimensionalArray() throws Exception { void testGetAsTextWithTwoDimensionalArray() {
String[][] chessboard = new String[8][8]; String[][] chessboard = new String[8][8];
ClassEditor editor = new ClassEditor(); ClassEditor editor = new ClassEditor();
editor.setValue(chessboard.getClass()); editor.setValue(chessboard.getClass());
@ -613,7 +600,7 @@ class CustomEditorTests {
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays * SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
*/ */
@Test @Test
void testGetAsTextWithRidiculousMultiDimensionalArray() throws Exception { void testGetAsTextWithRidiculousMultiDimensionalArray() {
String[][][][][] ridiculousChessboard = new String[8][4][0][1][3]; String[][][][][] ridiculousChessboard = new String[8][4][0][1][3];
ClassEditor editor = new ClassEditor(); ClassEditor editor = new ClassEditor();
editor.setValue(ridiculousChessboard.getClass()); editor.setValue(ridiculousChessboard.getClass());
@ -1413,7 +1400,7 @@ class CustomEditorTests {
} }
@Test @Test
void testClassArrayEditorSunnyDay() throws Exception { void testClassArrayEditorSunnyDay() {
ClassArrayEditor classArrayEditor = new ClassArrayEditor(); ClassArrayEditor classArrayEditor = new ClassArrayEditor();
classArrayEditor.setAsText("java.lang.String,java.util.HashMap"); classArrayEditor.setAsText("java.lang.String,java.util.HashMap");
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue(); Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
@ -1426,7 +1413,7 @@ class CustomEditorTests {
} }
@Test @Test
void testClassArrayEditorSunnyDayWithArrayTypes() throws Exception { void testClassArrayEditorSunnyDayWithArrayTypes() {
ClassArrayEditor classArrayEditor = new ClassArrayEditor(); ClassArrayEditor classArrayEditor = new ClassArrayEditor();
classArrayEditor.setAsText("java.lang.String[],java.util.Map[],int[],float[][][]"); classArrayEditor.setAsText("java.lang.String[],java.util.Map[],int[],float[][][]");
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue(); Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
@ -1441,7 +1428,7 @@ class CustomEditorTests {
} }
@Test @Test
void testClassArrayEditorSetAsTextWithNull() throws Exception { void testClassArrayEditorSetAsTextWithNull() {
ClassArrayEditor editor = new ClassArrayEditor(); ClassArrayEditor editor = new ClassArrayEditor();
editor.setAsText(null); editor.setAsText(null);
assertThat(editor.getValue()).isNull(); assertThat(editor.getValue()).isNull();
@ -1449,7 +1436,7 @@ class CustomEditorTests {
} }
@Test @Test
void testClassArrayEditorSetAsTextWithEmptyString() throws Exception { void testClassArrayEditorSetAsTextWithEmptyString() {
ClassArrayEditor editor = new ClassArrayEditor(); ClassArrayEditor editor = new ClassArrayEditor();
editor.setAsText(""); editor.setAsText("");
assertThat(editor.getValue()).isNull(); assertThat(editor.getValue()).isNull();
@ -1457,7 +1444,7 @@ class CustomEditorTests {
} }
@Test @Test
void testClassArrayEditorSetAsTextWithWhitespaceString() throws Exception { void testClassArrayEditorSetAsTextWithWhitespaceString() {
ClassArrayEditor editor = new ClassArrayEditor(); ClassArrayEditor editor = new ClassArrayEditor();
editor.setAsText("\n"); editor.setAsText("\n");
assertThat(editor.getValue()).isNull(); assertThat(editor.getValue()).isNull();
@ -1465,7 +1452,7 @@ class CustomEditorTests {
} }
@Test @Test
void testCharsetEditor() throws Exception { void testCharsetEditor() {
CharsetEditor editor = new CharsetEditor(); CharsetEditor editor = new CharsetEditor();
String name = "UTF-8"; String name = "UTF-8";
editor.setAsText(name); editor.setAsText(name);

View File

@ -34,57 +34,51 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
public class FileEditorTests { public class FileEditorTests {
@Test @Test
public void testClasspathFileName() throws Exception { public void testClasspathFileName() {
PropertyEditor fileEditor = new FileEditor(); PropertyEditor fileEditor = new FileEditor();
fileEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + fileEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
ClassUtils.getShortName(getClass()) + ".class"); ClassUtils.getShortName(getClass()) + ".class");
Object value = fileEditor.getValue(); Object value = fileEditor.getValue();
boolean condition = value instanceof File; assertThat(value instanceof File).isTrue();
assertThat(condition).isTrue();
File file = (File) value; File file = (File) value;
assertThat(file).exists(); assertThat(file).exists();
} }
@Test @Test
public void testWithNonExistentResource() throws Exception { public void testWithNonExistentResource() {
PropertyEditor propertyEditor = new FileEditor(); PropertyEditor propertyEditor = new FileEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc")); propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc"));
} }
@Test @Test
public void testWithNonExistentFile() throws Exception { public void testWithNonExistentFile() {
PropertyEditor fileEditor = new FileEditor(); PropertyEditor fileEditor = new FileEditor();
fileEditor.setAsText("file:no_way_this_file_is_found.doc"); fileEditor.setAsText("file:no_way_this_file_is_found.doc");
Object value = fileEditor.getValue(); Object value = fileEditor.getValue();
boolean condition1 = value instanceof File; assertThat(value instanceof File).isTrue();
assertThat(condition1).isTrue();
File file = (File) value; File file = (File) value;
boolean condition = !file.exists(); assertThat(file).doesNotExist();
assertThat(condition).isTrue();
} }
@Test @Test
public void testAbsoluteFileName() throws Exception { public void testAbsoluteFileName() {
PropertyEditor fileEditor = new FileEditor(); PropertyEditor fileEditor = new FileEditor();
fileEditor.setAsText("/no_way_this_file_is_found.doc"); fileEditor.setAsText("/no_way_this_file_is_found.doc");
Object value = fileEditor.getValue(); Object value = fileEditor.getValue();
boolean condition1 = value instanceof File; assertThat(value instanceof File).isTrue();
assertThat(condition1).isTrue();
File file = (File) value; File file = (File) value;
boolean condition = !file.exists(); assertThat(file).doesNotExist();
assertThat(condition).isTrue();
} }
@Test @Test
public void testUnqualifiedFileNameFound() throws Exception { public void testUnqualifiedFileNameFound() {
PropertyEditor fileEditor = new FileEditor(); PropertyEditor fileEditor = new FileEditor();
String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
ClassUtils.getShortName(getClass()) + ".class"; ClassUtils.getShortName(getClass()) + ".class";
fileEditor.setAsText(fileName); fileEditor.setAsText(fileName);
Object value = fileEditor.getValue(); Object value = fileEditor.getValue();
boolean condition = value instanceof File; assertThat(value instanceof File).isTrue();
assertThat(condition).isTrue();
File file = (File) value; File file = (File) value;
assertThat(file).exists(); assertThat(file).exists();
String absolutePath = file.getAbsolutePath().replace('\\', '/'); String absolutePath = file.getAbsolutePath().replace('\\', '/');
@ -92,14 +86,13 @@ public class FileEditorTests {
} }
@Test @Test
public void testUnqualifiedFileNameNotFound() throws Exception { public void testUnqualifiedFileNameNotFound() {
PropertyEditor fileEditor = new FileEditor(); PropertyEditor fileEditor = new FileEditor();
String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" +
ClassUtils.getShortName(getClass()) + ".clazz"; ClassUtils.getShortName(getClass()) + ".clazz";
fileEditor.setAsText(fileName); fileEditor.setAsText(fileName);
Object value = fileEditor.getValue(); Object value = fileEditor.getValue();
boolean condition = value instanceof File; assertThat(value instanceof File).isTrue();
assertThat(condition).isTrue();
File file = (File) value; File file = (File) value;
assertThat(file).doesNotExist(); assertThat(file).doesNotExist();
String absolutePath = file.getAbsolutePath().replace('\\', '/'); String absolutePath = file.getAbsolutePath().replace('\\', '/');

View File

@ -16,6 +16,7 @@
package org.springframework.beans.propertyeditors; package org.springframework.beans.propertyeditors;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -34,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
public class InputStreamEditorTests { public class InputStreamEditorTests {
@Test @Test
public void testCtorWithNullResourceEditor() throws Exception { public void testCtorWithNullResourceEditor() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new InputStreamEditor(null)); new InputStreamEditor(null));
} }
@Test @Test
public void testSunnyDay() throws Exception { public void testSunnyDay() throws IOException {
InputStream stream = null; InputStream stream = null;
try { try {
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
@ -49,8 +50,7 @@ public class InputStreamEditorTests {
editor.setAsText(resource); editor.setAsText(resource);
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).isNotNull(); assertThat(value).isNotNull();
boolean condition = value instanceof InputStream; assertThat(value instanceof InputStream).isTrue();
assertThat(condition).isTrue();
stream = (InputStream) value; stream = (InputStream) value;
assertThat(stream.available()).isGreaterThan(0); assertThat(stream.available()).isGreaterThan(0);
} }
@ -62,14 +62,14 @@ public class InputStreamEditorTests {
} }
@Test @Test
public void testWhenResourceDoesNotExist() throws Exception { public void testWhenResourceDoesNotExist() {
InputStreamEditor editor = new InputStreamEditor(); InputStreamEditor editor = new InputStreamEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
editor.setAsText("classpath:bingo!")); editor.setAsText("classpath:bingo!"));
} }
@Test @Test
public void testGetAsTextReturnsNullByDefault() throws Exception { public void testGetAsTextReturnsNullByDefault() {
assertThat(new InputStreamEditor().getAsText()).isNull(); assertThat(new InputStreamEditor().getAsText()).isNull();
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
"/" + ClassUtils.getShortName(getClass()) + ".class"; "/" + ClassUtils.getShortName(getClass()) + ".class";

View File

@ -151,7 +151,7 @@ public class PropertiesEditorTests {
} }
@Test @Test
public void usingMapAsValueSource() throws Exception { public void usingMapAsValueSource() {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("one", "1"); map.put("one", "1");
map.put("two", "2"); map.put("two", "2");
@ -160,8 +160,7 @@ public class PropertiesEditorTests {
pe.setValue(map); pe.setValue(map);
Object value = pe.getValue(); Object value = pe.getValue();
assertThat(value).isNotNull(); assertThat(value).isNotNull();
boolean condition = value instanceof Properties; assertThat(value instanceof Properties).isTrue();
assertThat(condition).isTrue();
Properties props = (Properties) value; Properties props = (Properties) value;
assertThat(props).hasSize(3); assertThat(props).hasSize(3);
assertThat(props.getProperty("one")).isEqualTo("1"); assertThat(props.getProperty("one")).isEqualTo("1");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.springframework.beans.propertyeditors; package org.springframework.beans.propertyeditors;
import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -34,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
public class ReaderEditorTests { public class ReaderEditorTests {
@Test @Test
public void testCtorWithNullResourceEditor() throws Exception { public void testCtorWithNullResourceEditor() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new ReaderEditor(null)); new ReaderEditor(null));
} }
@Test @Test
public void testSunnyDay() throws Exception { public void testSunnyDay() throws IOException {
Reader reader = null; Reader reader = null;
try { try {
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
@ -49,8 +50,7 @@ public class ReaderEditorTests {
editor.setAsText(resource); editor.setAsText(resource);
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).isNotNull(); assertThat(value).isNotNull();
boolean condition = value instanceof Reader; assertThat(value instanceof Reader).isTrue();
assertThat(condition).isTrue();
reader = (Reader) value; reader = (Reader) value;
assertThat(reader.ready()).isTrue(); assertThat(reader.ready()).isTrue();
} }
@ -62,7 +62,7 @@ public class ReaderEditorTests {
} }
@Test @Test
public void testWhenResourceDoesNotExist() throws Exception { public void testWhenResourceDoesNotExist() {
String resource = "classpath:bingo!"; String resource = "classpath:bingo!";
ReaderEditor editor = new ReaderEditor(); ReaderEditor editor = new ReaderEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
@ -70,7 +70,7 @@ public class ReaderEditorTests {
} }
@Test @Test
public void testGetAsTextReturnsNullByDefault() throws Exception { public void testGetAsTextReturnsNullByDefault() {
assertThat(new ReaderEditor().getAsText()).isNull(); assertThat(new ReaderEditor().getAsText()).isNull();
String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
"/" + ClassUtils.getShortName(getClass()) + ".class"; "/" + ClassUtils.getShortName(getClass()) + ".class";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,93 +37,88 @@ public class ResourceBundleEditorTests {
@Test @Test
public void testSetAsTextWithJustBaseName() throws Exception { public void testSetAsTextWithJustBaseName() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
editor.setAsText(BASE_NAME); editor.setAsText(BASE_NAME);
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull();
boolean condition = value instanceof ResourceBundle; assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
ResourceBundle bundle = (ResourceBundle) value; ResourceBundle bundle = (ResourceBundle) value;
String string = bundle.getString(MESSAGE_KEY); String string = bundle.getString(MESSAGE_KEY);
assertThat(string).isEqualTo(MESSAGE_KEY); assertThat(string).isEqualTo(MESSAGE_KEY);
} }
@Test @Test
public void testSetAsTextWithBaseNameThatEndsInDefaultSeparator() throws Exception { public void testSetAsTextWithBaseNameThatEndsInDefaultSeparator() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
editor.setAsText(BASE_NAME + "_"); editor.setAsText(BASE_NAME + "_");
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull();
boolean condition = value instanceof ResourceBundle; assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
ResourceBundle bundle = (ResourceBundle) value; ResourceBundle bundle = (ResourceBundle) value;
String string = bundle.getString(MESSAGE_KEY); String string = bundle.getString(MESSAGE_KEY);
assertThat(string).isEqualTo(MESSAGE_KEY); assertThat(string).isEqualTo(MESSAGE_KEY);
} }
@Test @Test
public void testSetAsTextWithBaseNameAndLanguageCode() throws Exception { public void testSetAsTextWithBaseNameAndLanguageCode() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
editor.setAsText(BASE_NAME + "Lang" + "_en"); editor.setAsText(BASE_NAME + "Lang" + "_en");
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull();
boolean condition = value instanceof ResourceBundle; assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
ResourceBundle bundle = (ResourceBundle) value; ResourceBundle bundle = (ResourceBundle) value;
String string = bundle.getString(MESSAGE_KEY); String string = bundle.getString(MESSAGE_KEY);
assertThat(string).isEqualTo("yob"); assertThat(string).isEqualTo("yob");
} }
@Test @Test
public void testSetAsTextWithBaseNameLanguageAndCountryCode() throws Exception { public void testSetAsTextWithBaseNameLanguageAndCountryCode() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
editor.setAsText(BASE_NAME + "LangCountry" + "_en_GB"); editor.setAsText(BASE_NAME + "LangCountry" + "_en_GB");
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull();
boolean condition = value instanceof ResourceBundle; assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
ResourceBundle bundle = (ResourceBundle) value; ResourceBundle bundle = (ResourceBundle) value;
String string = bundle.getString(MESSAGE_KEY); String string = bundle.getString(MESSAGE_KEY);
assertThat(string).isEqualTo("chav"); assertThat(string).isEqualTo("chav");
} }
@Test @Test
public void testSetAsTextWithTheKitchenSink() throws Exception { public void testSetAsTextWithTheKitchenSink() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
editor.setAsText(BASE_NAME + "LangCountryDialect" + "_en_GB_GLASGOW"); editor.setAsText(BASE_NAME + "LangCountryDialect" + "_en_GB_GLASGOW");
Object value = editor.getValue(); Object value = editor.getValue();
assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull();
boolean condition = value instanceof ResourceBundle; assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue();
ResourceBundle bundle = (ResourceBundle) value; ResourceBundle bundle = (ResourceBundle) value;
String string = bundle.getString(MESSAGE_KEY); String string = bundle.getString(MESSAGE_KEY);
assertThat(string).isEqualTo("ned"); assertThat(string).isEqualTo("ned");
} }
@Test @Test
public void testSetAsTextWithNull() throws Exception { public void testSetAsTextWithNull() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
editor.setAsText(null)); editor.setAsText(null));
} }
@Test @Test
public void testSetAsTextWithEmptyString() throws Exception { public void testSetAsTextWithEmptyString() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
editor.setAsText("")); editor.setAsText(""));
} }
@Test @Test
public void testSetAsTextWithWhiteSpaceString() throws Exception { public void testSetAsTextWithWhiteSpaceString() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
editor.setAsText(" ")); editor.setAsText(" "));
} }
@Test @Test
public void testSetAsTextWithJustSeparatorString() throws Exception { public void testSetAsTextWithJustSeparatorString() {
ResourceBundleEditor editor = new ResourceBundleEditor(); ResourceBundleEditor editor = new ResourceBundleEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
editor.setAsText("_")); editor.setAsText("_"));

View File

@ -32,78 +32,72 @@ import static org.assertj.core.api.Assertions.assertThat;
public class URIEditorTests { public class URIEditorTests {
@Test @Test
public void standardURI() throws Exception { public void standardURI() {
doTestURI("mailto:juergen.hoeller@interface21.com"); doTestURI("mailto:juergen.hoeller@interface21.com");
} }
@Test @Test
public void withNonExistentResource() throws Exception { public void withNonExistentResource() {
doTestURI("gonna:/freak/in/the/morning/freak/in/the.evening"); doTestURI("gonna:/freak/in/the/morning/freak/in/the.evening");
} }
@Test @Test
public void standardURL() throws Exception { public void standardURL() {
doTestURI("https://www.springframework.org"); doTestURI("https://www.springframework.org");
} }
@Test @Test
public void standardURLWithFragment() throws Exception { public void standardURLWithFragment() {
doTestURI("https://www.springframework.org#1"); doTestURI("https://www.springframework.org#1");
} }
@Test @Test
public void standardURLWithWhitespace() throws Exception { public void standardURLWithWhitespace() {
PropertyEditor uriEditor = new URIEditor(); PropertyEditor uriEditor = new URIEditor();
uriEditor.setAsText(" https://www.springframework.org "); uriEditor.setAsText(" https://www.springframework.org ");
Object value = uriEditor.getValue(); Object value = uriEditor.getValue();
boolean condition = value instanceof URI; assertThat(value instanceof URI).isTrue();
assertThat(condition).isTrue();
URI uri = (URI) value; URI uri = (URI) value;
assertThat(uri.toString()).isEqualTo("https://www.springframework.org"); assertThat(uri.toString()).isEqualTo("https://www.springframework.org");
} }
@Test @Test
public void classpathURL() throws Exception { public void classpathURL() {
PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader()); PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader());
uriEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + uriEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
"/" + ClassUtils.getShortName(getClass()) + ".class"); "/" + ClassUtils.getShortName(getClass()) + ".class");
Object value = uriEditor.getValue(); Object value = uriEditor.getValue();
boolean condition1 = value instanceof URI; assertThat(value instanceof URI).isTrue();
assertThat(condition1).isTrue();
URI uri = (URI) value; URI uri = (URI) value;
assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
boolean condition = !uri.getScheme().startsWith("classpath"); assertThat(uri.getScheme()).doesNotStartWith("classpath");
assertThat(condition).isTrue();
} }
@Test @Test
public void classpathURLWithWhitespace() throws Exception { public void classpathURLWithWhitespace() {
PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader()); PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader());
uriEditor.setAsText(" classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + uriEditor.setAsText(" classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
"/" + ClassUtils.getShortName(getClass()) + ".class "); "/" + ClassUtils.getShortName(getClass()) + ".class ");
Object value = uriEditor.getValue(); Object value = uriEditor.getValue();
boolean condition1 = value instanceof URI; assertThat(value instanceof URI).isTrue();
assertThat(condition1).isTrue();
URI uri = (URI) value; URI uri = (URI) value;
assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
boolean condition = !uri.getScheme().startsWith("classpath"); assertThat(uri.getScheme()).doesNotStartWith("classpath");
assertThat(condition).isTrue();
} }
@Test @Test
public void classpathURLAsIs() throws Exception { public void classpathURLAsIs() {
PropertyEditor uriEditor = new URIEditor(); PropertyEditor uriEditor = new URIEditor();
uriEditor.setAsText("classpath:test.txt"); uriEditor.setAsText("classpath:test.txt");
Object value = uriEditor.getValue(); Object value = uriEditor.getValue();
boolean condition = value instanceof URI; assertThat(value instanceof URI).isTrue();
assertThat(condition).isTrue();
URI uri = (URI) value; URI uri = (URI) value;
assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
assertThat(uri.getScheme()).startsWith("classpath"); assertThat(uri.getScheme()).startsWith("classpath");
} }
@Test @Test
public void setAsTextWithNull() throws Exception { public void setAsTextWithNull() {
PropertyEditor uriEditor = new URIEditor(); PropertyEditor uriEditor = new URIEditor();
uriEditor.setAsText(null); uriEditor.setAsText(null);
assertThat(uriEditor.getValue()).isNull(); assertThat(uriEditor.getValue()).isNull();
@ -111,30 +105,28 @@ public class URIEditorTests {
} }
@Test @Test
public void getAsTextReturnsEmptyStringIfValueNotSet() throws Exception { public void getAsTextReturnsEmptyStringIfValueNotSet() {
PropertyEditor uriEditor = new URIEditor(); PropertyEditor uriEditor = new URIEditor();
assertThat(uriEditor.getAsText()).isEmpty(); assertThat(uriEditor.getAsText()).isEmpty();
} }
@Test @Test
public void encodeURI() throws Exception { public void encodeURI() {
PropertyEditor uriEditor = new URIEditor(); PropertyEditor uriEditor = new URIEditor();
uriEditor.setAsText("https://example.com/spaces and \u20AC"); uriEditor.setAsText("https://example.com/spaces and \u20AC");
Object value = uriEditor.getValue(); Object value = uriEditor.getValue();
boolean condition = value instanceof URI; assertThat(value instanceof URI).isTrue();
assertThat(condition).isTrue();
URI uri = (URI) value; URI uri = (URI) value;
assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
assertThat(uri.toASCIIString()).isEqualTo("https://example.com/spaces%20and%20%E2%82%AC"); assertThat(uri.toASCIIString()).isEqualTo("https://example.com/spaces%20and%20%E2%82%AC");
} }
@Test @Test
public void encodeAlreadyEncodedURI() throws Exception { public void encodeAlreadyEncodedURI() {
PropertyEditor uriEditor = new URIEditor(false); PropertyEditor uriEditor = new URIEditor(false);
uriEditor.setAsText("https://example.com/spaces%20and%20%E2%82%AC"); uriEditor.setAsText("https://example.com/spaces%20and%20%E2%82%AC");
Object value = uriEditor.getValue(); Object value = uriEditor.getValue();
boolean condition = value instanceof URI; assertThat(value instanceof URI).isTrue();
assertThat(condition).isTrue();
URI uri = (URI) value; URI uri = (URI) value;
assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uriEditor.getAsText()).isEqualTo(uri.toString());
assertThat(uri.toASCIIString()).isEqualTo("https://example.com/spaces%20and%20%E2%82%AC"); assertThat(uri.toASCIIString()).isEqualTo("https://example.com/spaces%20and%20%E2%82%AC");
@ -145,8 +137,7 @@ public class URIEditorTests {
PropertyEditor uriEditor = new URIEditor(); PropertyEditor uriEditor = new URIEditor();
uriEditor.setAsText(uriSpec); uriEditor.setAsText(uriSpec);
Object value = uriEditor.getValue(); Object value = uriEditor.getValue();
boolean condition = value instanceof URI; assertThat(value instanceof URI).isTrue();
assertThat(condition).isTrue();
URI uri = (URI) value; URI uri = (URI) value;
assertThat(uri.toString()).isEqualTo(uriSpec); assertThat(uri.toString()).isEqualTo(uriSpec);
} }

View File

@ -33,56 +33,52 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
public class URLEditorTests { public class URLEditorTests {
@Test @Test
public void testCtorWithNullResourceEditor() throws Exception { public void testCtorWithNullResourceEditor() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
new URLEditor(null)); new URLEditor(null));
} }
@Test @Test
public void testStandardURI() throws Exception { public void testStandardURI() {
PropertyEditor urlEditor = new URLEditor(); PropertyEditor urlEditor = new URLEditor();
urlEditor.setAsText("mailto:juergen.hoeller@interface21.com"); urlEditor.setAsText("mailto:juergen.hoeller@interface21.com");
Object value = urlEditor.getValue(); Object value = urlEditor.getValue();
boolean condition = value instanceof URL; assertThat(value instanceof URL).isTrue();
assertThat(condition).isTrue();
URL url = (URL) value; URL url = (URL) value;
assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm()); assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm());
} }
@Test @Test
public void testStandardURL() throws Exception { public void testStandardURL() {
PropertyEditor urlEditor = new URLEditor(); PropertyEditor urlEditor = new URLEditor();
urlEditor.setAsText("https://www.springframework.org"); urlEditor.setAsText("https://www.springframework.org");
Object value = urlEditor.getValue(); Object value = urlEditor.getValue();
boolean condition = value instanceof URL; assertThat(value instanceof URL).isTrue();
assertThat(condition).isTrue();
URL url = (URL) value; URL url = (URL) value;
assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm()); assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm());
} }
@Test @Test
public void testClasspathURL() throws Exception { public void testClasspathURL() {
PropertyEditor urlEditor = new URLEditor(); PropertyEditor urlEditor = new URLEditor();
urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) +
"/" + ClassUtils.getShortName(getClass()) + ".class"); "/" + ClassUtils.getShortName(getClass()) + ".class");
Object value = urlEditor.getValue(); Object value = urlEditor.getValue();
boolean condition1 = value instanceof URL; assertThat(value instanceof URL).isTrue();
assertThat(condition1).isTrue();
URL url = (URL) value; URL url = (URL) value;
assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm()); assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm());
boolean condition = !url.getProtocol().startsWith("classpath"); assertThat(url.getProtocol()).doesNotStartWith("classpath");
assertThat(condition).isTrue();
} }
@Test @Test
public void testWithNonExistentResource() throws Exception { public void testWithNonExistentResource() {
PropertyEditor urlEditor = new URLEditor(); PropertyEditor urlEditor = new URLEditor();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening")); urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening"));
} }
@Test @Test
public void testSetAsTextWithNull() throws Exception { public void testSetAsTextWithNull() {
PropertyEditor urlEditor = new URLEditor(); PropertyEditor urlEditor = new URLEditor();
urlEditor.setAsText(null); urlEditor.setAsText(null);
assertThat(urlEditor.getValue()).isNull(); assertThat(urlEditor.getValue()).isNull();
@ -90,7 +86,7 @@ public class URLEditorTests {
} }
@Test @Test
public void testGetAsTextReturnsEmptyStringIfValueNotSet() throws Exception { public void testGetAsTextReturnsEmptyStringIfValueNotSet() {
PropertyEditor urlEditor = new URLEditor(); PropertyEditor urlEditor = new URLEditor();
assertThat(urlEditor.getAsText()).isEmpty(); assertThat(urlEditor.getAsText()).isEmpty();
} }