-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed
Labels
Milestone
Description
In MediaTypeAssert, we have both isEqualTo(Object) and isEqualTo(String), but only isNotEqualTo(Object).
The later is inherited from AbstractAssert.
As a String is never equal to a MediaType, the following test appears to pass but it does for the wrong reasons (false negative):
@Test
void isNotEqualWhenDifferentShouldPass() {
assertThat(mediaType("application/json")).isNotEqualTo(MediaType.TEXT_HTML_VALUE);
}To make the issue more evident, one can try the following test instead, which doesn't pass with the current implementation:
@Test
void isNotEqualWhenSameShouldFail() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> assertThat(mediaType("application/json")).isNotEqualTo(MediaType.APPLICATION_JSON_VALUE))
.withMessageContaining("Media type");
}(note that isNotEqual isn't currently tested in MediaTypeAssertTests, such tests should be added as part of fixing this issue)