Skip to content

Commit df263d0

Browse files
committed
Use idiomatic AssertJ assertions for true, false, and null
1 parent 2a80b64 commit df263d0

File tree

75 files changed

+345
-333
lines changed

Some content is hidden

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

75 files changed

+345
-333
lines changed

integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -74,7 +74,7 @@ void succeedsWhenSubclassProxyAndScheduledMethodNotPresentOnInterface() throws I
7474

7575
MyRepository repository = ctx.getBean(MyRepository.class);
7676
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
77-
assertThat(AopUtils.isCglibProxy(repository)).isEqualTo(true);
77+
assertThat(AopUtils.isCglibProxy(repository)).isTrue();
7878
assertThat(repository.getInvocationCount()).isGreaterThan(0);
7979
assertThat(txManager.commits).isGreaterThan(0);
8080
}

spring-beans/src/test/java/org/springframework/beans/BeanWrapperEnumTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -46,15 +46,15 @@ public void testCustomEnumWithNull() {
4646
GenericBean<?> gb = new GenericBean<>();
4747
BeanWrapper bw = new BeanWrapperImpl(gb);
4848
bw.setPropertyValue("customEnum", null);
49-
assertThat(gb.getCustomEnum()).isEqualTo(null);
49+
assertThat(gb.getCustomEnum()).isNull();
5050
}
5151

5252
@Test
5353
public void testCustomEnumWithEmptyString() {
5454
GenericBean<?> gb = new GenericBean<>();
5555
BeanWrapper bw = new BeanWrapperImpl(gb);
5656
bw.setPropertyValue("customEnum", "");
57-
assertThat(gb.getCustomEnum()).isEqualTo(null);
57+
assertThat(gb.getCustomEnum()).isNull();
5858
}
5959

6060
@Test

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

Lines changed: 4 additions & 4 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-2022 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.
@@ -433,7 +433,7 @@ void nonStaticPrototypeFactoryMethodFoundByNonEagerTypeMatching() {
433433
assertThat(lbf.isTypeMatch("x1", Object.class)).isTrue();
434434
assertThat(lbf.isTypeMatch("&x1", Object.class)).isFalse();
435435
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
436-
assertThat(lbf.getType("&x1")).isEqualTo(null);
436+
assertThat(lbf.getType("&x1")).isNull();
437437
assertThat(TestBeanFactory.initialized).isFalse();
438438

439439
lbf.registerAlias("x1", "x2");
@@ -2622,8 +2622,8 @@ void initSecurityAwarePrototypeBean() {
26222622
void containsBeanReturnsTrueEvenForAbstractBeanDefinition() {
26232623
lbf.registerBeanDefinition("abs", BeanDefinitionBuilder
26242624
.rootBeanDefinition(TestBean.class).setAbstract(true).getBeanDefinition());
2625-
assertThat(lbf.containsBean("abs")).isEqualTo(true);
2626-
assertThat(lbf.containsBean("bogus")).isEqualTo(false);
2625+
assertThat(lbf.containsBean("abs")).isTrue();
2626+
assertThat(lbf.containsBean("bogus")).isFalse();
26272627
}
26282628

26292629
@Test

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -111,7 +111,7 @@ public void testPropertyOverrideConfigurer() {
111111

112112
assertThat(tb1.getAge()).isEqualTo(99);
113113
assertThat(tb2.getAge()).isEqualTo(99);
114-
assertThat(tb1.getName()).isEqualTo(null);
114+
assertThat(tb1.getName()).isNull();
115115
assertThat(tb2.getName()).isEqualTo("test");
116116
}
117117

@@ -310,7 +310,7 @@ public void testPropertyOverrideConfigurerWithIgnoreInvalidKeys() {
310310
TestBean tb2 = (TestBean) factory.getBean("tb2");
311311
assertThat(tb1.getAge()).isEqualTo(99);
312312
assertThat(tb2.getAge()).isEqualTo(99);
313-
assertThat(tb1.getName()).isEqualTo(null);
313+
assertThat(tb1.getName()).isNull();
314314
assertThat(tb2.getName()).isEqualTo("test");
315315
}
316316

@@ -423,7 +423,7 @@ private void doTestPropertyPlaceholderConfigurer(boolean parentChildSeparation)
423423
TestBean inner1 = (TestBean) tb2.getSomeMap().get("key3");
424424
TestBean inner2 = (TestBean) tb2.getSomeMap().get("mykey4");
425425
assertThat(inner1.getAge()).isEqualTo(0);
426-
assertThat(inner1.getName()).isEqualTo(null);
426+
assertThat(inner1.getName()).isNull();
427427
assertThat(inner1.getCountry()).isEqualTo(System.getProperty("os.name"));
428428
assertThat(inner2.getAge()).isEqualTo(98);
429429
assertThat(inner2.getName()).isEqualTo("namemyvarmyvar${");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -449,7 +449,7 @@ public void testTrustedExecution() throws Exception {
449449
public Object run() {
450450
// sanity check
451451
assertThat(getCurrentSubjectName()).isEqualTo("user1");
452-
assertThat(NonPrivilegedBean.destroyed).isEqualTo(false);
452+
assertThat(NonPrivilegedBean.destroyed).isFalse();
453453

454454
beanFactory.getBean("trusted-spring-callbacks");
455455
beanFactory.getBean("trusted-custom-init-destroy");
@@ -465,7 +465,7 @@ public Object run() {
465465
beanFactory.getBean("trusted-working-property-injection");
466466

467467
beanFactory.destroySingletons();
468-
assertThat(NonPrivilegedBean.destroyed).isEqualTo(true);
468+
assertThat(NonPrivilegedBean.destroyed).isTrue();
469469
return null;
470470
}
471471
}, provider.getAccessControlContext());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -100,17 +100,17 @@ public void testFactoryMethodsWithNullValue() {
100100

101101
FactoryMethods fm = (FactoryMethods) xbf.getBean("fullWithNull");
102102
assertThat(fm.getNum()).isEqualTo(27);
103-
assertThat(fm.getName()).isEqualTo(null);
103+
assertThat(fm.getName()).isNull();
104104
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
105105

106106
fm = (FactoryMethods) xbf.getBean("fullWithGenericNull");
107107
assertThat(fm.getNum()).isEqualTo(27);
108-
assertThat(fm.getName()).isEqualTo(null);
108+
assertThat(fm.getName()).isNull();
109109
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
110110

111111
fm = (FactoryMethods) xbf.getBean("fullWithNamedNull");
112112
assertThat(fm.getNum()).isEqualTo(27);
113-
assertThat(fm.getName()).isEqualTo(null);
113+
assertThat(fm.getName()).isNull();
114114
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
115115
}
116116

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -342,7 +342,7 @@ public void testNestedInConstructor() {
342342
public void testLoadProperties() {
343343
Properties props = (Properties) this.beanFactory.getBean("myProperties");
344344
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
345-
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
345+
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
346346
Properties props2 = (Properties) this.beanFactory.getBean("myProperties");
347347
assertThat(props == props2).isTrue();
348348
}
@@ -351,17 +351,17 @@ public void testLoadProperties() {
351351
public void testScopedProperties() {
352352
Properties props = (Properties) this.beanFactory.getBean("myScopedProperties");
353353
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
354-
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
354+
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
355355
Properties props2 = (Properties) this.beanFactory.getBean("myScopedProperties");
356356
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
357-
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
357+
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
358358
assertThat(props != props2).isTrue();
359359
}
360360

361361
@Test
362362
public void testLocalProperties() {
363363
Properties props = (Properties) this.beanFactory.getBean("myLocalProperties");
364-
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo(null);
364+
assertThat(props.get("foo")).as("Incorrect property value").isNull();
365365
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("bar2");
366366
}
367367

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -283,7 +283,7 @@ public void testPopulatedSet() throws Exception {
283283
Iterator it = hasMap.getSet().iterator();
284284
assertThat(it.next()).isEqualTo("bar");
285285
assertThat(it.next()).isEqualTo(jenny);
286-
assertThat(it.next()).isEqualTo(null);
286+
assertThat(it.next()).isNull();
287287
}
288288

289289
@Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -181,7 +181,7 @@ public void autoAliasing() {
181181
assertThat(beanNames.contains("aliasWithoutId3")).isFalse();
182182

183183
TestBean tb4 = (TestBean) getBeanFactory().getBean(TestBean.class.getName() + "#0");
184-
assertThat(tb4.getName()).isEqualTo(null);
184+
assertThat(tb4.getName()).isNull();
185185

186186
Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false);
187187
assertThat(drs.size()).isEqualTo(5);

spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -106,7 +106,7 @@ void testPutIfAbsentNullValue() {
106106
Cache.ValueWrapper wrapper = cache.putIfAbsent(key, "anotherValue");
107107
// A value is set but is 'null'
108108
assertThat(wrapper).isNotNull();
109-
assertThat(wrapper.get()).isEqualTo(null);
109+
assertThat(wrapper.get()).isNull();
110110
// not changed
111111
assertThat(cache.get(key).get()).isEqualTo(value);
112112
}

0 commit comments

Comments
 (0)