Replace assertThat(x.isEmpty()).isTrue() with assertThat(x).isEmpty()

Search for   : assertThat\((.+).isEmpty\(\)\).isTrue\(\)
Replace with : assertThat($1).isEmpty()

Search for   : assertThat\((.+).isEmpty\(\)\).isFalse\(\)
Replace with : assertThat($1).isNotEmpty()

Closes gh-31758
This commit is contained in:
Yanming Zhou
2023-12-06 09:34:06 +08:00
committed by Brian Clozel
parent 7b16ef90f1
commit afcd03bddc
55 changed files with 135 additions and 134 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -35,7 +35,7 @@ public class HttpEntityTests {
String body = "foo";
HttpEntity<String> entity = new HttpEntity<>(body);
assertThat(entity.getBody()).isSameAs(body);
assertThat(entity.getHeaders().isEmpty()).isTrue();
assertThat(entity.getHeaders()).isEmpty();
}
@Test

View File

@@ -587,7 +587,7 @@ public class HttpHeadersTests {
// here to check the behavior of the entire contract.
// isEmpty() and size()
assertThat(keySet.isEmpty()).isFalse();
assertThat(keySet).isNotEmpty();
assertThat(keySet).hasSize(2);
// contains()
@@ -618,9 +618,9 @@ public class HttpHeadersTests {
// clear()
keySet.clear();
assertThat(keySet.isEmpty()).isTrue();
assertThat(keySet).isEmpty();
assertThat(headers.isEmpty()).isTrue();
assertThat(keySet).isEmpty();
assertThat(headers).isEmpty();
assertThat(headers).isEmpty();
// Unsupported operations
@@ -665,11 +665,11 @@ public class HttpHeadersTests {
String headerName = "MyHeader";
String headerValue = "value";
assertThat(headers.isEmpty()).isTrue();
assertThat(headers).isEmpty();
headers.add(headerName, headerValue);
assertThat(headers.containsKey(headerName)).isTrue();
headers.keySet().removeIf(key -> key.equals(headerName));
assertThat(headers.isEmpty()).isTrue();
assertThat(headers).isEmpty();
headers.add(headerName, headerValue);
assertThat(headers.get(headerName)).element(0).isEqualTo(headerValue);
}
@@ -679,11 +679,11 @@ public class HttpHeadersTests {
String headerName = "MyHeader";
String headerValue = "value";
assertThat(headers.isEmpty()).isTrue();
assertThat(headers).isEmpty();
headers.add(headerName, headerValue);
assertThat(headers.containsKey(headerName)).isTrue();
headers.entrySet().removeIf(entry -> entry.getKey().equals(headerName));
assertThat(headers.isEmpty()).isTrue();
assertThat(headers).isEmpty();
headers.add(headerName, headerValue);
assertThat(headers.get(headerName)).element(0).isEqualTo(headerValue);
}

View File

@@ -39,7 +39,7 @@ public class MediaTypeFactoryTests {
public void nullParameter() {
assertThat(MediaTypeFactory.getMediaType((String) null)).isNotPresent();
assertThat(MediaTypeFactory.getMediaType((Resource) null)).isNotPresent();
assertThat(MediaTypeFactory.getMediaTypes(null).isEmpty()).isTrue();
assertThat(MediaTypeFactory.getMediaTypes(null)).isEmpty();
}
}

View File

@@ -250,7 +250,7 @@ class ResponseEntityTests {
ResponseEntity.ok().headers((HttpHeaders) null).build();
assertThat(responseEntityWithEmptyHeaders.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntityWithEmptyHeaders.getHeaders().isEmpty()).isTrue();
assertThat(responseEntityWithEmptyHeaders.getHeaders()).isEmpty();
assertThat(responseEntityWithNullHeaders.toString()).isEqualTo(responseEntityWithEmptyHeaders.toString());
}

View File

@@ -112,7 +112,7 @@ class ServerHttpResponseTests {
assertThat(response.cookiesWritten).isFalse();
assertThat(headers).doesNotContainKeys(HttpHeaders.CONTENT_TYPE, HttpHeaders.CONTENT_LENGTH,
HttpHeaders.CONTENT_ENCODING);
assertThat(response.body.isEmpty()).isTrue();
assertThat(response.body).isEmpty();
}
@Test
@@ -123,7 +123,7 @@ class ServerHttpResponseTests {
assertThat(response.statusCodeWritten).isTrue();
assertThat(response.headersWritten).isTrue();
assertThat(response.cookiesWritten).isTrue();
assertThat(response.body.isEmpty()).isTrue();
assertThat(response.body).isEmpty();
}
@Test
@@ -157,7 +157,7 @@ class ServerHttpResponseTests {
assertThat(response.statusCodeWritten).isTrue();
assertThat(response.headersWritten).isTrue();
assertThat(response.cookiesWritten).isTrue();
assertThat(response.body.isEmpty()).isTrue();
assertThat(response.body).isEmpty();
assertThat(response.getCookies().getFirst("ID")).isSameAs(cookie);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -73,7 +73,7 @@ public class ModelAndViewContainerTests {
this.mavContainer.addAttribute("name", "value");
this.mavContainer.setRedirectModelScenario(true);
assertThat(this.mavContainer.getModel().isEmpty()).isTrue();
assertThat(this.mavContainer.getModel()).isEmpty();
}
@Test // SPR-14045

View File

@@ -112,7 +112,7 @@ public class ContentCachingRequestWrapperTests {
ContentCachingRequestWrapper wrapper = new ContentCachingRequestWrapper(request);
// getting request parameters will consume the request body
assertThat(wrapper.getParameterMap().isEmpty()).isFalse();
assertThat(wrapper.getParameterMap()).isNotEmpty();
assertThat(new String(wrapper.getContentAsByteArray())).isEqualTo("first=value&second=foo&second=bar");
// SPR-12810 : inputstream body should be consumed
assertThat(new String(wrapper.getInputStream().readAllBytes())).isEmpty();

View File

@@ -772,8 +772,8 @@ class UriComponentsBuilderTests {
UriComponents uri1 = UriComponentsBuilder.fromUriString("http://test.com").build().normalize();
UriComponents uri2 = UriComponentsBuilder.fromUriString("http://test.com/").build();
assertThat(uri1.getPathSegments().isEmpty()).isTrue();
assertThat(uri2.getPathSegments().isEmpty()).isTrue();
assertThat(uri1.getPathSegments()).isEmpty();
assertThat(uri2.getPathSegments()).isEmpty();
assertThat(uri2).isNotEqualTo(uri1);
}