Remove inefficiency in HttpStatus.series()

Prior to this commit, the Series value for an HttpStatus was always
evaluated which resulted in an allocation of a Series array by invoking
Series.values() which makes a defensive copy.

This commit addresses this issue by hardcoding the corresponding Series
within the HttpStatus constructor, thereby avoiding any unnecessary
computations. In addition, a unit test has been added to verify that
all HttpStatus enum constants have a properly configured Series.

Closes gh-22366
This commit is contained in:
Nico Heller
2019-02-06 21:05:56 +01:00
committed by Sam Brannen
parent b34778d220
commit 97cc89630d
2 changed files with 81 additions and 72 deletions

View File

@@ -128,4 +128,12 @@ public class HttpStatusTests {
}
}
@Test
public void allStatusSeriesShouldMatchExpectations() {
// a series of a status is manually set, make sure it is the correct one
for (HttpStatus status : HttpStatus.values()) {
HttpStatus.Series expectedSeries = HttpStatus.Series.valueOf(status.value());
assertThat(expectedSeries).isEqualTo(status.series());
}
}
}