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-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.
@@ -71,8 +71,8 @@ class GenericTypeResolverTests {
void methodReturnTypes() {
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "integer"), MyInterfaceType.class)).isEqualTo(Integer.class);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "string"), MyInterfaceType.class)).isEqualTo(String.class);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class)).isEqualTo(null);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class)).isEqualTo(null);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class)).isNull();
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class)).isNull();
}
@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.
@@ -370,9 +370,9 @@ class ReactiveAdapterRegistryTests {
@Test
void deferred() {
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isEqualTo(false);
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isEqualTo(true);
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isEqualTo(true);
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isFalse();
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isTrue();
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isTrue();
}
}

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.
@@ -60,8 +60,8 @@ class AnnotationAttributesTests {
assertThat(attributes.getString("name")).isEqualTo("dave");
assertThat(attributes.getStringArray("names")).isEqualTo(new String[] {"dave", "frank", "hal"});
assertThat(attributes.getBoolean("bool1")).isEqualTo(true);
assertThat(attributes.getBoolean("bool2")).isEqualTo(false);
assertThat(attributes.getBoolean("bool1")).isTrue();
assertThat(attributes.getBoolean("bool2")).isFalse();
assertThat(attributes.<Color>getEnum("color")).isEqualTo(Color.RED);
assertThat(attributes.getClass("class").equals(Integer.class)).isTrue();
assertThat(attributes.getClassArray("classes")).isEqualTo(new Class<?>[] {Number.class, Short.class, Integer.class});

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.
@@ -79,7 +79,7 @@ class DefaultConversionServiceTests {
@Test
void stringToCharacterEmptyString() {
assertThat(conversionService.convert("", Character.class)).isEqualTo(null);
assertThat(conversionService.convert("", Character.class)).isNull();
}
@Test
@@ -95,29 +95,29 @@ class DefaultConversionServiceTests {
@Test
void stringToBooleanTrue() {
assertThat(conversionService.convert("true", Boolean.class)).isEqualTo(true);
assertThat(conversionService.convert("on", Boolean.class)).isEqualTo(true);
assertThat(conversionService.convert("yes", Boolean.class)).isEqualTo(true);
assertThat(conversionService.convert("1", Boolean.class)).isEqualTo(true);
assertThat(conversionService.convert("TRUE", Boolean.class)).isEqualTo(true);
assertThat(conversionService.convert("ON", Boolean.class)).isEqualTo(true);
assertThat(conversionService.convert("YES", Boolean.class)).isEqualTo(true);
assertThat(conversionService.convert("true", Boolean.class)).isTrue();
assertThat(conversionService.convert("on", Boolean.class)).isTrue();
assertThat(conversionService.convert("yes", Boolean.class)).isTrue();
assertThat(conversionService.convert("1", Boolean.class)).isTrue();
assertThat(conversionService.convert("TRUE", Boolean.class)).isTrue();
assertThat(conversionService.convert("ON", Boolean.class)).isTrue();
assertThat(conversionService.convert("YES", Boolean.class)).isTrue();
}
@Test
void stringToBooleanFalse() {
assertThat(conversionService.convert("false", Boolean.class)).isEqualTo(false);
assertThat(conversionService.convert("off", Boolean.class)).isEqualTo(false);
assertThat(conversionService.convert("no", Boolean.class)).isEqualTo(false);
assertThat(conversionService.convert("0", Boolean.class)).isEqualTo(false);
assertThat(conversionService.convert("FALSE", Boolean.class)).isEqualTo(false);
assertThat(conversionService.convert("OFF", Boolean.class)).isEqualTo(false);
assertThat(conversionService.convert("NO", Boolean.class)).isEqualTo(false);
assertThat(conversionService.convert("false", Boolean.class)).isFalse();
assertThat(conversionService.convert("off", Boolean.class)).isFalse();
assertThat(conversionService.convert("no", Boolean.class)).isFalse();
assertThat(conversionService.convert("0", Boolean.class)).isFalse();
assertThat(conversionService.convert("FALSE", Boolean.class)).isFalse();
assertThat(conversionService.convert("OFF", Boolean.class)).isFalse();
assertThat(conversionService.convert("NO", Boolean.class)).isFalse();
}
@Test
void stringToBooleanEmptyString() {
assertThat(conversionService.convert("", Boolean.class)).isEqualTo(null);
assertThat(conversionService.convert("", Boolean.class)).isNull();
}
@Test
@@ -219,7 +219,7 @@ class DefaultConversionServiceTests {
@Test
void stringToNumberEmptyString() {
assertThat(conversionService.convert("", Number.class)).isEqualTo(null);
assertThat(conversionService.convert("", Number.class)).isNull();
}
@Test
@@ -234,7 +234,7 @@ class DefaultConversionServiceTests {
@Test
void stringToEnumEmptyString() {
assertThat(conversionService.convert("", Foo.class)).isEqualTo(null);
assertThat(conversionService.convert("", Foo.class)).isNull();
}
@Test
@@ -254,7 +254,7 @@ class DefaultConversionServiceTests {
@Test
void integerToEnumNull() {
assertThat(conversionService.convert(null, Foo.class)).isEqualTo(null);
assertThat(conversionService.convert(null, Foo.class)).isNull();
}
@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.
@@ -109,7 +109,7 @@ class GenericConversionServiceTests {
@Test
void convertNullSource() {
assertThat(conversionService.convert(null, Integer.class)).isEqualTo(null);
assertThat(conversionService.convert(null, Integer.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.
@@ -79,7 +79,7 @@ class PropertySourceTests {
PropertySource<?> ps1 = new MapPropertySource("ps1", map1);
ps1.getSource();
List<PropertySource<?>> propertySources = new ArrayList<>();
assertThat(propertySources.add(ps1)).isEqualTo(true);
assertThat(propertySources.add(ps1)).isTrue();
assertThat(propertySources.contains(ps1)).isTrue();
assertThat(propertySources.contains(PropertySource.named("ps1"))).isTrue();

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.
@@ -50,7 +50,7 @@ class SystemEnvironmentPropertySourceTests {
@Test
void none() {
assertThat(ps.containsProperty("a.key")).isEqualTo(false);
assertThat(ps.containsProperty("a.key")).isFalse();
assertThat(ps.getProperty("a.key")).isNull();
}
@@ -58,7 +58,7 @@ class SystemEnvironmentPropertySourceTests {
void normalWithoutPeriod() {
envMap.put("akey", "avalue");
assertThat(ps.containsProperty("akey")).isEqualTo(true);
assertThat(ps.containsProperty("akey")).isTrue();
assertThat(ps.getProperty("akey")).isEqualTo("avalue");
}
@@ -66,7 +66,7 @@ class SystemEnvironmentPropertySourceTests {
void normalWithPeriod() {
envMap.put("a.key", "a.value");
assertThat(ps.containsProperty("a.key")).isEqualTo(true);
assertThat(ps.containsProperty("a.key")).isTrue();
assertThat(ps.getProperty("a.key")).isEqualTo("a.value");
}
@@ -74,8 +74,8 @@ class SystemEnvironmentPropertySourceTests {
void withUnderscore() {
envMap.put("a_key", "a_value");
assertThat(ps.containsProperty("a_key")).isEqualTo(true);
assertThat(ps.containsProperty("a.key")).isEqualTo(true);
assertThat(ps.containsProperty("a_key")).isTrue();
assertThat(ps.containsProperty("a.key")).isTrue();
assertThat(ps.getProperty("a_key")).isEqualTo("a_value");
assertThat( ps.getProperty("a.key")).isEqualTo("a_value");
@@ -97,30 +97,30 @@ class SystemEnvironmentPropertySourceTests {
envMap.put("A_DOT.KEY", "a_dot_value");
envMap.put("A_HYPHEN-KEY", "a_hyphen_value");
assertThat(ps.containsProperty("A_KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("a_key")).isEqualTo(true);
assertThat(ps.containsProperty("a.key")).isEqualTo(true);
assertThat(ps.containsProperty("a-key")).isEqualTo(true);
assertThat(ps.containsProperty("A_LONG_KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A.LONG.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A-LONG-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A.LONG-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A-LONG.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A_long_KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A.long.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A-long-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A.long-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A-long.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A_DOT.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A-DOT.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A_dot.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A-dot.KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A_HYPHEN-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A.HYPHEN-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A_hyphen-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A.hyphen-KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A_KEY")).isTrue();
assertThat(ps.containsProperty("A.KEY")).isTrue();
assertThat(ps.containsProperty("A-KEY")).isTrue();
assertThat(ps.containsProperty("a_key")).isTrue();
assertThat(ps.containsProperty("a.key")).isTrue();
assertThat(ps.containsProperty("a-key")).isTrue();
assertThat(ps.containsProperty("A_LONG_KEY")).isTrue();
assertThat(ps.containsProperty("A.LONG.KEY")).isTrue();
assertThat(ps.containsProperty("A-LONG-KEY")).isTrue();
assertThat(ps.containsProperty("A.LONG-KEY")).isTrue();
assertThat(ps.containsProperty("A-LONG.KEY")).isTrue();
assertThat(ps.containsProperty("A_long_KEY")).isTrue();
assertThat(ps.containsProperty("A.long.KEY")).isTrue();
assertThat(ps.containsProperty("A-long-KEY")).isTrue();
assertThat(ps.containsProperty("A.long-KEY")).isTrue();
assertThat(ps.containsProperty("A-long.KEY")).isTrue();
assertThat(ps.containsProperty("A_DOT.KEY")).isTrue();
assertThat(ps.containsProperty("A-DOT.KEY")).isTrue();
assertThat(ps.containsProperty("A_dot.KEY")).isTrue();
assertThat(ps.containsProperty("A-dot.KEY")).isTrue();
assertThat(ps.containsProperty("A_HYPHEN-KEY")).isTrue();
assertThat(ps.containsProperty("A.HYPHEN-KEY")).isTrue();
assertThat(ps.containsProperty("A_hyphen-KEY")).isTrue();
assertThat(ps.containsProperty("A.hyphen-KEY")).isTrue();
assertThat(ps.getProperty("A_KEY")).isEqualTo("a_value");
assertThat(ps.getProperty("A.KEY")).isEqualTo("a_value");
@@ -170,7 +170,7 @@ class SystemEnvironmentPropertySourceTests {
}
};
assertThat(ps.containsProperty("A_KEY")).isEqualTo(true);
assertThat(ps.containsProperty("A_KEY")).isTrue();
assertThat(ps.getProperty("A_KEY")).isEqualTo("a_value");
}

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.
@@ -124,37 +124,37 @@ class PathResourceTests {
@Test
void fileExists() {
PathResource resource = new PathResource(TEST_FILE);
assertThat(resource.exists()).isEqualTo(true);
assertThat(resource.exists()).isTrue();
}
@Test
void dirExists() {
PathResource resource = new PathResource(TEST_DIR);
assertThat(resource.exists()).isEqualTo(true);
assertThat(resource.exists()).isTrue();
}
@Test
void fileDoesNotExist() {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThat(resource.exists()).isEqualTo(false);
assertThat(resource.exists()).isFalse();
}
@Test
void fileIsReadable() {
PathResource resource = new PathResource(TEST_FILE);
assertThat(resource.isReadable()).isEqualTo(true);
assertThat(resource.isReadable()).isTrue();
}
@Test
void doesNotExistIsNotReadable() {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThat(resource.isReadable()).isEqualTo(false);
assertThat(resource.isReadable()).isFalse();
}
@Test
void directoryIsNotReadable() {
PathResource resource = new PathResource(TEST_DIR);
assertThat(resource.isReadable()).isEqualTo(false);
assertThat(resource.isReadable()).isFalse();
}
@Test
@@ -256,13 +256,13 @@ class PathResourceTests {
@Test
void fileIsWritable() {
PathResource resource = new PathResource(TEST_FILE);
assertThat(resource.isWritable()).isEqualTo(true);
assertThat(resource.isWritable()).isTrue();
}
@Test
void directoryIsNotWritable() {
PathResource resource = new PathResource(TEST_DIR);
assertThat(resource.isWritable()).isEqualTo(false);
assertThat(resource.isWritable()).isFalse();
}
@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.
@@ -115,7 +115,7 @@ class AnnotationMetadataTests {
assertThat(metadata.getAnnotationAttributes(MetaAnnotation.class.getName(), false)).isNull();
assertThat(metadata.getAnnotationAttributes(MetaAnnotation.class.getName(), true)).isNull();
assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size()).isEqualTo(0);
assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName())).isEqualTo(false);
assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName())).isFalse();
assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName())).isNull();
}

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.
@@ -28,8 +28,8 @@ class PatternMatchUtilsTests {
@Test
void trivial() {
assertThat(PatternMatchUtils.simpleMatch((String) null, "")).isEqualTo(false);
assertThat(PatternMatchUtils.simpleMatch("1", null)).isEqualTo(false);
assertThat(PatternMatchUtils.simpleMatch((String) null, "")).isFalse();
assertThat(PatternMatchUtils.simpleMatch("1", null)).isFalse();
doTest("*", "123", true);
doTest("123", "123", true);
}

View File

@@ -37,18 +37,18 @@ class StringUtilsTests {
@Test
void hasTextBlank() {
String blank = " ";
assertThat(StringUtils.hasText(blank)).isEqualTo(false);
assertThat(StringUtils.hasText(blank)).isFalse();
}
@Test
void hasTextNullEmpty() {
assertThat(StringUtils.hasText(null)).isEqualTo(false);
assertThat(StringUtils.hasText("")).isEqualTo(false);
assertThat(StringUtils.hasText(null)).isFalse();
assertThat(StringUtils.hasText("")).isFalse();
}
@Test
void hasTextValid() {
assertThat(StringUtils.hasText("t")).isEqualTo(true);
assertThat(StringUtils.hasText("t")).isTrue();
}
@Test
@@ -68,7 +68,7 @@ class StringUtilsTests {
@Test
void trimWhitespace() {
assertThat(StringUtils.trimWhitespace(null)).isEqualTo(null);
assertThat(StringUtils.trimWhitespace(null)).isNull();
assertThat(StringUtils.trimWhitespace("")).isEqualTo("");
assertThat(StringUtils.trimWhitespace(" ")).isEqualTo("");
assertThat(StringUtils.trimWhitespace("\t")).isEqualTo("");
@@ -83,7 +83,7 @@ class StringUtilsTests {
@Test
void trimAllWhitespace() {
assertThat(StringUtils.trimAllWhitespace(null)).isEqualTo(null);
assertThat(StringUtils.trimAllWhitespace(null)).isNull();
assertThat(StringUtils.trimAllWhitespace("")).isEqualTo("");
assertThat(StringUtils.trimAllWhitespace(" ")).isEqualTo("");
assertThat(StringUtils.trimAllWhitespace("\t")).isEqualTo("");
@@ -98,7 +98,7 @@ class StringUtilsTests {
@Test
void trimLeadingWhitespace() {
assertThat(StringUtils.trimLeadingWhitespace(null)).isEqualTo(null);
assertThat(StringUtils.trimLeadingWhitespace(null)).isNull();
assertThat(StringUtils.trimLeadingWhitespace("")).isEqualTo("");
assertThat(StringUtils.trimLeadingWhitespace(" ")).isEqualTo("");
assertThat(StringUtils.trimLeadingWhitespace("\t")).isEqualTo("");
@@ -113,7 +113,7 @@ class StringUtilsTests {
@Test
void trimTrailingWhitespace() {
assertThat(StringUtils.trimTrailingWhitespace(null)).isEqualTo(null);
assertThat(StringUtils.trimTrailingWhitespace(null)).isNull();
assertThat(StringUtils.trimTrailingWhitespace("")).isEqualTo("");
assertThat(StringUtils.trimTrailingWhitespace(" ")).isEqualTo("");
assertThat(StringUtils.trimTrailingWhitespace("\t")).isEqualTo("");
@@ -128,7 +128,7 @@ class StringUtilsTests {
@Test
void trimLeadingCharacter() {
assertThat(StringUtils.trimLeadingCharacter(null, ' ')).isEqualTo(null);
assertThat(StringUtils.trimLeadingCharacter(null, ' ')).isNull();
assertThat(StringUtils.trimLeadingCharacter("", ' ')).isEqualTo("");
assertThat(StringUtils.trimLeadingCharacter(" ", ' ')).isEqualTo("");
assertThat(StringUtils.trimLeadingCharacter("\t", ' ')).isEqualTo("\t");
@@ -141,7 +141,7 @@ class StringUtilsTests {
@Test
void trimTrailingCharacter() {
assertThat(StringUtils.trimTrailingCharacter(null, ' ')).isEqualTo(null);
assertThat(StringUtils.trimTrailingCharacter(null, ' ')).isNull();
assertThat(StringUtils.trimTrailingCharacter("", ' ')).isEqualTo("");
assertThat(StringUtils.trimTrailingCharacter(" ", ' ')).isEqualTo("");
assertThat(StringUtils.trimTrailingCharacter("\t", ' ')).isEqualTo("\t");
@@ -340,7 +340,7 @@ class StringUtilsTests {
@Test
void getFilename() {
assertThat(StringUtils.getFilename(null)).isEqualTo(null);
assertThat(StringUtils.getFilename(null)).isNull();
assertThat(StringUtils.getFilename("")).isEqualTo("");
assertThat(StringUtils.getFilename("myfile")).isEqualTo("myfile");
assertThat(StringUtils.getFilename("mypath/myfile")).isEqualTo("myfile");
@@ -352,11 +352,11 @@ class StringUtilsTests {
@Test
void getFilenameExtension() {
assertThat(StringUtils.getFilenameExtension(null)).isEqualTo(null);
assertThat(StringUtils.getFilenameExtension("")).isEqualTo(null);
assertThat(StringUtils.getFilenameExtension("myfile")).isEqualTo(null);
assertThat(StringUtils.getFilenameExtension("myPath/myfile")).isEqualTo(null);
assertThat(StringUtils.getFilenameExtension("/home/user/.m2/settings/myfile")).isEqualTo(null);
assertThat(StringUtils.getFilenameExtension(null)).isNull();
assertThat(StringUtils.getFilenameExtension("")).isNull();
assertThat(StringUtils.getFilenameExtension("myfile")).isNull();
assertThat(StringUtils.getFilenameExtension("myPath/myfile")).isNull();
assertThat(StringUtils.getFilenameExtension("/home/user/.m2/settings/myfile")).isNull();
assertThat(StringUtils.getFilenameExtension("myfile.")).isEqualTo("");
assertThat(StringUtils.getFilenameExtension("myPath/myfile.")).isEqualTo("");
assertThat(StringUtils.getFilenameExtension("myfile.txt")).isEqualTo("txt");