View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.http.response;
6   
7   import com.google.common.base.Joiner;
8   import com.jcabi.http.Response;
9   import com.jcabi.http.request.FakeRequest;
10  import com.jcabi.matchers.XhtmlMatchers;
11  import org.hamcrest.MatcherAssert;
12  import org.junit.jupiter.api.Test;
13  
14  /**
15   * Test case for {@link JsoupResponse}.
16   *
17   * @since 1.4
18   */
19  final class JsoupResponseTest {
20  
21      /**
22       * JsoupResponse normalizes malformed HTML responses.
23       * @throws Exception If a problem occurs.
24       */
25      @Test
26      void normalizesHtml() throws Exception {
27          final Response resp = new FakeRequest().withBody(
28              Joiner.on(' ').join(
29                  "<html xmlns='http://www.w3.org/1999/xhtml'>",
30                  "<head><meta name='test'></head>",
31                  "<p>Hello world"
32              )
33          ).fetch();
34          MatcherAssert.assertThat(
35              "should contains normalized response",
36              new JsoupResponse(resp).body(),
37              XhtmlMatchers.hasXPaths(
38                  "/xhtml:html/xhtml:head",
39                  "/xhtml:html/xhtml:body/xhtml:p[.=\"Hello world\"]"
40              )
41          );
42      }
43  
44  }