Skip to content

Commit 7b16ef9

Browse files
quaffbclozel
authored andcommitted
Replace assertThat(x.equals(y)) with assertThat(x).isEqualTo(y)
Search for : assertThat\((.+)\.equals\((\w+)\)\)\.isTrue\(\) Replace with : assertThat($1).isEqualTo($2) Search for : assertThat\((.+)\.equals\((\w+)\)\)\.isFalse\(\) Replace with : assertThat($1).isNotEqualTo($2) Closes gh-31763
1 parent e2852e7 commit 7b16ef9

File tree

30 files changed

+151
-151
lines changed

30 files changed

+151
-151
lines changed

spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void testEqualsAndHashCode() throws Exception {
141141

142142
pc1.intersection(GETTER_METHOD_MATCHER);
143143

144-
assertThat(pc1.equals(pc2)).isFalse();
144+
assertThat(pc1).isNotEqualTo(pc2);
145145
assertThat(pc1.hashCode()).isNotEqualTo(pc2.hashCode());
146146

147147
pc2.intersection(GETTER_METHOD_MATCHER);

spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public void testStaticMethodMatcherUnion() throws Exception {
110110
public void testUnionEquals() {
111111
MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE);
112112
MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher();
113-
assertThat(first.equals(second)).isTrue();
114-
assertThat(second.equals(first)).isTrue();
113+
assertThat(first).isEqualTo(second);
114+
assertThat(second).isEqualTo(first);
115115
}
116116

117117
@Test

spring-aspects/src/test/java/org/springframework/cache/aspectj/AbstractCacheAnnotationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ protected void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
543543
Object r1 = service.multiConditionalCacheAndEvict(key);
544544
Object r3 = service.multiConditionalCacheAndEvict(key);
545545

546-
assertThat(r1.equals(r3)).isFalse();
546+
assertThat(r1).isNotEqualTo(r3);
547547
assertThat(primary.get(key)).isNull();
548548

549549
Object key2 = 3;

spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public void beanDefinitionEquality() {
3535
bd.setLazyInit(true);
3636
bd.setScope("request");
3737
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
38-
assertThat(bd.equals(otherBd)).isFalse();
39-
assertThat(otherBd.equals(bd)).isFalse();
38+
assertThat(bd).isNotEqualTo(otherBd);
39+
assertThat(otherBd).isNotEqualTo(bd);
4040
otherBd.setAbstract(true);
4141
otherBd.setLazyInit(true);
4242
otherBd.setScope("request");
43-
assertThat(bd.equals(otherBd)).isTrue();
44-
assertThat(otherBd.equals(bd)).isTrue();
43+
assertThat(bd).isEqualTo(otherBd);
44+
assertThat(otherBd).isEqualTo(bd);
4545
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
4646
}
4747

@@ -52,14 +52,14 @@ public void beanDefinitionEqualityWithPropertyValues() {
5252
bd.getPropertyValues().add("age", "99");
5353
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
5454
otherBd.getPropertyValues().add("name", "myName");
55-
assertThat(bd.equals(otherBd)).isFalse();
56-
assertThat(otherBd.equals(bd)).isFalse();
55+
assertThat(bd).isNotEqualTo(otherBd);
56+
assertThat(otherBd).isNotEqualTo(bd);
5757
otherBd.getPropertyValues().add("age", "11");
58-
assertThat(bd.equals(otherBd)).isFalse();
59-
assertThat(otherBd.equals(bd)).isFalse();
58+
assertThat(bd).isNotEqualTo(otherBd);
59+
assertThat(otherBd).isNotEqualTo(bd);
6060
otherBd.getPropertyValues().add("age", "99");
61-
assertThat(bd.equals(otherBd)).isTrue();
62-
assertThat(otherBd.equals(bd)).isTrue();
61+
assertThat(bd).isEqualTo(otherBd);
62+
assertThat(otherBd).isEqualTo(bd);
6363
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
6464
}
6565

@@ -70,14 +70,14 @@ public void beanDefinitionEqualityWithConstructorArguments() {
7070
bd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5);
7171
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
7272
otherBd.getConstructorArgumentValues().addGenericArgumentValue("test");
73-
assertThat(bd.equals(otherBd)).isFalse();
74-
assertThat(otherBd.equals(bd)).isFalse();
73+
assertThat(bd).isNotEqualTo(otherBd);
74+
assertThat(otherBd).isNotEqualTo(bd);
7575
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 9);
76-
assertThat(bd.equals(otherBd)).isFalse();
77-
assertThat(otherBd.equals(bd)).isFalse();
76+
assertThat(bd).isNotEqualTo(otherBd);
77+
assertThat(otherBd).isNotEqualTo(bd);
7878
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5);
79-
assertThat(bd.equals(otherBd)).isTrue();
80-
assertThat(otherBd.equals(bd)).isTrue();
79+
assertThat(bd).isEqualTo(otherBd);
80+
assertThat(otherBd).isEqualTo(bd);
8181
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
8282
}
8383

@@ -89,14 +89,14 @@ public void beanDefinitionEqualityWithTypedConstructorArguments() {
8989
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
9090
otherBd.getConstructorArgumentValues().addGenericArgumentValue("test", "int");
9191
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5);
92-
assertThat(bd.equals(otherBd)).isFalse();
93-
assertThat(otherBd.equals(bd)).isFalse();
92+
assertThat(bd).isNotEqualTo(otherBd);
93+
assertThat(otherBd).isNotEqualTo(bd);
9494
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "int");
95-
assertThat(bd.equals(otherBd)).isFalse();
96-
assertThat(otherBd.equals(bd)).isFalse();
95+
assertThat(bd).isNotEqualTo(otherBd);
96+
assertThat(otherBd).isNotEqualTo(bd);
9797
otherBd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "long");
98-
assertThat(bd.equals(otherBd)).isTrue();
99-
assertThat(otherBd.equals(bd)).isTrue();
98+
assertThat(bd).isEqualTo(otherBd);
99+
assertThat(otherBd).isEqualTo(bd);
100100
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
101101
}
102102

@@ -111,21 +111,21 @@ public void genericBeanDefinitionEquality() {
111111
otherBd.setScope("request");
112112
otherBd.setAbstract(true);
113113
otherBd.setLazyInit(true);
114-
assertThat(bd.equals(otherBd)).isFalse();
115-
assertThat(otherBd.equals(bd)).isFalse();
114+
assertThat(bd).isNotEqualTo(otherBd);
115+
assertThat(otherBd).isNotEqualTo(bd);
116116
otherBd.setParentName("parent");
117-
assertThat(bd.equals(otherBd)).isTrue();
118-
assertThat(otherBd.equals(bd)).isTrue();
117+
assertThat(bd).isEqualTo(otherBd);
118+
assertThat(otherBd).isEqualTo(bd);
119119
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
120120

121121
bd.getPropertyValues();
122-
assertThat(bd.equals(otherBd)).isTrue();
123-
assertThat(otherBd.equals(bd)).isTrue();
122+
assertThat(bd).isEqualTo(otherBd);
123+
assertThat(otherBd).isEqualTo(bd);
124124
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
125125

126126
bd.getConstructorArgumentValues();
127-
assertThat(bd.equals(otherBd)).isTrue();
128-
assertThat(otherBd.equals(bd)).isTrue();
127+
assertThat(bd).isEqualTo(otherBd);
128+
assertThat(otherBd).isEqualTo(bd);
129129
assertThat(bd.hashCode()).isEqualTo(otherBd.hashCode());
130130
}
131131

@@ -137,14 +137,14 @@ public void beanDefinitionHolderEquality() {
137137
bd.setScope("request");
138138
BeanDefinitionHolder holder = new BeanDefinitionHolder(bd, "bd");
139139
RootBeanDefinition otherBd = new RootBeanDefinition(TestBean.class);
140-
assertThat(bd.equals(otherBd)).isFalse();
141-
assertThat(otherBd.equals(bd)).isFalse();
140+
assertThat(bd).isNotEqualTo(otherBd);
141+
assertThat(otherBd).isNotEqualTo(bd);
142142
otherBd.setAbstract(true);
143143
otherBd.setLazyInit(true);
144144
otherBd.setScope("request");
145145
BeanDefinitionHolder otherHolder = new BeanDefinitionHolder(bd, "bd");
146-
assertThat(holder.equals(otherHolder)).isTrue();
147-
assertThat(otherHolder.equals(holder)).isTrue();
146+
assertThat(holder).isEqualTo(otherHolder);
147+
assertThat(otherHolder).isEqualTo(holder);
148148
assertThat(holder.hashCode()).isEqualTo(otherHolder.hashCode());
149149
}
150150

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Excepti
8585
List l = (List) jumble.getJumble();
8686
assertThat(l.get(0).equals("literal")).isTrue();
8787
Integer[] array1 = (Integer[]) l.get(1);
88-
assertThat(array1[0].equals(2)).isTrue();
89-
assertThat(array1[1].equals(4)).isTrue();
88+
assertThat(array1[0]).isEqualTo(2);
89+
assertThat(array1[1]).isEqualTo(4);
9090
int[] array2 = (int[]) l.get(2);
9191
assertThat(array2[0]).isEqualTo(3);
9292
assertThat(array2[1]).isEqualTo(5);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ public void testMapWithLiteralsOnly() {
198198
public void testMapWithLiteralsAndReferences() {
199199
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap");
200200
assertThat(hasMap.getMap().size()).isEqualTo(5);
201-
assertThat(hasMap.getMap().get("foo").equals(10)).isTrue();
201+
assertThat(hasMap.getMap().get("foo")).isEqualTo(10);
202202
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
203203
assertThat(hasMap.getMap().get("jenny")).isSameAs(jenny);
204204
assertThat(hasMap.getMap().get(5).equals("david")).isTrue();
205205
assertThat(hasMap.getMap().get("bar")).isInstanceOf(Long.class);
206-
assertThat(hasMap.getMap().get("bar").equals(100L)).isTrue();
206+
assertThat(hasMap.getMap().get("bar")).isEqualTo(100L);
207207
assertThat(hasMap.getMap().get("baz")).isInstanceOf(Integer.class);
208-
assertThat(hasMap.getMap().get("baz").equals(200)).isTrue();
208+
assertThat(hasMap.getMap().get("baz")).isEqualTo(200);
209209
}
210210

211211
@Test
@@ -230,7 +230,7 @@ public void testMapWithLiteralsReferencesAndList() {
230230
assertThat(hasMap.getMap().size()).isEqualTo(4);
231231
assertThat(hasMap.getMap().get(null).equals("bar")).isTrue();
232232
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
233-
assertThat(hasMap.getMap().get("jenny").equals(jenny)).isTrue();
233+
assertThat(hasMap.getMap().get("jenny")).isEqualTo(jenny);
234234

235235
// Check list
236236
List l = (List) hasMap.getMap().get("list");
@@ -250,7 +250,7 @@ public void testMapWithLiteralsReferencesAndList() {
250250
l = (List) l.get(2);
251251
assertThat(l).isNotNull();
252252
assertThat(l.size()).isEqualTo(2);
253-
assertThat(l.get(0).equals(jenny)).isTrue();
253+
assertThat(l.get(0)).isEqualTo(jenny);
254254
assertThat(l.get(1).equals("ba")).isTrue();
255255

256256
// Check nested map

spring-context-support/src/test/java/org/springframework/mail/SimpleMailMessageTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public final void testEqualsObject() {
128128
// Same object is equal
129129
message1 = new SimpleMailMessage();
130130
message2 = message1;
131-
assertThat(message1.equals(message2)).isTrue();
131+
assertThat(message1).isEqualTo(message2);
132132

133133
// Null object is not equal
134134
message1 = new SimpleMailMessage();
@@ -143,7 +143,7 @@ public final void testEqualsObject() {
143143
// Equal values are equal
144144
message1 = new SimpleMailMessage();
145145
message2 = new SimpleMailMessage();
146-
assertThat(message1.equals(message2)).isTrue();
146+
assertThat(message1).isEqualTo(message2);
147147

148148
message1 = new SimpleMailMessage();
149149
message1.setFrom("from@somewhere");
@@ -155,7 +155,7 @@ public final void testEqualsObject() {
155155
message1.setSubject("subject");
156156
message1.setText("text");
157157
message2 = new SimpleMailMessage(message1);
158-
assertThat(message1.equals(message2)).isTrue();
158+
assertThat(message1).isEqualTo(message2);
159159
}
160160

161161
@Test

spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ public void testEquals() {
11781178
assertThat(i2).isEqualTo(i1);
11791179
assertThat(proxyB).isEqualTo(proxyA);
11801180
assertThat(proxyB.hashCode()).isEqualTo(proxyA.hashCode());
1181-
assertThat(proxyA.equals(a)).isFalse();
1181+
assertThat(proxyA).isNotEqualTo(a);
11821182

11831183
// Equality checks were handled by the proxy
11841184
assertThat(i1.getCount()).isEqualTo(0);
@@ -1187,7 +1187,7 @@ public void testEquals() {
11871187
// and won't think it's equal to B's NopInterceptor
11881188
proxyA.absquatulate();
11891189
assertThat(i1.getCount()).isEqualTo(1);
1190-
assertThat(proxyA.equals(proxyB)).isFalse();
1190+
assertThat(proxyA).isNotEqualTo(proxyB);
11911191
}
11921192

11931193
@Test

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ void verifyEquals() throws Exception {
4444
ConfigurationClass configurationClass2 = newConfigurationClass(Config1.class);
4545
ConfigurationClass configurationClass3 = newConfigurationClass(Config2.class);
4646

47-
assertThat(configurationClass1.equals(null)).isFalse();
47+
assertThat(configurationClass1).isNotEqualTo(null);
4848
assertThat(configurationClass1).isNotSameAs(configurationClass2);
4949

50-
assertThat(configurationClass1.equals(configurationClass1)).isTrue();
51-
assertThat(configurationClass2.equals(configurationClass2)).isTrue();
52-
assertThat(configurationClass1.equals(configurationClass2)).isTrue();
53-
assertThat(configurationClass2.equals(configurationClass1)).isTrue();
50+
assertThat(configurationClass1).isEqualTo(configurationClass1);
51+
assertThat(configurationClass2).isEqualTo(configurationClass2);
52+
assertThat(configurationClass1).isEqualTo(configurationClass2);
53+
assertThat(configurationClass2).isEqualTo(configurationClass1);
5454

55-
assertThat(configurationClass1.equals(configurationClass3)).isFalse();
56-
assertThat(configurationClass3.equals(configurationClass2)).isFalse();
55+
assertThat(configurationClass1).isNotEqualTo(configurationClass3);
56+
assertThat(configurationClass3).isNotEqualTo(configurationClass2);
5757

5858
// ---------------------------------------------------------------------
5959

@@ -72,18 +72,18 @@ void verifyEquals() throws Exception {
7272
BeanMethod beanMethod_3_1 = beanMethods3.get(1);
7373
BeanMethod beanMethod_3_2 = beanMethods3.get(2);
7474

75-
assertThat(beanMethod_1_0.equals(null)).isFalse();
75+
assertThat(beanMethod_1_0).isNotEqualTo(null);
7676
assertThat(beanMethod_1_0).isNotSameAs(beanMethod_2_0);
7777

78-
assertThat(beanMethod_1_0.equals(beanMethod_1_0)).isTrue();
79-
assertThat(beanMethod_1_0.equals(beanMethod_2_0)).isTrue();
80-
assertThat(beanMethod_1_1.equals(beanMethod_2_1)).isTrue();
81-
assertThat(beanMethod_1_2.equals(beanMethod_2_2)).isTrue();
78+
assertThat(beanMethod_1_0).isEqualTo(beanMethod_1_0);
79+
assertThat(beanMethod_1_0).isEqualTo(beanMethod_2_0);
80+
assertThat(beanMethod_1_1).isEqualTo(beanMethod_2_1);
81+
assertThat(beanMethod_1_2).isEqualTo(beanMethod_2_2);
8282

8383
assertThat(beanMethod_1_0.getMetadata().getMethodName()).isEqualTo(beanMethod_3_0.getMetadata().getMethodName());
84-
assertThat(beanMethod_1_0.equals(beanMethod_3_0)).isFalse();
85-
assertThat(beanMethod_1_1.equals(beanMethod_3_1)).isFalse();
86-
assertThat(beanMethod_1_2.equals(beanMethod_3_2)).isFalse();
84+
assertThat(beanMethod_1_0).isNotEqualTo(beanMethod_3_0);
85+
assertThat(beanMethod_1_1).isNotEqualTo(beanMethod_3_1);
86+
assertThat(beanMethod_1_2).isNotEqualTo(beanMethod_3_2);
8787
}
8888

8989
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void configurationWithNullReference() {
210210
BeanFactory factory = initBeanFactory(ConfigWithNullReference.class);
211211

212212
TestBean foo = factory.getBean("foo", TestBean.class);
213-
assertThat(factory.getBean("bar").equals(null)).isTrue();
213+
assertThat(factory.getBean("bar")).isEqualTo(null);
214214
assertThat(foo.getSpouse()).isNull();
215215
}
216216

0 commit comments

Comments
 (0)