Use idiomatic AssertJ assertions for true, false, and null

This commit is contained in:
Sam Brannen
2022-01-10 14:15:55 +01:00
parent 2a80b64d40
commit df263d01b9
75 changed files with 345 additions and 333 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@@ -196,7 +196,7 @@ class CommonsPool2TargetSourceTests {
void testSetWhenExhaustedAction() {
CommonsPool2TargetSource targetSource = new CommonsPool2TargetSource();
targetSource.setBlockWhenExhausted(true);
assertThat(targetSource.isBlockWhenExhausted()).isEqualTo(true);
assertThat(targetSource.isBlockWhenExhausted()).isTrue();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@@ -876,7 +876,7 @@ class XmlBeanFactoryTests {
// should have been autowired
assertThat(rod1.getSpouse1()).isEqualTo(kerry);
assertThat(rod1.getAge()).isEqualTo(0);
assertThat(rod1.getName()).isEqualTo(null);
assertThat(rod1.getName()).isNull();
ConstructorDependenciesBean rod2 = (ConstructorDependenciesBean) xbf.getBean("rod2");
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
@@ -885,7 +885,7 @@ class XmlBeanFactoryTests {
assertThat(rod2.getSpouse1()).isEqualTo(kerry2);
assertThat(rod2.getSpouse2()).isEqualTo(kerry1);
assertThat(rod2.getAge()).isEqualTo(0);
assertThat(rod2.getName()).isEqualTo(null);
assertThat(rod2.getName()).isNull();
ConstructorDependenciesBean rod = (ConstructorDependenciesBean) xbf.getBean("rod3");
IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
@@ -894,7 +894,7 @@ class XmlBeanFactoryTests {
assertThat(rod.getSpouse2()).isEqualTo(kerry);
assertThat(rod.getOther()).isEqualTo(other);
assertThat(rod.getAge()).isEqualTo(0);
assertThat(rod.getName()).isEqualTo(null);
assertThat(rod.getName()).isNull();
xbf.getBean("rod4", ConstructorDependenciesBean.class);
// should have been autowired
@@ -902,7 +902,7 @@ class XmlBeanFactoryTests {
assertThat(rod.getSpouse2()).isEqualTo(kerry);
assertThat(rod.getOther()).isEqualTo(other);
assertThat(rod.getAge()).isEqualTo(0);
assertThat(rod.getName()).isEqualTo(null);
assertThat(rod.getName()).isNull();
}
@Test
@@ -929,7 +929,7 @@ class XmlBeanFactoryTests {
assertThat(rod6.getSpouse2()).isEqualTo(kerry1);
assertThat(rod6.getOther()).isEqualTo(other);
assertThat(rod6.getAge()).isEqualTo(0);
assertThat(rod6.getName()).isEqualTo(null);
assertThat(rod6.getName()).isNull();
xbf.destroySingletons();
assertThat(rod6.destroyed).isTrue();
@@ -967,7 +967,7 @@ class XmlBeanFactoryTests {
assertThat(rod9c.getAge()).isEqualTo(97);
ConstructorDependenciesBean rod10 = (ConstructorDependenciesBean) xbf.getBean("rod10");
assertThat(rod10.getName()).isEqualTo(null);
assertThat(rod10.getName()).isNull();
ConstructorDependenciesBean rod11 = (ConstructorDependenciesBean) xbf.getBean("rod11");
assertThat(rod11.getSpouse1()).isEqualTo(kerry2);
@@ -1331,7 +1331,7 @@ class XmlBeanFactoryTests {
OverrideOneMethodSubclass ooms = (OverrideOneMethodSubclass) xbf.getBean("replaceVoidMethod");
DoSomethingReplacer dos = (DoSomethingReplacer) xbf.getBean("doSomethingReplacer");
assertThat(dos.lastArg).isEqualTo(null);
assertThat(dos.lastArg).isNull();
String s1 = "";
String s2 = "foo bar black sheep";
ooms.doSomething(s1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -47,7 +47,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveLookupByName() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
boolean b = ctx.getBean("b", boolean.class);
assertThat(b).isEqualTo(true);
assertThat(b).isTrue();
int i = ctx.getBean("i", int.class);
assertThat(i).isEqualTo(42);
}
@@ -56,7 +56,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveLookupByType() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
boolean b = ctx.getBean(boolean.class);
assertThat(b).isEqualTo(true);
assertThat(b).isTrue();
int i = ctx.getBean(int.class);
assertThat(i).isEqualTo(42);
}
@@ -65,7 +65,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveAutowiredInjection() {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(Config.class, AutowiredComponent.class);
assertThat(ctx.getBean(AutowiredComponent.class).b).isEqualTo(true);
assertThat(ctx.getBean(AutowiredComponent.class).b).isTrue();
assertThat(ctx.getBean(AutowiredComponent.class).i).isEqualTo(42);
}
@@ -73,7 +73,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveResourceInjection() {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(Config.class, ResourceComponent.class);
assertThat(ctx.getBean(ResourceComponent.class).b).isEqualTo(true);
assertThat(ctx.getBean(ResourceComponent.class).b).isTrue();
assertThat(ctx.getBean(ResourceComponent.class).i).isEqualTo(42);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -27,6 +27,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -43,7 +44,7 @@ public class CachedExpressionEvaluatorTests {
Method method = ReflectionUtils.findMethod(getClass(), "toString");
Expression expression = expressionEvaluator.getTestExpression("true", method, getClass());
hasParsedExpression("true");
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
assertThat(expressionEvaluator.testCache.size()).as("Expression should be in cache").isEqualTo(1);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -25,6 +25,7 @@ import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
/**
* Unit tests for {@link MethodBasedEvaluationContext}.
@@ -47,9 +48,9 @@ public class MethodBasedEvaluationContextTests {
assertThat(context.lookupVariable("p0")).isEqualTo("test");
assertThat(context.lookupVariable("foo")).isEqualTo("test");
assertThat(context.lookupVariable("a1")).isEqualTo(true);
assertThat(context.lookupVariable("p1")).isEqualTo(true);
assertThat(context.lookupVariable("flag")).isEqualTo(true);
assertThat(context.lookupVariable("a1")).asInstanceOf(BOOLEAN).isTrue();
assertThat(context.lookupVariable("p1")).asInstanceOf(BOOLEAN).isTrue();
assertThat(context.lookupVariable("flag")).asInstanceOf(BOOLEAN).isTrue();
assertThat(context.lookupVariable("a2")).isNull();
assertThat(context.lookupVariable("p2")).isNull();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -345,7 +345,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
.addPropertyValue("jedi", "${jedi:false}")
.getBeanDefinition());
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).isJedi()).isEqualTo(true);
assertThat(bf.getBean(TestBean.class).isJedi()).isTrue();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -281,7 +281,7 @@ public class FormattingConversionServiceTests {
@Test
public void printNullDefault() {
assertThat(formattingService
.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class))).isEqualTo(null);
.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class))).isNull();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -42,7 +42,7 @@ public class JndiLocatorDelegateTests {
builderField.set(null, null);
try {
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()).isEqualTo(false);
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()).isFalse();
}
finally {
builderField.set(null, oldBuilder);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -57,7 +57,7 @@ public class ExecutorBeanDefinitionParserTests {
assertThat(getMaxPoolSize(executor)).isEqualTo(Integer.MAX_VALUE);
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
@Override
@@ -96,7 +96,7 @@ public class ExecutorBeanDefinitionParserTests {
assertThat(getCorePoolSize(executor)).isEqualTo(9);
assertThat(getMaxPoolSize(executor)).isEqualTo(9);
assertThat(getKeepAliveSeconds(executor)).isEqualTo(37);
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(true);
assertThat(getAllowCoreThreadTimeOut(executor)).isTrue();
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
}
@@ -106,7 +106,7 @@ public class ExecutorBeanDefinitionParserTests {
assertThat(getCorePoolSize(executor)).isEqualTo(123);
assertThat(getMaxPoolSize(executor)).isEqualTo(123);
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
}
@@ -115,7 +115,7 @@ public class ExecutorBeanDefinitionParserTests {
Object executor = this.context.getBean("propertyPlaceholderWithRange");
assertThat(getCorePoolSize(executor)).isEqualTo(5);
assertThat(getMaxPoolSize(executor)).isEqualTo(25);
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
assertThat(getQueueCapacity(executor)).isEqualTo(10);
}
@@ -124,7 +124,7 @@ public class ExecutorBeanDefinitionParserTests {
Object executor = this.context.getBean("propertyPlaceholderWithRangeAndCoreThreadTimeout");
assertThat(getCorePoolSize(executor)).isEqualTo(99);
assertThat(getMaxPoolSize(executor)).isEqualTo(99);
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(true);
assertThat(getAllowCoreThreadTimeOut(executor)).isTrue();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -1242,7 +1242,7 @@ class DataBinderTests {
assertThat(errors.getFieldError("name").getCodes()[2]).isEqualTo("NOT_ROD.java.lang.String");
assertThat(errors.getFieldError("name").getCodes()[3]).isEqualTo("NOT_ROD");
assertThat((errors.getFieldErrors("name").get(0)).getField()).isEqualTo("name");
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isEqualTo(null);
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isNull();
assertThat(errors.hasFieldErrors("spouse.age")).isTrue();
assertThat(errors.getFieldErrorCount("spouse.age")).isEqualTo(1);
@@ -1314,7 +1314,7 @@ class DataBinderTests {
assertThat(errors.getFieldError("name").getCodes()[2]).isEqualTo("validation.NOT_ROD.java.lang.String");
assertThat(errors.getFieldError("name").getCodes()[3]).isEqualTo("validation.NOT_ROD");
assertThat((errors.getFieldErrors("name").get(0)).getField()).isEqualTo("name");
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isEqualTo(null);
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isNull();
assertThat(errors.hasFieldErrors("spouse.age")).isTrue();
assertThat(errors.getFieldErrorCount("spouse.age")).isEqualTo(1);
@@ -1339,7 +1339,7 @@ class DataBinderTests {
assertThat(errors.getFieldErrorCount("spouse")).isEqualTo(1);
assertThat(errors.getFieldError("spouse").getCode()).isEqualTo("SPOUSE_NOT_AVAILABLE");
assertThat((errors.getFieldErrors("spouse").get(0)).getObjectName()).isEqualTo("tb");
assertThat((errors.getFieldErrors("spouse").get(0)).getRejectedValue()).isEqualTo(null);
assertThat((errors.getFieldErrors("spouse").get(0)).getRejectedValue()).isNull();
}
@Test