diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java index 5e049f8d2b..b3cbede748 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java @@ -390,7 +390,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess @Override @Nullable 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) */ public Class getBeanClass() throws IllegalStateException { - Object beanClassObject = this.beanClass; + Object beanClassObject = this.beanClass; // defensive access to volatile beanClass field if (beanClassObject == null) { throw new IllegalStateException("No bean class specified on bean definition"); } diff --git a/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyValuesTests.java b/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyValuesTests.java index 43140febc5..26bd33066e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyValuesTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyValuesTests.java @@ -35,8 +35,7 @@ public abstract class AbstractPropertyValuesTests { assertThat(pvs.contains("forname")).as("Contains forname").isTrue(); assertThat(pvs.contains("surname")).as("Contains surname").isTrue(); assertThat(pvs.contains("age")).as("Contains age").isTrue(); - boolean condition1 = !pvs.contains("tory"); - assertThat(condition1).as("Doesn't contain tory").isTrue(); + assertThat(!pvs.contains("tory")).as("Doesn't contain tory").isTrue(); PropertyValue[] ps = pvs.getPropertyValues(); Map m = new HashMap<>(); @@ -46,8 +45,7 @@ public abstract class AbstractPropertyValuesTests { for (PropertyValue element : ps) { Object val = m.get(element.getName()); assertThat(val).as("Can't have unexpected value").isNotNull(); - boolean condition = val instanceof String; - assertThat(condition).as("Val i string").isTrue(); + assertThat(val instanceof String).as("Val i string").isTrue(); assertThat(val.equals(element.getValue())).as("val matches expected").isTrue(); m.remove(element.getName()); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java index 175065ce38..5ba2aec57c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java @@ -155,8 +155,7 @@ public class BeanFactoryUtilsTests { assertThat(beans.get("t1")).isEqualTo(t1); assertThat(beans.get("t2")).isEqualTo(t2); assertThat(beans.get("t3")).isEqualTo(t3.getObject()); - boolean condition = beans.get("t4") instanceof TestBean; - assertThat(condition).isTrue(); + assertThat(beans.get("t4") instanceof TestBean).isTrue(); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true); assertThat(beans).hasSize(2); @@ -192,8 +191,7 @@ public class BeanFactoryUtilsTests { assertThat(beans.get("t1")).isEqualTo(t1); assertThat(beans.get("t2")).isEqualTo(t2); assertThat(beans.get("t3")).isEqualTo(t3.getObject()); - boolean condition2 = beans.get("t4") instanceof TestBean; - assertThat(condition2).isTrue(); + assertThat(beans.get("t4") instanceof TestBean).isTrue(); // 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 // 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("test")).isEqualTo(test); assertThat(beans.get("testFactory1")).isEqualTo(testFactory1); - boolean condition1 = beans.get("testFactory2") instanceof TestBean; - assertThat(condition1).isTrue(); + assertThat(beans.get("testFactory2") instanceof TestBean).isTrue(); assertThat(beans.get("t1")).isEqualTo(t1); assertThat(beans.get("t2")).isEqualTo(t2); assertThat(beans.get("t3")).isEqualTo(t3.getObject()); - boolean condition = beans.get("t4") instanceof TestBean; - assertThat(condition).isTrue(); + assertThat(beans.get("t4") instanceof TestBean).isTrue(); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true); assertThat(beans).hasSize(4); @@ -261,8 +257,7 @@ public class BeanFactoryUtilsTests { assertThat(beans.get("test3")).isEqualTo(test3); assertThat(beans.get("test")).isEqualTo(test); assertThat(beans.get("testFactory1")).isEqualTo(testFactory1); - boolean condition = beans.get("testFactory2") instanceof TestBean; - assertThat(condition).isTrue(); + assertThat(beans.get("testFactory2") instanceof TestBean).isTrue(); beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true); assertThat(beans).hasSize(2); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java index de14305f70..e94e472d0a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java @@ -85,8 +85,7 @@ public class InjectAnnotationBeanPostProcessorTests { bf.getBean("testBean"); } catch (BeanCreationException ex) { - boolean condition = ex.getRootCause() instanceof IllegalStateException; - assertThat(condition).isTrue(); + assertThat(ex.getRootCause() instanceof IllegalStateException).isTrue(); } } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java index 48abf9e720..1eb97f98e5 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java @@ -66,8 +66,7 @@ public class CustomScopeConfigurerTests { CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); - boolean condition = factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope; - assertThat(condition).isTrue(); + assertThat(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope).isTrue(); } @Test @@ -77,8 +76,7 @@ public class CustomScopeConfigurerTests { CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.setScopes(scopes); figurer.postProcessBeanFactory(factory); - boolean condition = factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope; - assertThat(condition).isTrue(); + assertThat(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope).isTrue(); } @Test diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java index c70408a6f4..b406e3c938 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java @@ -49,8 +49,7 @@ public class PropertyPathFactoryBeanTests { assertThat(xbf.getType("otb.spouse")).isEqualTo(ITestBean.class); Object result1 = xbf.getBean("otb.spouse"); Object result2 = xbf.getBean("otb.spouse"); - boolean condition = result1 instanceof TestBean; - assertThat(condition).isTrue(); + assertThat(result1 instanceof TestBean).isTrue(); assertThat(result1).isSameAs(result2); assertThat(((TestBean) result1).getAge()).isEqualTo(99); } @@ -64,12 +63,9 @@ public class PropertyPathFactoryBeanTests { Object result1 = xbf.getBean("tb.spouse"); Object result2 = xbf.getBean("propertyPath3"); Object result3 = xbf.getBean("propertyPath3"); - boolean condition2 = result1 instanceof TestBean; - assertThat(condition2).isTrue(); - boolean condition1 = result2 instanceof TestBean; - assertThat(condition1).isTrue(); - boolean condition = result3 instanceof TestBean; - assertThat(condition).isTrue(); + assertThat(result1 instanceof TestBean).isTrue(); + assertThat(result2 instanceof TestBean).isTrue(); + assertThat(result3 instanceof TestBean).isTrue(); assertThat(((TestBean) result1).getAge()).isEqualTo(11); assertThat(((TestBean) result2).getAge()).isEqualTo(11); assertThat(((TestBean) result3).getAge()).isEqualTo(11); @@ -93,8 +89,7 @@ public class PropertyPathFactoryBeanTests { TestBean spouse = (TestBean) xbf.getBean("otb.spouse"); TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner"); assertThat(tbWithInner.getSpouse()).isSameAs(spouse); - boolean condition = !tbWithInner.getFriends().isEmpty(); - assertThat(condition).isTrue(); + assertThat(!tbWithInner.getFriends().isEmpty()).isTrue(); assertThat(tbWithInner.getFriends().iterator().next()).isSameAs(spouse); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java index fe074daf3e..1d80dfd9b2 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java @@ -198,14 +198,10 @@ public class ServiceLocatorFactoryBeanTests { assertThat(testBean3).isNotSameAs(testBean2); assertThat(testBean4).isNotSameAs(testBean2); assertThat(testBean4).isNotSameAs(testBean3); - boolean condition3 = testBean1 instanceof ExtendedTestService; - assertThat(condition3).isFalse(); - boolean condition2 = testBean2 instanceof ExtendedTestService; - assertThat(condition2).isFalse(); - boolean condition1 = testBean3 instanceof ExtendedTestService; - assertThat(condition1).isFalse(); - boolean condition = testBean4 instanceof ExtendedTestService; - assertThat(condition).isTrue(); + assertThat(testBean1 instanceof ExtendedTestService).isFalse(); + assertThat(testBean2 instanceof ExtendedTestService).isFalse(); + assertThat(testBean3 instanceof ExtendedTestService).isFalse(); + assertThat(testBean4 instanceof ExtendedTestService).isTrue(); } @Test @@ -264,17 +260,14 @@ public class ServiceLocatorFactoryBeanTests { public static class TestService { - } public static class ExtendedTestService extends TestService { - } public static class TestService2 { - } @@ -345,7 +338,6 @@ public class ServiceLocatorFactoryBeanTests { @SuppressWarnings("serial") public static class ExceptionClassWithOnlyZeroArgCtor extends Exception { - } } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java index abef27bf44..defb200e81 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java @@ -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"); * 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.containsKey("foo")).isTrue(); Object object = map.get("foo"); - boolean condition = object instanceof LinkedHashMap; - assertThat(condition).isTrue(); + assertThat(object instanceof LinkedHashMap).isTrue(); @SuppressWarnings("unchecked") Map sub = (Map) object; assertThat(sub.containsKey("key1.key2")).isTrue(); @@ -115,8 +114,7 @@ public class YamlMapFactoryBeanTests { assertThat(map).hasSize(1); assertThat(map.containsKey("foo")).isTrue(); Object object = map.get("foo"); - boolean condition = object instanceof LinkedHashMap; - assertThat(condition).isTrue(); + assertThat(object instanceof LinkedHashMap).isTrue(); @SuppressWarnings("unchecked") Map sub = (Map) object; assertThat(sub).hasSize(1); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java index bdf544c6c5..6f8f956863 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/serviceloader/ServiceLoaderTests.java @@ -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"); * 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()); bf.registerBeanDefinition("service", bd); ServiceLoader serviceLoader = (ServiceLoader) bf.getBean("service"); - boolean condition = serviceLoader.iterator().next() instanceof DocumentBuilderFactory; - assertThat(condition).isTrue(); + assertThat(serviceLoader.iterator().next() instanceof DocumentBuilderFactory).isTrue(); } @Test @@ -58,8 +57,7 @@ class ServiceLoaderTests { RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); bf.registerBeanDefinition("service", bd); - boolean condition = bf.getBean("service") instanceof DocumentBuilderFactory; - assertThat(condition).isTrue(); + assertThat(bf.getBean("service") instanceof DocumentBuilderFactory).isTrue(); } @Test @@ -69,8 +67,7 @@ class ServiceLoaderTests { bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); bf.registerBeanDefinition("service", bd); List serviceList = (List) bf.getBean("service"); - boolean condition = serviceList.get(0) instanceof DocumentBuilderFactory; - assertThat(condition).isTrue(); + assertThat(serviceList.get(0) instanceof DocumentBuilderFactory).isTrue(); } } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java index 0499e16e35..5ef9a6dc8a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java @@ -35,10 +35,8 @@ public class BeanDefinitionTests { bd.setLazyInit(true); bd.setScope("request"); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); - boolean condition1 = !bd.equals(otherBd); - assertThat(condition1).isTrue(); - boolean condition = !otherBd.equals(bd); - assertThat(condition).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.setAbstract(true); otherBd.setLazyInit(true); otherBd.setScope("request"); @@ -54,15 +52,11 @@ public class BeanDefinitionTests { bd.getPropertyValues().add("age", "99"); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); otherBd.getPropertyValues().add("name", "myName"); - boolean condition3 = !bd.equals(otherBd); - assertThat(condition3).isTrue(); - boolean condition2 = !otherBd.equals(bd); - assertThat(condition2).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.getPropertyValues().add("age", "11"); - boolean condition1 = !bd.equals(otherBd); - assertThat(condition1).isTrue(); - boolean condition = !otherBd.equals(bd); - assertThat(condition).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.getPropertyValues().add("age", "99"); assertThat(bd.equals(otherBd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue(); @@ -76,15 +70,11 @@ public class BeanDefinitionTests { bd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); otherBd.getConstructorArgumentValues().addGenericArgumentValue("test"); - boolean condition3 = !bd.equals(otherBd); - assertThat(condition3).isTrue(); - boolean condition2 = !otherBd.equals(bd); - assertThat(condition2).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 9); - boolean condition1 = !bd.equals(otherBd); - assertThat(condition1).isTrue(); - boolean condition = !otherBd.equals(bd); - assertThat(condition).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); assertThat(bd.equals(otherBd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue(); @@ -99,15 +89,11 @@ public class BeanDefinitionTests { RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); otherBd.getConstructorArgumentValues().addGenericArgumentValue("test", "int"); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); - boolean condition3 = !bd.equals(otherBd); - assertThat(condition3).isTrue(); - boolean condition2 = !otherBd.equals(bd); - assertThat(condition2).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "int"); - boolean condition1 = !bd.equals(otherBd); - assertThat(condition1).isTrue(); - boolean condition = !otherBd.equals(bd); - assertThat(condition).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "long"); assertThat(bd.equals(otherBd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue(); @@ -125,10 +111,8 @@ public class BeanDefinitionTests { otherBd.setScope("request"); otherBd.setAbstract(true); otherBd.setLazyInit(true); - boolean condition1 = !bd.equals(otherBd); - assertThat(condition1).isTrue(); - boolean condition = !otherBd.equals(bd); - assertThat(condition).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.setParentName("parent"); assertThat(bd.equals(otherBd)).isTrue(); assertThat(otherBd.equals(bd)).isTrue(); @@ -153,10 +137,8 @@ public class BeanDefinitionTests { bd.setScope("request"); BeanDefinitionHolder holder = new BeanDefinitionHolder(bd, "bd"); RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class); - boolean condition1 = !bd.equals(otherBd); - assertThat(condition1).isTrue(); - boolean condition = !otherBd.equals(bd); - assertThat(condition).isTrue(); + assertThat(!bd.equals(otherBd)).isTrue(); + assertThat(!otherBd.equals(bd)).isTrue(); otherBd.setAbstract(true); otherBd.setLazyInit(true); otherBd.setScope("request"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java index a9f943ae28..0efebed42a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java @@ -422,10 +422,8 @@ class BeanFactoryGenericsTests { bf.registerBeanDefinition("genericBean", rbd); GenericBean gb = (GenericBean) bf.getBean("genericBean"); - boolean condition1 = gb.getCollectionMap().get(1) instanceof HashSet; - assertThat(condition1).isTrue(); - boolean condition = gb.getCollectionMap().get(2) instanceof ArrayList; - assertThat(condition).isTrue(); + assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue(); + assertThat(gb.getCollectionMap().get(2) instanceof ArrayList).isTrue(); } @@ -577,10 +575,8 @@ class BeanFactoryGenericsTests { bf.registerBeanDefinition("genericBean", rbd); GenericBean gb = (GenericBean) bf.getBean("genericBean"); - boolean condition1 = gb.getCollectionMap().get(1) instanceof HashSet; - assertThat(condition1).isTrue(); - boolean condition = gb.getCollectionMap().get(2) instanceof ArrayList; - assertThat(condition).isTrue(); + assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue(); + assertThat(gb.getCollectionMap().get(2) instanceof ArrayList).isTrue(); } @Test diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java index fd8498b878..74b599bc51 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java @@ -337,16 +337,14 @@ public class FactoryMethodTests { // Check that listInstance is not considered a bean of type FactoryMethods. assertThat(List.class.isAssignableFrom(xbf.getType("listInstance"))).isTrue(); String[] names = xbf.getBeanNamesForType(FactoryMethods.class); - boolean condition1 = !Arrays.asList(names).contains("listInstance"); - assertThat(condition1).isTrue(); + assertThat(Arrays.asList(names).contains("listInstance")).isFalse(); names = xbf.getBeanNamesForType(List.class); assertThat(Arrays.asList(names).contains("listInstance")).isTrue(); xbf.preInstantiateSingletons(); assertThat(List.class.isAssignableFrom(xbf.getType("listInstance"))).isTrue(); names = xbf.getBeanNamesForType(FactoryMethods.class); - boolean condition = !Arrays.asList(names).contains("listInstance"); - assertThat(condition).isTrue(); + assertThat(Arrays.asList(names).contains("listInstance")).isFalse(); names = xbf.getBeanNamesForType(List.class); assertThat(Arrays.asList(names).contains("listInstance")).isTrue(); List list = (List) xbf.getBean("listInstance"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java index 579245f6cf..9d853af3e6 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java @@ -70,24 +70,21 @@ public class XmlBeanCollectionTests { ListFactoryBean listFactory = new ListFactoryBean(); listFactory.setSourceList(new LinkedList()); listFactory.afterPropertiesSet(); - boolean condition2 = listFactory.getObject() instanceof ArrayList; - assertThat(condition2).isTrue(); + assertThat(listFactory.getObject() instanceof ArrayList).isTrue(); SetFactoryBean setFactory = new SetFactoryBean(); setFactory.setSourceSet(new TreeSet()); setFactory.afterPropertiesSet(); - boolean condition1 = setFactory.getObject() instanceof LinkedHashSet; - assertThat(condition1).isTrue(); + assertThat(setFactory.getObject() instanceof LinkedHashSet).isTrue(); MapFactoryBean mapFactory = new MapFactoryBean(); mapFactory.setSourceMap(new TreeMap()); mapFactory.afterPropertiesSet(); - boolean condition = mapFactory.getObject() instanceof LinkedHashMap; - assertThat(condition).isTrue(); + assertThat(mapFactory.getObject() instanceof LinkedHashMap).isTrue(); } @Test - public void testRefSubelement() throws Exception { + public void testRefSubelement() { //assertTrue("5 beans in reftypes, not " + this.beanFactory.getBeanDefinitionCount(), this.beanFactory.getBeanDefinitionCount() == 5); TestBean jen = (TestBean) this.beanFactory.getBean("jenny"); TestBean dave = (TestBean) this.beanFactory.getBean("david"); @@ -95,25 +92,25 @@ public class XmlBeanCollectionTests { } @Test - public void testPropertyWithLiteralValueSubelement() throws Exception { + public void testPropertyWithLiteralValueSubelement() { TestBean verbose = (TestBean) this.beanFactory.getBean("verbose"); assertThat(verbose.getName()).isEqualTo("verbose"); } @Test - public void testPropertyWithIdRefLocalAttrSubelement() throws Exception { + public void testPropertyWithIdRefLocalAttrSubelement() { TestBean verbose = (TestBean) this.beanFactory.getBean("verbose2"); assertThat(verbose.getName()).isEqualTo("verbose"); } @Test - public void testPropertyWithIdRefBeanAttrSubelement() throws Exception { + public void testPropertyWithIdRefBeanAttrSubelement() { TestBean verbose = (TestBean) this.beanFactory.getBean("verbose3"); assertThat(verbose.getName()).isEqualTo("verbose"); } @Test - public void testRefSubelementsBuildCollection() throws Exception { + public void testRefSubelementsBuildCollection() { TestBean jen = (TestBean) this.beanFactory.getBean("jenny"); TestBean dave = (TestBean) this.beanFactory.getBean("david"); TestBean rod = (TestBean) this.beanFactory.getBean("rod"); @@ -130,7 +127,7 @@ public class XmlBeanCollectionTests { } @Test - public void testRefSubelementsBuildCollectionWithPrototypes() throws Exception { + public void testRefSubelementsBuildCollectionWithPrototypes() { TestBean jen = (TestBean) this.beanFactory.getBean("pJenny"); TestBean dave = (TestBean) this.beanFactory.getBean("pDavid"); TestBean rod = (TestBean) this.beanFactory.getBean("pRod"); @@ -153,7 +150,7 @@ public class XmlBeanCollectionTests { } @Test - public void testRefSubelementsBuildCollectionFromSingleElement() throws Exception { + public void testRefSubelementsBuildCollectionFromSingleElement() { TestBean loner = (TestBean) this.beanFactory.getBean("loner"); TestBean dave = (TestBean) this.beanFactory.getBean("david"); assertThat(loner.getFriends().size()).isEqualTo(1); @@ -161,7 +158,7 @@ public class XmlBeanCollectionTests { } @Test - public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception { + public void testBuildCollectionFromMixtureOfReferencesAndValues() { MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble"); assertThat(jumble.getJumble().size()).as("Expected 5 elements, not " + jumble.getJumble().size()).isEqualTo(5); List l = (List) jumble.getJumble(); @@ -175,7 +172,7 @@ public class XmlBeanCollectionTests { } @Test - public void testInvalidBeanNameReference() throws Exception { + public void testInvalidBeanNameReference() { assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.beanFactory.getBean("jumble2")) .withCauseInstanceOf(BeanDefinitionStoreException.class) @@ -183,13 +180,13 @@ public class XmlBeanCollectionTests { } @Test - public void testEmptyMap() throws Exception { + public void testEmptyMap() { HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyMap"); assertThat(hasMap.getMap().size()).isEqualTo(0); } @Test - public void testMapWithLiteralsOnly() throws Exception { + public void testMapWithLiteralsOnly() { HasMap hasMap = (HasMap) this.beanFactory.getBean("literalMap"); assertThat(hasMap.getMap().size()).isEqualTo(3); assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue(); @@ -198,23 +195,21 @@ public class XmlBeanCollectionTests { } @Test - public void testMapWithLiteralsAndReferences() throws Exception { + public void testMapWithLiteralsAndReferences() { HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap"); assertThat(hasMap.getMap().size()).isEqualTo(5); assertThat(hasMap.getMap().get("foo").equals(10)).isTrue(); TestBean jenny = (TestBean) this.beanFactory.getBean("jenny"); assertThat(hasMap.getMap().get("jenny")).isSameAs(jenny); assertThat(hasMap.getMap().get(5).equals("david")).isTrue(); - boolean condition1 = hasMap.getMap().get("bar") instanceof Long; - assertThat(condition1).isTrue(); + assertThat(hasMap.getMap().get("bar") instanceof Long).isTrue(); assertThat(hasMap.getMap().get("bar").equals(100L)).isTrue(); - boolean condition = hasMap.getMap().get("baz") instanceof Integer; - assertThat(condition).isTrue(); + assertThat(hasMap.getMap().get("baz") instanceof Integer).isTrue(); assertThat(hasMap.getMap().get("baz").equals(200)).isTrue(); } @Test - public void testMapWithLiteralsAndPrototypeReferences() throws Exception { + public void testMapWithLiteralsAndPrototypeReferences() { TestBean jenny = (TestBean) this.beanFactory.getBean("pJenny"); HasMap hasMap = (HasMap) this.beanFactory.getBean("pMixedMap"); assertThat(hasMap.getMap().size()).isEqualTo(2); @@ -230,7 +225,7 @@ public class XmlBeanCollectionTests { } @Test - public void testMapWithLiteralsReferencesAndList() throws Exception { + public void testMapWithLiteralsReferencesAndList() { HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMapWithList"); assertThat(hasMap.getMap().size()).isEqualTo(4); assertThat(hasMap.getMap().get(null).equals("bar")).isTrue(); @@ -267,13 +262,13 @@ public class XmlBeanCollectionTests { } @Test - public void testEmptySet() throws Exception { + public void testEmptySet() { HasMap hasMap = (HasMap) this.beanFactory.getBean("emptySet"); assertThat(hasMap.getSet().size()).isEqualTo(0); } @Test - public void testPopulatedSet() throws Exception { + public void testPopulatedSet() { HasMap hasMap = (HasMap) this.beanFactory.getBean("set"); assertThat(hasMap.getSet().size()).isEqualTo(3); assertThat(hasMap.getSet().contains("bar")).isTrue(); @@ -287,7 +282,7 @@ public class XmlBeanCollectionTests { } @Test - public void testPopulatedConcurrentSet() throws Exception { + public void testPopulatedConcurrentSet() { HasMap hasMap = (HasMap) this.beanFactory.getBean("concurrentSet"); assertThat(hasMap.getConcurrentSet().size()).isEqualTo(3); assertThat(hasMap.getConcurrentSet().contains("bar")).isTrue(); @@ -297,7 +292,7 @@ public class XmlBeanCollectionTests { } @Test - public void testPopulatedIdentityMap() throws Exception { + public void testPopulatedIdentityMap() { HasMap hasMap = (HasMap) this.beanFactory.getBean("identityMap"); assertThat(hasMap.getIdentityMap().size()).isEqualTo(2); HashSet set = new HashSet(hasMap.getIdentityMap().keySet()); @@ -306,14 +301,14 @@ public class XmlBeanCollectionTests { } @Test - public void testEmptyProps() throws Exception { + public void testEmptyProps() { HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyProps"); assertThat(hasMap.getProps().size()).isEqualTo(0); assertThat(Properties.class).isEqualTo(hasMap.getProps().getClass()); } @Test - public void testPopulatedProps() throws Exception { + public void testPopulatedProps() { HasMap hasMap = (HasMap) this.beanFactory.getBean("props"); assertThat(hasMap.getProps().size()).isEqualTo(2); assertThat(hasMap.getProps().get("foo").equals("bar")).isTrue(); @@ -321,7 +316,7 @@ public class XmlBeanCollectionTests { } @Test - public void testObjectArray() throws Exception { + public void testObjectArray() { HasMap hasMap = (HasMap) this.beanFactory.getBean("objectArray"); assertThat(hasMap.getObjectArray().length).isEqualTo(2); assertThat(hasMap.getObjectArray()[0].equals("one")).isTrue(); @@ -329,7 +324,7 @@ public class XmlBeanCollectionTests { } @Test - public void testIntegerArray() throws Exception { + public void testIntegerArray() { HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray"); assertThat(hasMap.getIntegerArray().length).isEqualTo(3); assertThat(hasMap.getIntegerArray()[0]).isEqualTo(0); @@ -338,7 +333,7 @@ public class XmlBeanCollectionTests { } @Test - public void testClassArray() throws Exception { + public void testClassArray() { HasMap hasMap = (HasMap) this.beanFactory.getBean("classArray"); assertThat(hasMap.getClassArray().length).isEqualTo(2); assertThat(hasMap.getClassArray()[0].equals(String.class)).isTrue(); @@ -346,7 +341,7 @@ public class XmlBeanCollectionTests { } @Test - public void testClassList() throws Exception { + public void testClassList() { HasMap hasMap = (HasMap) this.beanFactory.getBean("classList"); assertThat(hasMap.getClassList().size()).isEqualTo(2); assertThat(hasMap.getClassList().get(0).equals(String.class)).isTrue(); @@ -354,7 +349,7 @@ public class XmlBeanCollectionTests { } @Test - public void testProps() throws Exception { + public void testProps() { HasMap hasMap = (HasMap) this.beanFactory.getBean("props"); assertThat(hasMap.getProps()).hasSize(2); assertThat(hasMap.getProps().getProperty("foo")).isEqualTo("bar"); @@ -367,60 +362,54 @@ public class XmlBeanCollectionTests { } @Test - public void testListFactory() throws Exception { + public void testListFactory() { List list = (List) this.beanFactory.getBean("listFactory"); - boolean condition = list instanceof LinkedList; - assertThat(condition).isTrue(); + assertThat(list instanceof LinkedList).isTrue(); assertThat(list.size()).isEqualTo(2); assertThat(list.get(0)).isEqualTo("bar"); assertThat(list.get(1)).isEqualTo("jenny"); } @Test - public void testPrototypeListFactory() throws Exception { + public void testPrototypeListFactory() { List list = (List) this.beanFactory.getBean("pListFactory"); - boolean condition = list instanceof LinkedList; - assertThat(condition).isTrue(); + assertThat(list instanceof LinkedList).isTrue(); assertThat(list.size()).isEqualTo(2); assertThat(list.get(0)).isEqualTo("bar"); assertThat(list.get(1)).isEqualTo("jenny"); } @Test - public void testSetFactory() throws Exception { + public void testSetFactory() { Set set = (Set) this.beanFactory.getBean("setFactory"); - boolean condition = set instanceof TreeSet; - assertThat(condition).isTrue(); + assertThat(set instanceof TreeSet).isTrue(); assertThat(set.size()).isEqualTo(2); assertThat(set.contains("bar")).isTrue(); assertThat(set.contains("jenny")).isTrue(); } @Test - public void testPrototypeSetFactory() throws Exception { + public void testPrototypeSetFactory() { Set set = (Set) this.beanFactory.getBean("pSetFactory"); - boolean condition = set instanceof TreeSet; - assertThat(condition).isTrue(); + assertThat(set instanceof TreeSet).isTrue(); assertThat(set.size()).isEqualTo(2); assertThat(set.contains("bar")).isTrue(); assertThat(set.contains("jenny")).isTrue(); } @Test - public void testMapFactory() throws Exception { + public void testMapFactory() { Map map = (Map) this.beanFactory.getBean("mapFactory"); - boolean condition = map instanceof TreeMap; - assertThat(condition).isTrue(); + assertThat(map instanceof TreeMap).isTrue(); assertThat(map.size()).isEqualTo(2); assertThat(map.get("foo")).isEqualTo("bar"); assertThat(map.get("jen")).isEqualTo("jenny"); } @Test - public void testPrototypeMapFactory() throws Exception { + public void testPrototypeMapFactory() { Map map = (Map) this.beanFactory.getBean("pMapFactory"); - boolean condition = map instanceof TreeMap; - assertThat(condition).isTrue(); + assertThat(map instanceof TreeMap).isTrue(); assertThat(map.size()).isEqualTo(2); assertThat(map.get("foo")).isEqualTo("bar"); assertThat(map.get("jen")).isEqualTo("jenny"); @@ -429,8 +418,7 @@ public class XmlBeanCollectionTests { @Test public void testChoiceBetweenSetAndMap() { MapAndSet sam = (MapAndSet) this.beanFactory.getBean("setAndMap"); - boolean condition = sam.getObject() instanceof Map; - assertThat(condition).as("Didn't choose constructor with Map argument").isTrue(); + assertThat(sam.getObject() instanceof Map).as("Didn't choose constructor with Map argument").isTrue(); Map map = (Map) sam.getObject(); assertThat(map).hasSize(3); assertThat(map.get("key1")).isEqualTo("val1"); @@ -439,7 +427,7 @@ public class XmlBeanCollectionTests { } @Test - public void testEnumSetFactory() throws Exception { + public void testEnumSetFactory() { Set set = (Set) this.beanFactory.getBean("enumSetFactory"); assertThat(set.size()).isEqualTo(2); assertThat(set.contains("ONE")).isTrue(); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java index 267f2a42e6..d5597923f7 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java @@ -34,33 +34,32 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException public class CustomCollectionEditorTests { @Test - public void testCtorWithNullCollectionType() throws Exception { + public void testCtorWithNullCollectionType() { assertThatIllegalArgumentException().isThrownBy(() -> new CustomCollectionEditor(null)); } @Test @SuppressWarnings({ "unchecked", "rawtypes" }) - public void testCtorWithNonCollectionType() throws Exception { + public void testCtorWithNonCollectionType() { assertThatIllegalArgumentException().isThrownBy(() -> new CustomCollectionEditor((Class) String.class)); } @Test - public void testWithCollectionTypeThatDoesNotExposeAPublicNoArgCtor() throws Exception { + public void testWithCollectionTypeThatDoesNotExposeAPublicNoArgCtor() { CustomCollectionEditor editor = new CustomCollectionEditor(CollectionTypeWithNoNoArgCtor.class); assertThatIllegalArgumentException().isThrownBy(() -> editor.setValue("1")); } @Test - public void testSunnyDaySetValue() throws Exception { + public void testSunnyDaySetValue() { CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class); editor.setValue(new int[] {0, 1, 2}); Object value = editor.getValue(); assertThat(value).isNotNull(); - boolean condition = value instanceof ArrayList; - assertThat(condition).isTrue(); + assertThat(value instanceof ArrayList).isTrue(); List list = (List) value; assertThat(list).as("There must be 3 elements in the converted collection").hasSize(3); assertThat(list.get(0)).isEqualTo(0); @@ -69,7 +68,7 @@ public class CustomCollectionEditorTests { } @Test - public void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() throws Exception { + public void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() { CustomCollectionEditor editor = new CustomCollectionEditor(Collection.class); editor.setValue("0, 1, 2"); Collection value = (Collection) editor.getValue(); @@ -79,13 +78,12 @@ public class CustomCollectionEditorTests { } @Test - public void testSunnyDaySetAsTextYieldsSingleValue() throws Exception { + public void testSunnyDaySetAsTextYieldsSingleValue() { CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class); editor.setValue("0, 1, 2"); Object value = editor.getValue(); assertThat(value).isNotNull(); - boolean condition = value instanceof ArrayList; - assertThat(condition).isTrue(); + assertThat(value instanceof ArrayList).isTrue(); List list = (List) value; assertThat(list).as("There must be 1 element in the converted collection").hasSize(1); assertThat(list.get(0)).isEqualTo("0, 1, 2"); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java index 4f377d5683..b744cd94aa 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java @@ -193,36 +193,31 @@ class CustomEditorTests { bw.setPropertyValue("bool1", "false"); assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool1"))).as("Correct bool1 value").isTrue(); - boolean condition4 = !tb.isBool1(); - assertThat(condition4).as("Correct bool1 value").isTrue(); + assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", " true "); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", " false "); - boolean condition3 = !tb.isBool1(); - assertThat(condition3).as("Correct bool1 value").isTrue(); + assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", "on"); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", "off"); - boolean condition2 = !tb.isBool1(); - assertThat(condition2).as("Correct bool1 value").isTrue(); + assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", "yes"); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", "no"); - boolean condition1 = !tb.isBool1(); - assertThat(condition1).as("Correct bool1 value").isTrue(); + assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", "1"); assertThat(tb.isBool1()).as("Correct bool1 value").isTrue(); bw.setPropertyValue("bool1", "0"); - boolean condition = !tb.isBool1(); - assertThat(condition).as("Correct bool1 value").isTrue(); + assertThat(!tb.isBool1()).as("Correct bool1 value").isTrue(); assertThatExceptionOfType(BeansException.class).isThrownBy(() -> bw.setPropertyValue("bool1", "argh")); @@ -239,29 +234,25 @@ class CustomEditorTests { bw.setPropertyValue("bool2", "false"); assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue(); - boolean condition3 = !tb.getBool2(); - assertThat(condition3).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "on"); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "off"); - boolean condition2 = !tb.getBool2(); - assertThat(condition2).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "yes"); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "no"); - boolean condition1 = !tb.getBool2(); - assertThat(condition1).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "1"); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "0"); - boolean condition = !tb.getBool2(); - assertThat(condition).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", ""); assertThat(tb.getBool2()).as("Correct bool2 value").isNull(); @@ -279,29 +270,25 @@ class CustomEditorTests { bw.setPropertyValue("bool2", "false"); assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue(); - boolean condition3 = !tb.getBool2(); - assertThat(condition3).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "on"); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "off"); - boolean condition2 = !tb.getBool2(); - assertThat(condition2).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "yes"); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "no"); - boolean condition1 = !tb.getBool2(); - assertThat(condition1).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "1"); assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", "0"); - boolean condition = !tb.getBool2(); - assertThat(condition).as("Correct bool2 value").isTrue(); + assertThat(!tb.getBool2()).as("Correct bool2 value").isTrue(); bw.setPropertyValue("bool2", ""); assertThat(bw.getPropertyValue("bool2")).as("Correct bool2 value").isNull(); @@ -309,7 +296,7 @@ class CustomEditorTests { } @Test - void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Exception { + void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() { String trueString = "pechorin"; String falseString = "nash"; @@ -458,7 +445,7 @@ class CustomEditorTests { } @Test - void testCustomNumberEditorWithFrenchBigDecimal() throws Exception { + void testCustomNumberEditorWithFrenchBigDecimal() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH); NumberTestBean tb = new NumberTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); @@ -542,14 +529,14 @@ class CustomEditorTests { } @Test - void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() throws Exception { + void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() { PropertyEditor charEditor = new CharacterEditor(false); assertThatIllegalArgumentException().isThrownBy(() -> charEditor.setAsText("ColdWaterCanyon")); } @Test - void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception { + void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() { PropertyEditor charEditor = new CharacterEditor(false); assertThat(charEditor.getAsText()).isEmpty(); charEditor = new CharacterEditor(true); @@ -562,7 +549,7 @@ class CustomEditorTests { } @Test - void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() throws Exception { + void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() { PropertyEditor charEditor = new CharacterEditor(false); assertThatIllegalArgumentException().isThrownBy(() -> charEditor.setAsText(null)); @@ -584,7 +571,7 @@ class CustomEditorTests { } @Test - void testClassEditorWithNonExistentClass() throws Exception { + void testClassEditorWithNonExistentClass() { PropertyEditor classEditor = new ClassEditor(); assertThatIllegalArgumentException().isThrownBy(() -> classEditor.setAsText("hairdresser.on.Fire")); @@ -602,7 +589,7 @@ class CustomEditorTests { * SPR_2165 - ClassEditor is inconsistent with multidimensional arrays */ @Test - void testGetAsTextWithTwoDimensionalArray() throws Exception { + void testGetAsTextWithTwoDimensionalArray() { String[][] chessboard = new String[8][8]; ClassEditor editor = new ClassEditor(); editor.setValue(chessboard.getClass()); @@ -613,7 +600,7 @@ class CustomEditorTests { * SPR_2165 - ClassEditor is inconsistent with multidimensional arrays */ @Test - void testGetAsTextWithRidiculousMultiDimensionalArray() throws Exception { + void testGetAsTextWithRidiculousMultiDimensionalArray() { String[][][][][] ridiculousChessboard = new String[8][4][0][1][3]; ClassEditor editor = new ClassEditor(); editor.setValue(ridiculousChessboard.getClass()); @@ -1413,7 +1400,7 @@ class CustomEditorTests { } @Test - void testClassArrayEditorSunnyDay() throws Exception { + void testClassArrayEditorSunnyDay() { ClassArrayEditor classArrayEditor = new ClassArrayEditor(); classArrayEditor.setAsText("java.lang.String,java.util.HashMap"); Class[] classes = (Class[]) classArrayEditor.getValue(); @@ -1426,7 +1413,7 @@ class CustomEditorTests { } @Test - void testClassArrayEditorSunnyDayWithArrayTypes() throws Exception { + void testClassArrayEditorSunnyDayWithArrayTypes() { ClassArrayEditor classArrayEditor = new ClassArrayEditor(); classArrayEditor.setAsText("java.lang.String[],java.util.Map[],int[],float[][][]"); Class[] classes = (Class[]) classArrayEditor.getValue(); @@ -1441,7 +1428,7 @@ class CustomEditorTests { } @Test - void testClassArrayEditorSetAsTextWithNull() throws Exception { + void testClassArrayEditorSetAsTextWithNull() { ClassArrayEditor editor = new ClassArrayEditor(); editor.setAsText(null); assertThat(editor.getValue()).isNull(); @@ -1449,7 +1436,7 @@ class CustomEditorTests { } @Test - void testClassArrayEditorSetAsTextWithEmptyString() throws Exception { + void testClassArrayEditorSetAsTextWithEmptyString() { ClassArrayEditor editor = new ClassArrayEditor(); editor.setAsText(""); assertThat(editor.getValue()).isNull(); @@ -1457,7 +1444,7 @@ class CustomEditorTests { } @Test - void testClassArrayEditorSetAsTextWithWhitespaceString() throws Exception { + void testClassArrayEditorSetAsTextWithWhitespaceString() { ClassArrayEditor editor = new ClassArrayEditor(); editor.setAsText("\n"); assertThat(editor.getValue()).isNull(); @@ -1465,7 +1452,7 @@ class CustomEditorTests { } @Test - void testCharsetEditor() throws Exception { + void testCharsetEditor() { CharsetEditor editor = new CharsetEditor(); String name = "UTF-8"; editor.setAsText(name); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java index 83d13cdf1e..3076977e9e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java @@ -34,57 +34,51 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException public class FileEditorTests { @Test - public void testClasspathFileName() throws Exception { + public void testClasspathFileName() { PropertyEditor fileEditor = new FileEditor(); fileEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); Object value = fileEditor.getValue(); - boolean condition = value instanceof File; - assertThat(condition).isTrue(); + assertThat(value instanceof File).isTrue(); File file = (File) value; assertThat(file).exists(); } @Test - public void testWithNonExistentResource() throws Exception { + public void testWithNonExistentResource() { PropertyEditor propertyEditor = new FileEditor(); assertThatIllegalArgumentException().isThrownBy(() -> propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc")); } @Test - public void testWithNonExistentFile() throws Exception { + public void testWithNonExistentFile() { PropertyEditor fileEditor = new FileEditor(); fileEditor.setAsText("file:no_way_this_file_is_found.doc"); Object value = fileEditor.getValue(); - boolean condition1 = value instanceof File; - assertThat(condition1).isTrue(); + assertThat(value instanceof File).isTrue(); File file = (File) value; - boolean condition = !file.exists(); - assertThat(condition).isTrue(); + assertThat(file).doesNotExist(); } @Test - public void testAbsoluteFileName() throws Exception { + public void testAbsoluteFileName() { PropertyEditor fileEditor = new FileEditor(); fileEditor.setAsText("/no_way_this_file_is_found.doc"); Object value = fileEditor.getValue(); - boolean condition1 = value instanceof File; - assertThat(condition1).isTrue(); + assertThat(value instanceof File).isTrue(); File file = (File) value; - boolean condition = !file.exists(); - assertThat(condition).isTrue(); + assertThat(file).doesNotExist(); } @Test - public void testUnqualifiedFileNameFound() throws Exception { + public void testUnqualifiedFileNameFound() { PropertyEditor fileEditor = new FileEditor(); String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"; fileEditor.setAsText(fileName); Object value = fileEditor.getValue(); - boolean condition = value instanceof File; - assertThat(condition).isTrue(); + assertThat(value instanceof File).isTrue(); File file = (File) value; assertThat(file).exists(); String absolutePath = file.getAbsolutePath().replace('\\', '/'); @@ -92,14 +86,13 @@ public class FileEditorTests { } @Test - public void testUnqualifiedFileNameNotFound() throws Exception { + public void testUnqualifiedFileNameNotFound() { PropertyEditor fileEditor = new FileEditor(); String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".clazz"; fileEditor.setAsText(fileName); Object value = fileEditor.getValue(); - boolean condition = value instanceof File; - assertThat(condition).isTrue(); + assertThat(value instanceof File).isTrue(); File file = (File) value; assertThat(file).doesNotExist(); String absolutePath = file.getAbsolutePath().replace('\\', '/'); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java index 5720c353bc..d0a3e676ec 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java @@ -16,6 +16,7 @@ package org.springframework.beans.propertyeditors; +import java.io.IOException; import java.io.InputStream; import org.junit.jupiter.api.Test; @@ -34,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException public class InputStreamEditorTests { @Test - public void testCtorWithNullResourceEditor() throws Exception { + public void testCtorWithNullResourceEditor() { assertThatIllegalArgumentException().isThrownBy(() -> new InputStreamEditor(null)); } @Test - public void testSunnyDay() throws Exception { + public void testSunnyDay() throws IOException { InputStream stream = null; try { String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + @@ -49,8 +50,7 @@ public class InputStreamEditorTests { editor.setAsText(resource); Object value = editor.getValue(); assertThat(value).isNotNull(); - boolean condition = value instanceof InputStream; - assertThat(condition).isTrue(); + assertThat(value instanceof InputStream).isTrue(); stream = (InputStream) value; assertThat(stream.available()).isGreaterThan(0); } @@ -62,14 +62,14 @@ public class InputStreamEditorTests { } @Test - public void testWhenResourceDoesNotExist() throws Exception { + public void testWhenResourceDoesNotExist() { InputStreamEditor editor = new InputStreamEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("classpath:bingo!")); } @Test - public void testGetAsTextReturnsNullByDefault() throws Exception { + public void testGetAsTextReturnsNullByDefault() { assertThat(new InputStreamEditor().getAsText()).isNull(); String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"; diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java index a2631bf435..b3ec8b4be2 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java @@ -151,7 +151,7 @@ public class PropertiesEditorTests { } @Test - public void usingMapAsValueSource() throws Exception { + public void usingMapAsValueSource() { Map map = new HashMap<>(); map.put("one", "1"); map.put("two", "2"); @@ -160,8 +160,7 @@ public class PropertiesEditorTests { pe.setValue(map); Object value = pe.getValue(); assertThat(value).isNotNull(); - boolean condition = value instanceof Properties; - assertThat(condition).isTrue(); + assertThat(value instanceof Properties).isTrue(); Properties props = (Properties) value; assertThat(props).hasSize(3); assertThat(props.getProperty("one")).isEqualTo("1"); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java index 5573452620..79e48a5db0 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.beans.propertyeditors; +import java.io.IOException; import java.io.Reader; import org.junit.jupiter.api.Test; @@ -34,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException public class ReaderEditorTests { @Test - public void testCtorWithNullResourceEditor() throws Exception { + public void testCtorWithNullResourceEditor() { assertThatIllegalArgumentException().isThrownBy(() -> new ReaderEditor(null)); } @Test - public void testSunnyDay() throws Exception { + public void testSunnyDay() throws IOException { Reader reader = null; try { String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + @@ -49,8 +50,7 @@ public class ReaderEditorTests { editor.setAsText(resource); Object value = editor.getValue(); assertThat(value).isNotNull(); - boolean condition = value instanceof Reader; - assertThat(condition).isTrue(); + assertThat(value instanceof Reader).isTrue(); reader = (Reader) value; assertThat(reader.ready()).isTrue(); } @@ -62,7 +62,7 @@ public class ReaderEditorTests { } @Test - public void testWhenResourceDoesNotExist() throws Exception { + public void testWhenResourceDoesNotExist() { String resource = "classpath:bingo!"; ReaderEditor editor = new ReaderEditor(); assertThatIllegalArgumentException().isThrownBy(() -> @@ -70,7 +70,7 @@ public class ReaderEditorTests { } @Test - public void testGetAsTextReturnsNullByDefault() throws Exception { + public void testGetAsTextReturnsNullByDefault() { assertThat(new ReaderEditor().getAsText()).isNull(); String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"; diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java index 3785304164..4cbdef1ddc 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -37,93 +37,88 @@ public class ResourceBundleEditorTests { @Test - public void testSetAsTextWithJustBaseName() throws Exception { + public void testSetAsTextWithJustBaseName() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME); Object value = editor.getValue(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); - boolean condition = value instanceof ResourceBundle; - assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); + assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); ResourceBundle bundle = (ResourceBundle) value; String string = bundle.getString(MESSAGE_KEY); assertThat(string).isEqualTo(MESSAGE_KEY); } @Test - public void testSetAsTextWithBaseNameThatEndsInDefaultSeparator() throws Exception { + public void testSetAsTextWithBaseNameThatEndsInDefaultSeparator() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "_"); Object value = editor.getValue(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); - boolean condition = value instanceof ResourceBundle; - assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); + assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); ResourceBundle bundle = (ResourceBundle) value; String string = bundle.getString(MESSAGE_KEY); assertThat(string).isEqualTo(MESSAGE_KEY); } @Test - public void testSetAsTextWithBaseNameAndLanguageCode() throws Exception { + public void testSetAsTextWithBaseNameAndLanguageCode() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "Lang" + "_en"); Object value = editor.getValue(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); - boolean condition = value instanceof ResourceBundle; - assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); + assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); ResourceBundle bundle = (ResourceBundle) value; String string = bundle.getString(MESSAGE_KEY); assertThat(string).isEqualTo("yob"); } @Test - public void testSetAsTextWithBaseNameLanguageAndCountryCode() throws Exception { + public void testSetAsTextWithBaseNameLanguageAndCountryCode() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "LangCountry" + "_en_GB"); Object value = editor.getValue(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); - boolean condition = value instanceof ResourceBundle; - assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); + assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); ResourceBundle bundle = (ResourceBundle) value; String string = bundle.getString(MESSAGE_KEY); assertThat(string).isEqualTo("chav"); } @Test - public void testSetAsTextWithTheKitchenSink() throws Exception { + public void testSetAsTextWithTheKitchenSink() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "LangCountryDialect" + "_en_GB_GLASGOW"); Object value = editor.getValue(); assertThat(value).as("Returned ResourceBundle was null (must not be for valid setAsText(..) call).").isNotNull(); - boolean condition = value instanceof ResourceBundle; - assertThat(condition).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); + assertThat(value instanceof ResourceBundle).as("Returned object was not a ResourceBundle (must be for valid setAsText(..) call).").isTrue(); ResourceBundle bundle = (ResourceBundle) value; String string = bundle.getString(MESSAGE_KEY); assertThat(string).isEqualTo("ned"); } @Test - public void testSetAsTextWithNull() throws Exception { + public void testSetAsTextWithNull() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText(null)); } @Test - public void testSetAsTextWithEmptyString() throws Exception { + public void testSetAsTextWithEmptyString() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("")); } @Test - public void testSetAsTextWithWhiteSpaceString() throws Exception { + public void testSetAsTextWithWhiteSpaceString() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText(" ")); } @Test - public void testSetAsTextWithJustSeparatorString() throws Exception { + public void testSetAsTextWithJustSeparatorString() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("_")); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java index 9275dde1d2..4d215e0156 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java @@ -32,78 +32,72 @@ import static org.assertj.core.api.Assertions.assertThat; public class URIEditorTests { @Test - public void standardURI() throws Exception { + public void standardURI() { doTestURI("mailto:juergen.hoeller@interface21.com"); } @Test - public void withNonExistentResource() throws Exception { + public void withNonExistentResource() { doTestURI("gonna:/freak/in/the/morning/freak/in/the.evening"); } @Test - public void standardURL() throws Exception { + public void standardURL() { doTestURI("https://www.springframework.org"); } @Test - public void standardURLWithFragment() throws Exception { + public void standardURLWithFragment() { doTestURI("https://www.springframework.org#1"); } @Test - public void standardURLWithWhitespace() throws Exception { + public void standardURLWithWhitespace() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText(" https://www.springframework.org "); Object value = uriEditor.getValue(); - boolean condition = value instanceof URI; - assertThat(condition).isTrue(); + assertThat(value instanceof URI).isTrue(); URI uri = (URI) value; assertThat(uri.toString()).isEqualTo("https://www.springframework.org"); } @Test - public void classpathURL() throws Exception { + public void classpathURL() { PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader()); uriEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); Object value = uriEditor.getValue(); - boolean condition1 = value instanceof URI; - assertThat(condition1).isTrue(); + assertThat(value instanceof URI).isTrue(); URI uri = (URI) value; assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); - boolean condition = !uri.getScheme().startsWith("classpath"); - assertThat(condition).isTrue(); + assertThat(uri.getScheme()).doesNotStartWith("classpath"); } @Test - public void classpathURLWithWhitespace() throws Exception { + public void classpathURLWithWhitespace() { PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader()); uriEditor.setAsText(" classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class "); Object value = uriEditor.getValue(); - boolean condition1 = value instanceof URI; - assertThat(condition1).isTrue(); + assertThat(value instanceof URI).isTrue(); URI uri = (URI) value; assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); - boolean condition = !uri.getScheme().startsWith("classpath"); - assertThat(condition).isTrue(); + assertThat(uri.getScheme()).doesNotStartWith("classpath"); } @Test - public void classpathURLAsIs() throws Exception { + public void classpathURLAsIs() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText("classpath:test.txt"); Object value = uriEditor.getValue(); - boolean condition = value instanceof URI; - assertThat(condition).isTrue(); + assertThat(value instanceof URI).isTrue(); URI uri = (URI) value; assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uri.getScheme()).startsWith("classpath"); } @Test - public void setAsTextWithNull() throws Exception { + public void setAsTextWithNull() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText(null); assertThat(uriEditor.getValue()).isNull(); @@ -111,30 +105,28 @@ public class URIEditorTests { } @Test - public void getAsTextReturnsEmptyStringIfValueNotSet() throws Exception { + public void getAsTextReturnsEmptyStringIfValueNotSet() { PropertyEditor uriEditor = new URIEditor(); assertThat(uriEditor.getAsText()).isEmpty(); } @Test - public void encodeURI() throws Exception { + public void encodeURI() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText("https://example.com/spaces and \u20AC"); Object value = uriEditor.getValue(); - boolean condition = value instanceof URI; - assertThat(condition).isTrue(); + assertThat(value instanceof URI).isTrue(); URI uri = (URI) value; assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uri.toASCIIString()).isEqualTo("https://example.com/spaces%20and%20%E2%82%AC"); } @Test - public void encodeAlreadyEncodedURI() throws Exception { + public void encodeAlreadyEncodedURI() { PropertyEditor uriEditor = new URIEditor(false); uriEditor.setAsText("https://example.com/spaces%20and%20%E2%82%AC"); Object value = uriEditor.getValue(); - boolean condition = value instanceof URI; - assertThat(condition).isTrue(); + assertThat(value instanceof URI).isTrue(); URI uri = (URI) value; assertThat(uriEditor.getAsText()).isEqualTo(uri.toString()); assertThat(uri.toASCIIString()).isEqualTo("https://example.com/spaces%20and%20%E2%82%AC"); @@ -145,8 +137,7 @@ public class URIEditorTests { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText(uriSpec); Object value = uriEditor.getValue(); - boolean condition = value instanceof URI; - assertThat(condition).isTrue(); + assertThat(value instanceof URI).isTrue(); URI uri = (URI) value; assertThat(uri.toString()).isEqualTo(uriSpec); } diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java index b65364b662..ba96e1b9ee 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java @@ -33,56 +33,52 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException public class URLEditorTests { @Test - public void testCtorWithNullResourceEditor() throws Exception { + public void testCtorWithNullResourceEditor() { assertThatIllegalArgumentException().isThrownBy(() -> new URLEditor(null)); } @Test - public void testStandardURI() throws Exception { + public void testStandardURI() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("mailto:juergen.hoeller@interface21.com"); Object value = urlEditor.getValue(); - boolean condition = value instanceof URL; - assertThat(condition).isTrue(); + assertThat(value instanceof URL).isTrue(); URL url = (URL) value; assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm()); } @Test - public void testStandardURL() throws Exception { + public void testStandardURL() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("https://www.springframework.org"); Object value = urlEditor.getValue(); - boolean condition = value instanceof URL; - assertThat(condition).isTrue(); + assertThat(value instanceof URL).isTrue(); URL url = (URL) value; assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm()); } @Test - public void testClasspathURL() throws Exception { + public void testClasspathURL() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); Object value = urlEditor.getValue(); - boolean condition1 = value instanceof URL; - assertThat(condition1).isTrue(); + assertThat(value instanceof URL).isTrue(); URL url = (URL) value; assertThat(urlEditor.getAsText()).isEqualTo(url.toExternalForm()); - boolean condition = !url.getProtocol().startsWith("classpath"); - assertThat(condition).isTrue(); + assertThat(url.getProtocol()).doesNotStartWith("classpath"); } @Test - public void testWithNonExistentResource() throws Exception { + public void testWithNonExistentResource() { PropertyEditor urlEditor = new URLEditor(); assertThatIllegalArgumentException().isThrownBy(() -> urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening")); } @Test - public void testSetAsTextWithNull() throws Exception { + public void testSetAsTextWithNull() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText(null); assertThat(urlEditor.getValue()).isNull(); @@ -90,7 +86,7 @@ public class URLEditorTests { } @Test - public void testGetAsTextReturnsEmptyStringIfValueNotSet() throws Exception { + public void testGetAsTextReturnsEmptyStringIfValueNotSet() { PropertyEditor urlEditor = new URLEditor(); assertThat(urlEditor.getAsText()).isEmpty(); }