Skip to content

Commit afcd03b

Browse files
quaffbclozel
authored andcommitted
Replace assertThat(x.isEmpty()).isTrue() with assertThat(x).isEmpty()
Search for : assertThat\((.+).isEmpty\(\)\).isTrue\(\) Replace with : assertThat($1).isEmpty() Search for : assertThat\((.+).isEmpty\(\)\).isFalse\(\) Replace with : assertThat($1).isNotEmpty() Closes spring-projectsgh-31758
1 parent 7b16ef9 commit afcd03b

55 files changed

Lines changed: 135 additions & 134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void testNoBeansOfType() {
134134
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
135135
lbf.addBean("foo", new Object());
136136
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
137-
assertThat(beans.isEmpty()).isTrue();
137+
assertThat(beans).isEmpty();
138138
}
139139

140140
@Test

spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ void singleConstructorInjectionWithEmptyVararg() {
11431143
SingleConstructorVarargBean bean = bf.getBean("annotatedBean", SingleConstructorVarargBean.class);
11441144
assertThat(bean.getTestBean()).isSameAs(tb);
11451145
assertThat(bean.getNestedTestBeans()).isNotNull();
1146-
assertThat(bean.getNestedTestBeans().isEmpty()).isTrue();
1146+
assertThat(bean.getNestedTestBeans()).isEmpty();
11471147
}
11481148

11491149
@Test
@@ -1172,7 +1172,7 @@ void singleConstructorInjectionWithEmptyCollection() {
11721172
SingleConstructorRequiredCollectionBean bean = bf.getBean("annotatedBean", SingleConstructorRequiredCollectionBean.class);
11731173
assertThat(bean.getTestBean()).isSameAs(tb);
11741174
assertThat(bean.getNestedTestBeans()).isNotNull();
1175-
assertThat(bean.getNestedTestBeans().isEmpty()).isTrue();
1175+
assertThat(bean.getNestedTestBeans()).isEmpty();
11761176
}
11771177

11781178
@Test
@@ -1666,13 +1666,13 @@ void objectProviderInjectionWithTargetNotAvailable() {
16661666
assertThat(bean.consumeUniqueTestBean()).isNull();
16671667

16681668
List<?> testBeans = bean.iterateTestBeans();
1669-
assertThat(testBeans.isEmpty()).isTrue();
1669+
assertThat(testBeans).isEmpty();
16701670
testBeans = bean.forEachTestBeans();
1671-
assertThat(testBeans.isEmpty()).isTrue();
1671+
assertThat(testBeans).isEmpty();
16721672
testBeans = bean.streamTestBeans();
1673-
assertThat(testBeans.isEmpty()).isTrue();
1673+
assertThat(testBeans).isEmpty();
16741674
testBeans = bean.sortedTestBeans();
1675-
assertThat(testBeans.isEmpty()).isTrue();
1675+
assertThat(testBeans).isEmpty();
16761676
}
16771677

16781678
@Test

spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public void testPropertyPathFactoryBeanAsInnerBean() {
8989
TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
9090
TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
9191
assertThat(tbWithInner.getSpouse()).isSameAs(spouse);
92-
assertThat(tbWithInner.getFriends().isEmpty()).isFalse();
93-
assertThat(tbWithInner.getFriends()).element(0).isSameAs(spouse);
92+
assertThat(tbWithInner.getFriends()).isNotEmpty();
93+
assertThat(tbWithInner.getFriends().iterator().next()).isSameAs(spouse);
9494
}
9595

9696
@Test

spring-context/src/test/java/org/springframework/beans/factory/xml/QualifierAnnotationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -110,7 +110,8 @@ public void testQualifiedByBeanName() {
110110
QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
111111
Person person = testBean.getLarry();
112112
assertThat(person.getName()).isEqualTo("LarryBean");
113-
assertThat(testBean.myProps != null && testBean.myProps.isEmpty()).isTrue();
113+
assertThat(testBean.myProps).isNotNull();
114+
assertThat(testBean.myProps).isEmpty();
114115
}
115116

116117
@Test

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ void testEmptyCollectionArgumentOnBeanMethod() {
10591059
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
10601060
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
10611061
assertThat(bean.testBeans).isNotNull();
1062-
assertThat(bean.testBeans.isEmpty()).isTrue();
1062+
assertThat(bean.testBeans).isEmpty();
10631063
ctx.close();
10641064
}
10651065

@@ -1078,7 +1078,7 @@ void testEmptyMapArgumentOnBeanMethod() {
10781078
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
10791079
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
10801080
assertThat(bean.testBeans).isNotNull();
1081-
assertThat(bean.testBeans.isEmpty()).isTrue();
1081+
assertThat(bean.testBeans).isEmpty();
10821082
ctx.close();
10831083
}
10841084

spring-context/src/test/java/org/springframework/context/annotation/LazyAutowiredAnnotationBeanPostProcessorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -81,7 +81,7 @@ void lazyResourceInjectionWithField() {
8181

8282
FieldResourceInjectionBean bean = ac.getBean("annotatedBean", FieldResourceInjectionBean.class);
8383
assertThat(ac.getBeanFactory().containsSingleton("testBean")).isFalse();
84-
assertThat(bean.getTestBeans().isEmpty()).isFalse();
84+
assertThat(bean.getTestBeans()).isNotEmpty();
8585
assertThat(bean.getTestBeans().get(0).getName()).isNull();
8686
assertThat(ac.getBeanFactory().containsSingleton("testBean")).isTrue();
8787
TestBean tb = (TestBean) ac.getBean("testBean");
@@ -156,7 +156,7 @@ void lazyOptionalResourceInjectionWithNonExistingTarget() {
156156
OptionalFieldResourceInjectionBean bean = (OptionalFieldResourceInjectionBean) bf.getBean("annotatedBean");
157157
assertThat(bean.getTestBean()).isNotNull();
158158
assertThat(bean.getTestBeans()).isNotNull();
159-
assertThat(bean.getTestBeans().isEmpty()).isTrue();
159+
assertThat(bean.getTestBeans()).isEmpty();
160160
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
161161
bean.getTestBean().getName());
162162
}

spring-context/src/test/java/org/springframework/context/annotation/configuration/AutowiredConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void testAutowiredConfigurationMethodDependenciesWithOptionalAndNotAvailable() {
9191
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
9292
OptionalAutowiredMethodConfig.class);
9393

94-
assertThat(context.getBeansOfType(Colour.class).isEmpty()).isTrue();
94+
assertThat(context.getBeansOfType(Colour.class)).isEmpty();
9595
assertThat(context.getBean(TestBean.class).getName()).isEmpty();
9696
context.close();
9797
}

spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ void orderedListeners() {
644644
load(OrderedTestListener.class);
645645
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
646646

647-
assertThat(listener.order.isEmpty()).isTrue();
647+
assertThat(listener.order).isEmpty();
648648
this.context.publishEvent("whatever");
649649
assertThat(listener.order).contains("first", "second", "third");
650650
}

spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ static class Baz {
141141
static class ComplexConstructorArgument {
142142

143143
ComplexConstructorArgument(Map<String, Class<?>> map) {
144-
assertThat(map.isEmpty()).isFalse();
145-
assertThat(map.keySet()).element(0).isInstanceOf(String.class);
146-
assertThat(map.values()).element(0).isInstanceOf(Class.class);
144+
assertThat(map).isNotEmpty();
145+
assertThat(map.keySet().iterator().next()).isInstanceOf(String.class);
146+
assertThat(map.values().iterator().next()).isInstanceOf(Class.class);
147147
}
148148
}
149149

spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ void propertyPlaceholderWithInactiveCron() {
542542
context.refresh();
543543

544544
ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class);
545-
assertThat(postProcessor.getScheduledTasks().isEmpty()).isTrue();
545+
assertThat(postProcessor.getScheduledTasks()).isEmpty();
546546
}
547547

548548
@ParameterizedTest

0 commit comments

Comments
 (0)