Simplify AssertJ assertions and also make them more readable

See gh-33653
This commit is contained in:
Krzysztof Krason
2022-12-29 17:52:45 +01:00
committed by Moritz Halbritter
parent c9a2b2ab66
commit cf6493f65c
345 changed files with 1258 additions and 1292 deletions

View File

@@ -37,7 +37,7 @@ class AuditEventTests {
@Test
void nowEvent() {
AuditEvent event = new AuditEvent("phil", "UNKNOWN", Collections.singletonMap("a", "b"));
assertThat(event.getData().get("a")).isEqualTo("b");
assertThat(event.getData()).containsEntry("a", "b");
assertThat(event.getType()).isEqualTo("UNKNOWN");
assertThat(event.getPrincipal()).isEqualTo("phil");
assertThat(event.getTimestamp()).isNotNull();
@@ -46,8 +46,8 @@ class AuditEventTests {
@Test
void convertStringsToData() {
AuditEvent event = new AuditEvent("phil", "UNKNOWN", "a=b", "c=d");
assertThat(event.getData().get("a")).isEqualTo("b");
assertThat(event.getData().get("c")).isEqualTo("d");
assertThat(event.getData()).containsEntry("a", "b");
assertThat(event.getData()).containsEntry("c", "d");
}
@Test

View File

@@ -42,7 +42,7 @@ class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "a"));
repository.add(new AuditEvent("dave", "b"));
List<AuditEvent> events = repository.find("dave", null, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events).hasSize(2);
assertThat(events.get(0).getType()).isEqualTo("a");
assertThat(events.get(1).getType()).isEqualTo("b");
}
@@ -54,7 +54,7 @@ class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "b"));
repository.add(new AuditEvent("dave", "c"));
List<AuditEvent> events = repository.find("dave", null, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events).hasSize(2);
assertThat(events.get(0).getType()).isEqualTo("b");
assertThat(events.get(1).getType()).isEqualTo("c");
}
@@ -74,7 +74,7 @@ class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "c"));
repository.add(new AuditEvent("phil", "d"));
List<AuditEvent> events = repository.find("dave", null, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events).hasSize(2);
assertThat(events.get(0).getType()).isEqualTo("a");
assertThat(events.get(1).getType()).isEqualTo("c");
}
@@ -87,7 +87,7 @@ class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "c"));
repository.add(new AuditEvent("phil", "d"));
List<AuditEvent> events = repository.find("dave", null, "a");
assertThat(events.size()).isEqualTo(1);
assertThat(events).hasSize(1);
assertThat(events.get(0).getPrincipal()).isEqualTo("dave");
assertThat(events.get(0).getType()).isEqualTo("a");
}
@@ -103,11 +103,11 @@ class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent(instant.plus(3, ChronoUnit.DAYS), "phil", "d", data));
Instant after = instant.plus(1, ChronoUnit.DAYS);
List<AuditEvent> events = repository.find(null, after, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events).hasSize(2);
assertThat(events.get(0).getType()).isEqualTo("c");
assertThat(events.get(1).getType()).isEqualTo("d");
events = repository.find("dave", after, null);
assertThat(events.size()).isEqualTo(1);
assertThat(events).hasSize(1);
assertThat(events.get(0).getType()).isEqualTo("c");
}

View File

@@ -52,7 +52,7 @@ class BeansEndpointTests {
ContextBeansDescriptor descriptor = result.getContexts().get(context.getId());
assertThat(descriptor.getParentId()).isNull();
Map<String, BeanDescriptor> beans = descriptor.getBeans();
assertThat(beans.size()).isLessThanOrEqualTo(context.getBeanDefinitionCount());
assertThat(beans).hasSizeLessThanOrEqualTo(context.getBeanDefinitionCount());
assertThat(beans).containsKey("endpoint");
});
}

View File

@@ -120,7 +120,7 @@ class CassandraDriverHealthIndicatorTests {
CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo(Version.V4_0_0);
assertThat(health.getDetails()).containsEntry("version", Version.V4_0_0);
}
@Test
@@ -129,7 +129,7 @@ class CassandraDriverHealthIndicatorTests {
CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isNull();
assertThat(health.getDetails()).doesNotContainKey("version");
}
@Test
@@ -139,8 +139,8 @@ class CassandraDriverHealthIndicatorTests {
CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("error"))
.isEqualTo(DriverTimeoutException.class.getName() + ": Test Exception");
assertThat(health.getDetails()).containsEntry("error",
DriverTimeoutException.class.getName() + ": Test Exception");
}
private CqlSession mockCqlSessionWithNodeState(NodeState... nodeStates) {

View File

@@ -131,7 +131,7 @@ class CassandraDriverReactiveHealthIndicatorTests {
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("version");
assertThat(h.getDetails().get("version")).isEqualTo(Version.V4_0_0);
assertThat(h.getDetails()).containsEntry("version", Version.V4_0_0);
}).verifyComplete();
}
@@ -142,7 +142,7 @@ class CassandraDriverReactiveHealthIndicatorTests {
Mono<Health> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails().get("version")).isNull();
assertThat(h.getDetails()).doesNotContainKey("version");
}).verifyComplete();
}
@@ -156,8 +156,8 @@ class CassandraDriverReactiveHealthIndicatorTests {
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
assertThat(h.getDetails()).containsOnlyKeys("error");
assertThat(h.getDetails().get("error"))
.isEqualTo(DriverTimeoutException.class.getName() + ": Test Exception");
assertThat(h.getDetails()).containsEntry("error",
DriverTimeoutException.class.getName() + ": Test Exception");
}).verifyComplete();
}

View File

@@ -109,7 +109,7 @@ class ConfigurationPropertiesReportEndpointFilteringTests {
.filter((id) -> findIdFromPrefix("only.bar", id)).findAny();
ConfigurationPropertiesBeanDescriptor descriptor = contextProperties.getBeans().get(key.get());
assertThat(descriptor.getPrefix()).isEqualTo("only.bar");
assertThat(descriptor.getProperties().get("name")).isEqualTo(value);
assertThat(descriptor.getProperties()).containsEntry("name", value);
});
}

View File

@@ -76,7 +76,7 @@ class ConfigurationPropertiesReportEndpointProxyTests {
.getBean(ConfigurationPropertiesReportEndpoint.class).configurationProperties();
Map<String, Object> properties = applicationProperties.getContexts().get(context.getId()).getBeans()
.values().stream().map(ConfigurationPropertiesBeanDescriptor::getProperties).findFirst().get();
assertThat(properties.get("name")).isEqualTo("baz");
assertThat(properties).containsEntry("name", "baz");
});
}

View File

@@ -71,7 +71,7 @@ class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> map = foo.getProperties();
assertThat(map).isNotNull();
assertThat(map).hasSize(2);
assertThat(map.get("name")).isEqualTo("foo");
assertThat(map).containsEntry("name", "foo");
});
}
@@ -90,7 +90,7 @@ class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> map = foo.getProperties();
assertThat(map).isNotNull();
assertThat(map).hasSize(2);
assertThat(((Map<String, Object>) map.get("bar")).get("name")).isEqualTo("foo");
assertThat(((Map<String, Object>) map.get("bar"))).containsEntry("name", "foo");
});
}
@@ -150,7 +150,7 @@ class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> map = fooProperties.getProperties();
assertThat(map).isNotNull();
assertThat(map).hasSize(3);
assertThat(((Map<String, Object>) map.get("map")).get("name")).isEqualTo("foo");
assertThat(((Map<String, Object>) map.get("map"))).containsEntry("name", "foo");
});
}
@@ -207,7 +207,7 @@ class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> map = foo.getProperties();
assertThat(map).isNotNull();
assertThat(map).hasSize(3);
assertThat(map.get("address")).isEqualTo("192.168.1.10");
assertThat(map).containsEntry("address", "192.168.1.10");
});
}

View File

@@ -105,12 +105,12 @@ class ConfigurationPropertiesReportEndpointTests {
Map<String, Object> nested = (Map<String, Object>) inputs.get("nested");
Map<String, Object> name = (Map<String, Object>) nested.get("name");
Map<String, Object> counter = (Map<String, Object>) nested.get("counter");
assertThat(name.get("value")).isEqualTo("nested");
assertThat(name.get("origin"))
.isEqualTo("\"immutablenested.nested.name\" from property source \"test\"");
assertThat(counter.get("origin"))
.isEqualTo("\"immutablenested.nested.counter\" from property source \"test\"");
assertThat(counter.get("value")).isEqualTo("42");
assertThat(name).containsEntry("value", "nested");
assertThat(name).containsEntry("origin",
"\"immutablenested.nested.name\" from property source \"test\"");
assertThat(counter).containsEntry("origin",
"\"immutablenested.nested.counter\" from property source \"test\"");
assertThat(counter).containsEntry("value", "42");
}));
}
@@ -184,8 +184,8 @@ class ConfigurationPropertiesReportEndpointTests {
.withPropertyValues(String.format("data.size=%s", configSize)).run(assertProperties("data",
(properties) -> assertThat(properties.get("size")).isEqualTo(stringifySize), (inputs) -> {
Map<String, Object> size = (Map<String, Object>) inputs.get("size");
assertThat(size.get("value")).isEqualTo(configSize);
assertThat(size.get("origin")).isEqualTo("\"data.size\" from property source \"test\"");
assertThat(size).containsEntry("value", configSize);
assertThat(size).containsEntry("origin", "\"data.size\" from property source \"test\"");
}));
}
@@ -199,15 +199,15 @@ class ConfigurationPropertiesReportEndpointTests {
List<Object> list = (List<Object>) properties.get("listItems");
assertThat(list).hasSize(1);
Map<String, Object> item = (Map<String, Object>) list.get(0);
assertThat(item.get("somePassword")).isEqualTo("******");
assertThat(item).containsEntry("somePassword", "******");
}, (inputs) -> {
List<Object> list = (List<Object>) inputs.get("listItems");
assertThat(list).hasSize(1);
Map<String, Object> item = (Map<String, Object>) list.get(0);
Map<String, Object> somePassword = (Map<String, Object>) item.get("somePassword");
assertThat(somePassword.get("value")).isEqualTo("******");
assertThat(somePassword.get("origin"))
.isEqualTo("\"sensible.listItems[0].some-password\" from property source \"test\"");
assertThat(somePassword).containsEntry("value", "******");
assertThat(somePassword).containsEntry("origin",
"\"sensible.listItems[0].some-password\" from property source \"test\"");
}));
}
@@ -223,7 +223,7 @@ class ConfigurationPropertiesReportEndpointTests {
List<Object> list = listOfLists.get(0);
assertThat(list).hasSize(1);
Map<String, Object> item = (Map<String, Object>) list.get(0);
assertThat(item.get("somePassword")).isEqualTo("******");
assertThat(item).containsEntry("somePassword", "******");
}, (inputs) -> {
assertThat(inputs.get("listOfListItems")).isInstanceOf(List.class);
List<List<Object>> listOfLists = (List<List<Object>>) inputs.get("listOfListItems");
@@ -232,8 +232,8 @@ class ConfigurationPropertiesReportEndpointTests {
assertThat(list).hasSize(1);
Map<String, Object> item = (Map<String, Object>) list.get(0);
Map<String, Object> somePassword = (Map<String, Object>) item.get("somePassword");
assertThat(somePassword.get("value")).isEqualTo("******");
assertThat(somePassword.get("origin")).isEqualTo(
assertThat(somePassword).containsEntry("value", "******");
assertThat(somePassword).containsEntry("origin",
"\"sensible.listOfListItems[0][0].some-password\" from property source \"test\"");
}));
}
@@ -243,8 +243,8 @@ class ConfigurationPropertiesReportEndpointTests {
new ApplicationContextRunner().withUserConfiguration(CustomSanitizingEndpointConfig.class,
SanitizingFunctionConfiguration.class, TestPropertiesConfiguration.class)
.run(assertProperties("test", (properties) -> {
assertThat(properties.get("dbPassword")).isEqualTo("$$$");
assertThat(properties.get("myTestProperty")).isEqualTo("$$$");
assertThat(properties).containsEntry("dbPassword", "$$$");
assertThat(properties).containsEntry("myTestProperty", "$$$");
}));
}
@@ -254,8 +254,8 @@ class ConfigurationPropertiesReportEndpointTests {
.withUserConfiguration(CustomSanitizingEndpointConfig.class,
PropertySourceBasedSanitizingFunctionConfiguration.class, TestPropertiesConfiguration.class)
.withPropertyValues("test.my-test-property=abcde").run(assertProperties("test", (properties) -> {
assertThat(properties.get("dbPassword")).isEqualTo("123456");
assertThat(properties.get("myTestProperty")).isEqualTo("$$$");
assertThat(properties).containsEntry("dbPassword", "123456");
assertThat(properties).containsEntry("myTestProperty", "$$$");
}));
}
@@ -270,15 +270,15 @@ class ConfigurationPropertiesReportEndpointTests {
List<Object> list = (List<Object>) properties.get("listItems");
assertThat(list).hasSize(1);
Map<String, Object> item = (Map<String, Object>) list.get(0);
assertThat(item.get("custom")).isEqualTo("$$$");
assertThat(item).containsEntry("custom", "$$$");
}, (inputs) -> {
List<Object> list = (List<Object>) inputs.get("listItems");
assertThat(list).hasSize(1);
Map<String, Object> item = (Map<String, Object>) list.get(0);
Map<String, Object> somePassword = (Map<String, Object>) item.get("custom");
assertThat(somePassword.get("value")).isEqualTo("$$$");
assertThat(somePassword.get("origin"))
.isEqualTo("\"sensible.listItems[0].custom\" from property source \"test\"");
assertThat(somePassword).containsEntry("value", "$$$");
assertThat(somePassword).containsEntry("origin",
"\"sensible.listItems[0].custom\" from property source \"test\"");
}));
}
@@ -287,8 +287,8 @@ class ConfigurationPropertiesReportEndpointTests {
new ApplicationContextRunner()
.withUserConfiguration(EndpointConfigWithShowAlways.class, TestPropertiesConfiguration.class)
.run(assertProperties("test", (properties) -> {
assertThat(properties.get("dbPassword")).isEqualTo("123456");
assertThat(properties.get("myTestProperty")).isEqualTo("654321");
assertThat(properties).containsEntry("dbPassword", "123456");
assertThat(properties).containsEntry("myTestProperty", "654321");
}));
}
@@ -297,8 +297,8 @@ class ConfigurationPropertiesReportEndpointTests {
new ApplicationContextRunner()
.withUserConfiguration(EndpointConfigWithShowNever.class, TestPropertiesConfiguration.class)
.run(assertProperties("test", (properties) -> {
assertThat(properties.get("dbPassword")).isEqualTo("******");
assertThat(properties.get("myTestProperty")).isEqualTo("******");
assertThat(properties).containsEntry("dbPassword", "******");
assertThat(properties).containsEntry("myTestProperty", "******");
}));
}

View File

@@ -80,7 +80,7 @@ class EndpointIdTests {
// Ideally we wouldn't support this but there are existing endpoints using the
// pattern. See gh-14773
EndpointId endpointId = EndpointId.of("foo.bar");
assertThat(endpointId.toString()).isEqualTo("foo.bar");
assertThat(endpointId).hasToString("foo.bar");
}
@Test
@@ -88,7 +88,7 @@ class EndpointIdTests {
// Ideally we wouldn't support this but there are existing endpoints using the
// pattern. See gh-14773
EndpointId endpointId = EndpointId.of("foo-bar");
assertThat(endpointId.toString()).isEqualTo("foo-bar");
assertThat(endpointId).hasToString("foo-bar");
}
@Test
@@ -102,21 +102,21 @@ class EndpointIdTests {
@Test
void ofWhenMigratingLegacyNameRemovesDots(CapturedOutput output) {
EndpointId endpointId = migrateLegacyName("one.two.three");
assertThat(endpointId.toString()).isEqualTo("onetwothree");
assertThat(endpointId).hasToString("onetwothree");
assertThat(output).doesNotContain("contains invalid characters");
}
@Test
void ofWhenMigratingLegacyNameRemovesHyphens(CapturedOutput output) {
EndpointId endpointId = migrateLegacyName("one-two-three");
assertThat(endpointId.toString()).isEqualTo("onetwothree");
assertThat(endpointId).hasToString("onetwothree");
assertThat(output).doesNotContain("contains invalid characters");
}
@Test
void ofWhenMigratingLegacyNameRemovesMixOfDashAndDot(CapturedOutput output) {
EndpointId endpointId = migrateLegacyName("one.two-three");
assertThat(endpointId.toString()).isEqualTo("onetwothree");
assertThat(endpointId).hasToString("onetwothree");
assertThat(output).doesNotContain("contains invalid characters");
}
@@ -135,7 +135,7 @@ class EndpointIdTests {
EndpointId four = EndpointId.of("foo.bar1");
EndpointId five = EndpointId.of("barfoo1");
EndpointId six = EndpointId.of("foobar2");
assertThat(one.hashCode()).isEqualTo(two.hashCode());
assertThat(one).hasSameHashCodeAs(two);
assertThat(one).isEqualTo(one).isEqualTo(two).isEqualTo(three).isEqualTo(four).isNotEqualTo(five)
.isNotEqualTo(six);
}
@@ -147,7 +147,7 @@ class EndpointIdTests {
@Test
void toStringReturnsString() {
assertThat(EndpointId.of("fooBar").toString()).isEqualTo("fooBar");
assertThat(EndpointId.of("fooBar")).hasToString("fooBar");
}
@Test

View File

@@ -61,7 +61,7 @@ class ProducibleOperationArgumentResolverTests {
@Test
void whenNothingIsAcceptableThenNullIsReturned() {
assertThat(resolve(acceptHeader("image/png"))).isEqualTo(null);
assertThat(resolve(acceptHeader("image/png"))).isNull();
}
@Test

View File

@@ -86,7 +86,7 @@ class OperationMethodParametersTests {
void getParameterCountShouldReturnParameterCount() {
OperationMethodParameters parameters = new OperationMethodParameters(this.exampleMethod,
new DefaultParameterNameDiscoverer());
assertThat(parameters.getParameterCount()).isEqualTo(1);
assertThat(parameters.getParameterCount()).isOne();
}
@Test

View File

@@ -64,7 +64,7 @@ class OperationMethodTests {
void getParametersShouldReturnParameters() {
OperationMethod operationMethod = new OperationMethod(this.exampleMethod, OperationType.READ);
OperationParameters parameters = operationMethod.getParameters();
assertThat(parameters.getParameterCount()).isEqualTo(1);
assertThat(parameters.getParameterCount()).isOne();
assertThat(parameters.iterator().next().getName()).isEqualTo("name");
}

View File

@@ -54,29 +54,29 @@ class MBeanInfoFactoryTests {
MBeanOperationInfo operationInfo = info.getOperations()[0];
assertThat(operationInfo.getName()).isEqualTo("testOperation");
assertThat(operationInfo.getReturnType()).isEqualTo(String.class.getName());
assertThat(operationInfo.getImpact()).isEqualTo(MBeanOperationInfo.INFO);
assertThat(operationInfo.getSignature()).hasSize(0);
assertThat(operationInfo.getImpact()).isZero();
assertThat(operationInfo.getSignature()).isEmpty();
}
@Test
void getMBeanInfoWhenReadOperationShouldHaveInfoImpact() {
MBeanInfo info = this.factory
.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation(OperationType.READ)));
assertThat(info.getOperations()[0].getImpact()).isEqualTo(MBeanOperationInfo.INFO);
assertThat(info.getOperations()[0].getImpact()).isZero();
}
@Test
void getMBeanInfoWhenWriteOperationShouldHaveActionImpact() {
MBeanInfo info = this.factory
.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation(OperationType.WRITE)));
assertThat(info.getOperations()[0].getImpact()).isEqualTo(MBeanOperationInfo.ACTION);
assertThat(info.getOperations()[0].getImpact()).isOne();
}
@Test
void getMBeanInfoWhenDeleteOperationShouldHaveActionImpact() {
MBeanInfo info = this.factory
.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation(OperationType.DELETE)));
assertThat(info.getOperations()[0].getImpact()).isEqualTo(MBeanOperationInfo.ACTION);
assertThat(info.getOperations()[0].getImpact()).isOne();
}
@Test

View File

@@ -29,12 +29,12 @@ class EndpointMappingTests {
@Test
void normalizationTurnsASlashIntoAnEmptyString() {
assertThat(new EndpointMapping("/").getPath()).isEqualTo("");
assertThat(new EndpointMapping("/").getPath()).isEmpty();
}
@Test
void normalizationLeavesAnEmptyStringAsIs() {
assertThat(new EndpointMapping("").getPath()).isEqualTo("");
assertThat(new EndpointMapping("").getPath()).isEmpty();
}
@Test

View File

@@ -351,7 +351,7 @@ abstract class HealthEndpointSupportTests<S extends HealthEndpointSupport<C, T>,
Collections.singletonMap("testGroup", testGroup));
HealthResult<T> result = create(this.registry, groups).getHealth(ApiVersion.V3, WebServerNamespace.SERVER,
SecurityContext.NONE, false, "healthz", "test");
assertThat(result).isEqualTo(null);
assertThat(result).isNull();
}
protected final S create(R registry, HealthEndpointGroups groups) {

View File

@@ -65,8 +65,8 @@ class HealthTests {
assertThat(h1).isEqualTo(h1);
assertThat(h1).isEqualTo(h2);
assertThat(h1).isNotEqualTo(h3);
assertThat(h1.hashCode()).isEqualTo(h1.hashCode());
assertThat(h1.hashCode()).isEqualTo(h2.hashCode());
assertThat(h1).hasSameHashCodeAs(h1);
assertThat(h1).hasSameHashCodeAs(h2);
assertThat(h1.hashCode()).isNotEqualTo(h3.hashCode());
}

View File

@@ -59,7 +59,7 @@ class StatusTests {
Status two = new Status("spring", "framework");
Status three = new Status("spock", "framework");
assertThat(one).isEqualTo(one).isEqualTo(two).isNotEqualTo(three);
assertThat(one.hashCode()).isEqualTo(two.hashCode());
assertThat(one).hasSameHashCodeAs(two);
}
@Test

View File

@@ -47,7 +47,7 @@ class InfluxDbHealthIndicatorTests {
InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDb);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo("0.9");
assertThat(health.getDetails()).containsEntry("version", "0.9");
then(influxDb).should().ping();
}

View File

@@ -42,7 +42,7 @@ class EnvironmentInfoContributorTests {
Info actual = contributeFrom(this.environment);
assertThat(actual.get("app", String.class)).isEqualTo("my app");
assertThat(actual.get("version", String.class)).isEqualTo("1.0.0");
assertThat(actual.getDetails().size()).isEqualTo(2);
assertThat(actual.getDetails()).hasSize(2);
}
@Test

View File

@@ -64,7 +64,7 @@ class GitInfoContributorTests {
Map<String, Object> content = contributor.generateContent();
assertThat(content.get("commit")).isInstanceOf(Map.class);
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
assertThat(commit.get("id")).isEqualTo("8e29a0b");
assertThat(commit).containsEntry("id", "8e29a0b");
}
@Test
@@ -80,8 +80,8 @@ class GitInfoContributorTests {
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
assertThat(commit.get("id")).isInstanceOf(Map.class);
Map<String, Object> id = (Map<String, Object>) commit.get("id");
assertThat(id.get("full")).isEqualTo("1b3cec34f7ca0a021244452f2cae07a80497a7c7");
assertThat(id.get("abbrev")).isEqualTo("1b3cec3");
assertThat(id).containsEntry("full", "1b3cec34f7ca0a021244452f2cae07a80497a7c7");
assertThat(id).containsEntry("abbrev", "1b3cec3");
}
@Test

View File

@@ -105,7 +105,7 @@ class DataSourceHealthIndicatorTests {
given(dataSource.getConnection()).willReturn(connection);
this.indicator.setDataSource(dataSource);
Health health = this.indicator.health();
assertThat(health.getDetails().get("database")).isNotNull();
assertThat(health.getDetails()).containsKey("database");
then(connection).should(times(2)).close();
}

View File

@@ -52,7 +52,7 @@ class JmsHealthIndicatorTests {
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider");
assertThat(health.getDetails()).containsEntry("provider", "JMS test provider");
then(connection).should().close();
}
@@ -63,7 +63,7 @@ class JmsHealthIndicatorTests {
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("provider")).isNull();
assertThat(health.getDetails()).doesNotContainKey("provider");
}
@Test
@@ -77,7 +77,7 @@ class JmsHealthIndicatorTests {
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("provider")).isNull();
assertThat(health.getDetails()).doesNotContainKey("provider");
then(connection).should().close();
}
@@ -93,7 +93,7 @@ class JmsHealthIndicatorTests {
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
Health health = indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("provider")).isNull();
assertThat(health.getDetails()).doesNotContainKey("provider");
}
@Test

View File

@@ -45,7 +45,7 @@ class LdapHealthIndicatorTests {
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo("3");
assertThat(health.getDetails()).containsEntry("version", "3");
then(ldapTemplate).should().executeReadOnly((ContextExecutor<String>) any());
}

View File

@@ -66,7 +66,7 @@ class MailHealthIndicatorTests {
given(this.mailSender.getProtocol()).willReturn("success");
Health health = this.indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("location")).isEqualTo("smtp.acme.org:25");
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org:25");
}
@Test
@@ -74,10 +74,10 @@ class MailHealthIndicatorTests {
willThrow(new MessagingException("A test exception")).given(this.mailSender).testConnection();
Health health = this.indicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("location")).isEqualTo("smtp.acme.org:25");
assertThat(health.getDetails()).containsEntry("location", "smtp.acme.org:25");
Object errorMessage = health.getDetails().get("error");
assertThat(errorMessage).isNotNull();
assertThat(errorMessage.toString().contains("A test exception")).isTrue();
assertThat(errorMessage.toString()).contains("A test exception");
}
static class SuccessTransport extends Transport {

View File

@@ -36,7 +36,7 @@ class ThreadDumpEndpointTests {
@Test
void dumpThreads() {
assertThat(new ThreadDumpEndpoint().threadDump().getThreads().size()).isGreaterThan(0);
assertThat(new ThreadDumpEndpoint().threadDump().getThreads()).isNotEmpty();
}
@Test

View File

@@ -86,7 +86,7 @@ class MetricsRepositoryMethodInvocationListenerTests {
}
private void assertMetricsContainsTag(String tagKey, String tagValue) {
assertThat(this.registry.get(REQUEST_METRICS_NAME).tag(tagKey, tagValue).timer().count()).isEqualTo(1);
assertThat(this.registry.get(REQUEST_METRICS_NAME).tag(tagKey, tagValue).timer().count()).isOne();
}
private RepositoryMethodInvocation createInvocation(Class<?> repositoryInterface) {

View File

@@ -46,7 +46,7 @@ class MongoHealthIndicatorTests {
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("maxWireVersion")).isEqualTo(10);
assertThat(health.getDetails()).containsEntry("maxWireVersion", 10);
then(commandResult).should().getInteger("maxWireVersion");
then(mongoTemplate).should().executeCommand("{ isMaster: 1 }");
}

View File

@@ -50,7 +50,7 @@ class MongoReactiveHealthIndicatorTests {
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("maxWireVersion");
assertThat(h.getDetails().get("maxWireVersion")).isEqualTo(10);
assertThat(h.getDetails()).containsEntry("maxWireVersion", 10);
}).verifyComplete();
}
@@ -65,7 +65,7 @@ class MongoReactiveHealthIndicatorTests {
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
assertThat(h.getDetails()).containsOnlyKeys("error");
assertThat(h.getDetails().get("error")).isEqualTo(MongoException.class.getName() + ": Connection failed");
assertThat(h.getDetails()).containsEntry("error", MongoException.class.getName() + ": Connection failed");
}).verifyComplete();
}

View File

@@ -59,7 +59,7 @@ class RedisHealthIndicatorTests {
RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo("2.8.9");
assertThat(health.getDetails()).containsEntry("version", "2.8.9");
}
@Test
@@ -80,9 +80,9 @@ class RedisHealthIndicatorTests {
RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_up")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L);
assertThat(health.getDetails()).containsEntry("cluster_size", 4L);
assertThat(health.getDetails()).containsEntry("slots_up", 4L);
assertThat(health.getDetails()).containsEntry("slots_fail", 0L);
then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}
@@ -92,9 +92,9 @@ class RedisHealthIndicatorTests {
RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_up")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L);
assertThat(health.getDetails()).containsEntry("cluster_size", 4L);
assertThat(health.getDetails()).containsEntry("slots_up", 4L);
assertThat(health.getDetails()).containsEntry("slots_fail", 0L);
then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}
@@ -104,9 +104,9 @@ class RedisHealthIndicatorTests {
RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
assertThat(health.getDetails().get("slots_up")).isEqualTo(3L);
assertThat(health.getDetails().get("slots_fail")).isEqualTo(1L);
assertThat(health.getDetails()).containsEntry("cluster_size", 4L);
assertThat(health.getDetails()).containsEntry("slots_up", 3L);
assertThat(health.getDetails()).containsEntry("slots_fail", 1L);
then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}

View File

@@ -62,7 +62,7 @@ class RedisReactiveHealthIndicatorTests {
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("version");
assertThat(h.getDetails().get("version")).isEqualTo("2.8.9");
assertThat(h.getDetails()).containsEntry("version", "2.8.9");
}).verifyComplete();
then(redisConnection).should().closeLater();
}
@@ -74,9 +74,9 @@ class RedisReactiveHealthIndicatorTests {
Mono<Health> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails().get("cluster_size")).isEqualTo(4L);
assertThat(h.getDetails().get("slots_up")).isEqualTo(4L);
assertThat(h.getDetails().get("slots_fail")).isEqualTo(0L);
assertThat(h.getDetails()).containsEntry("cluster_size", 4L);
assertThat(h.getDetails()).containsEntry("slots_up", 4L);
assertThat(h.getDetails()).containsEntry("slots_fail", 0L);
}).verifyComplete();
then(redisConnectionFactory.getReactiveConnection()).should().closeLater();
}
@@ -88,9 +88,9 @@ class RedisReactiveHealthIndicatorTests {
Mono<Health> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails().get("cluster_size")).isEqualTo(4L);
assertThat(h.getDetails().get("slots_up")).isEqualTo(4L);
assertThat(h.getDetails().get("slots_fail")).isEqualTo(0L);
assertThat(h.getDetails()).containsEntry("cluster_size", 4L);
assertThat(h.getDetails()).containsEntry("slots_up", 4L);
assertThat(h.getDetails()).containsEntry("slots_fail", 0L);
}).verifyComplete();
}
@@ -101,8 +101,8 @@ class RedisReactiveHealthIndicatorTests {
Mono<Health> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
assertThat(h.getDetails().get("slots_up")).isEqualTo(3L);
assertThat(h.getDetails().get("slots_fail")).isEqualTo(1L);
assertThat(h.getDetails()).containsEntry("slots_up", 3L);
assertThat(h.getDetails()).containsEntry("slots_fail", 1L);
}).verifyComplete();
}

View File

@@ -93,7 +93,7 @@ class ScheduledTasksEndpointTests {
assertThat(tasks.getFixedDelay()).hasSize(1);
FixedDelayTaskDescriptor description = (FixedDelayTaskDescriptor) tasks.getFixedDelay().get(0);
assertThat(description.getInitialDelay()).isEqualTo(2);
assertThat(description.getInterval()).isEqualTo(1);
assertThat(description.getInterval()).isOne();
assertThat(description.getRunnable().getTarget())
.isEqualTo(FixedDelayScheduledMethod.class.getName() + ".fixedDelay");
});

View File

@@ -64,11 +64,11 @@ class DiskSpaceHealthIndicatorTests {
given(this.fileMock.getAbsolutePath()).willReturn("/absolute-path");
Health health = this.healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD.toBytes());
assertThat(health.getDetails().get("free")).isEqualTo(freeSpace);
assertThat(health.getDetails().get("total")).isEqualTo(TOTAL_SPACE.toBytes());
assertThat(health.getDetails().get("path")).isEqualTo("/absolute-path");
assertThat(health.getDetails().get("exists")).isEqualTo(true);
assertThat(health.getDetails()).containsEntry("threshold", THRESHOLD.toBytes());
assertThat(health.getDetails()).containsEntry("free", freeSpace);
assertThat(health.getDetails()).containsEntry("total", TOTAL_SPACE.toBytes());
assertThat(health.getDetails()).containsEntry("path", "/absolute-path");
assertThat(health.getDetails()).containsEntry("exists", true);
}
@Test
@@ -80,20 +80,20 @@ class DiskSpaceHealthIndicatorTests {
given(this.fileMock.getAbsolutePath()).willReturn("/absolute-path");
Health health = this.healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD.toBytes());
assertThat(health.getDetails().get("free")).isEqualTo(freeSpace);
assertThat(health.getDetails().get("total")).isEqualTo(TOTAL_SPACE.toBytes());
assertThat(health.getDetails().get("path")).isEqualTo("/absolute-path");
assertThat(health.getDetails().get("exists")).isEqualTo(true);
assertThat(health.getDetails()).containsEntry("threshold", THRESHOLD.toBytes());
assertThat(health.getDetails()).containsEntry("free", freeSpace);
assertThat(health.getDetails()).containsEntry("total", TOTAL_SPACE.toBytes());
assertThat(health.getDetails()).containsEntry("path", "/absolute-path");
assertThat(health.getDetails()).containsEntry("exists", true);
}
@Test
void whenPathDoesNotExistDiskSpaceIsDown() {
Health health = new DiskSpaceHealthIndicator(new File("does/not/exist"), THRESHOLD).health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("free")).isEqualTo(0L);
assertThat(health.getDetails().get("total")).isEqualTo(0L);
assertThat(health.getDetails().get("exists")).isEqualTo(false);
assertThat(health.getDetails()).containsEntry("free", 0L);
assertThat(health.getDetails()).containsEntry("total", 0L);
assertThat(health.getDetails()).containsEntry("exists", false);
}
}

View File

@@ -115,7 +115,7 @@ class HttpExchangesFilterTests {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setServerName("<script>alert(document.domain)</script>");
this.filter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
assertThat(this.repository.findAll()).hasSize(0);
assertThat(this.repository.findAll()).isEmpty();
}
}

View File

@@ -62,7 +62,7 @@ class RecordableServletHttpRequestTests {
private void validate(String expectedUri) {
RecordableServletHttpRequest sourceRequest = new RecordableServletHttpRequest(this.request);
assertThat(sourceRequest.getUri().toString()).isEqualTo(expectedUri);
assertThat(sourceRequest.getUri()).hasToString(expectedUri);
}
}