View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.http.mock;
6   
7   import java.io.ByteArrayInputStream;
8   import java.util.Collections;
9   import org.glassfish.grizzly.http.server.Request;
10  import org.hamcrest.MatcherAssert;
11  import org.hamcrest.Matchers;
12  import org.junit.jupiter.api.Test;
13  import org.mockito.Mockito;
14  
15  /**
16   * Test case for {@link GrizzlyQuery}.
17   * @since 1.13
18   */
19  final class GrizzlyQueryTest {
20  
21      /**
22       * GrizzlyQuery can return a body as a byte array.
23       * @throws Exception if something goes wrong.
24       */
25      @Test
26      void returnsBinaryBody() throws Exception {
27          final Request request = Mockito.mock(Request.class);
28          Mockito.when(request.getRequestURI()).thenReturn("http://fake.com");
29          Mockito.when(request.getHeaderNames()).thenReturn(
30              Collections.<String>emptyList()
31          );
32          final byte[] body = "body".getBytes();
33          Mockito.when(request.getInputStream()).thenReturn(
34              new ByteArrayInputStream(body)
35          );
36          MatcherAssert.assertThat(
37              "should match the body",
38              new GrizzlyQuery(request).binary(),
39              Matchers.is(body)
40          );
41      }
42  
43  }