Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaTypeAssert risk false negative with isNotEqual assertion #32756

Closed
simonbasle opened this issue May 3, 2024 · 2 comments
Closed

MediaTypeAssert risk false negative with isNotEqual assertion #32756

simonbasle opened this issue May 3, 2024 · 2 comments
Assignees
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@simonbasle
Copy link
Contributor

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)

@simonbasle simonbasle added in: test Issues in the test module type: bug A general bug labels May 3, 2024
@simonbasle simonbasle added this to the 6.2.0-M2 milestone May 3, 2024
@simonbasle simonbasle self-assigned this May 3, 2024
@simonbasle
Copy link
Contributor Author

simonbasle commented May 3, 2024

Note that this is also the case for ResponseBodyAssert#isEqualTo(String) but this is a bit different as the method is a shortcut for .asString().isEqualTo(String).

@simonbasle

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant