Skip to content

Commit

Permalink
Add unit tests for content type with charset
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed Mar 11, 2022
1 parent 60621d8 commit d234cb9
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.AbstractMap;
import java.util.Set;

@QuarkusTest
class OpenApiUtilsTest {

Expand Down Expand Up @@ -39,4 +42,26 @@ void shouldReturnDefaultContentType() {
MediaType result = OpenApiUtils.getMediaTypeFromContent(content, "non-app/json");
Assertions.assertThat(result).isNull();
}

@Test
void shouldReturnContentTypeWhenContainingCharset() {
Content content = Mockito.mock(Content.class);
MediaType mediaType = Mockito.mock(MediaType.class);
MediaType mediaTypeCharset = Mockito.mock(MediaType.class);

Mockito.when(content.get("app/json")).thenReturn(mediaType);
Mockito.when(content.entrySet()).thenReturn(Set.of(new AbstractMap.SimpleEntry<>("app/json2", mediaTypeCharset)));
MediaType actual = OpenApiUtils.getMediaTypeFromContent(content, "app/json2");
Assertions.assertThat(actual).isSameAs(mediaTypeCharset).isNotSameAs(mediaType);
}

@Test
void shouldReturnTrueWhenContentTypeWithCharset() {
Content content = Mockito.mock(Content.class);
MediaType mediaType = Mockito.mock(MediaType.class);
Mockito.when(content.keySet()).thenReturn(Set.of("application/json;charset=UTF-8"));

boolean actual = OpenApiUtils.hasContentType(content, "application/json");
Assertions.assertThat(actual).isTrue();
}
}

0 comments on commit d234cb9

Please sign in to comment.