View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.tools.plugin.generator;
20  
21  import org.junit.jupiter.api.Test;
22  
23  import static org.junit.jupiter.api.Assertions.assertEquals;
24  import static org.junit.jupiter.api.Assertions.assertNull;
25  
26  class HtmlToPlainTextConverterTest {
27      private final Converter converter;
28  
29      public HtmlToPlainTextConverterTest() {
30          converter = new HtmlToPlainTextConverter();
31      }
32  
33      @Test
34      void testConvertWithCodeAndLink() {
35          String test =
36                  "This is a <code>code</code> and <a href=\"https://javadoc.example.com/some/javadoc.html\">Link</a>";
37          assertEquals(
38                  "This is a code and Link <https://javadoc.example.com/some/javadoc.html>", converter.convert(test));
39      }
40  
41      @Test
42      void testMultilineJavadocAndWordWrap() {
43          String test =
44                  "Generates a <a href=\"https://jackrabbit.apache.org/jcr/node-type-notation.html\">CND file</a> containing all\n"
45                          + "used node types and namespaces. It uses the <a href=\"https://s.apache.org/jcr-2.0-spec/3_Repository_Model.html#3.7.11%20Standard%20Application%20Node%20Types\">default namespaces and node types</a>\n"
46                          + "and in addition some provided ones as source node type and namespace registry.";
47          assertEquals(
48                  "Generates a CND file <https://jackrabbit.apache.org/jcr/node-type-notation.html> "
49                          + "containing all used node types and namespaces. It uses the default namespaces"
50                          + " and node types <https://s.apache.org/jcr-2.0-spec/3_Repository_Model.html#3.7.11%20Standard%20Application%20Node%20Types>"
51                          + " and in addition some provided ones as source node type and namespace registry.",
52                  converter.convert(test));
53      }
54  
55      @Test
56      void testRelativeUrl() {
57          String test = "<a href=\"#field\">field</a>";
58          assertEquals("field", converter.convert(test));
59      }
60  
61      @Test
62      void testNullValue() {
63          assertNull(converter.convert(null));
64      }
65  
66      @Test
67      void testExplicitNewline() {
68          String test =
69                  "Some \"quotation\" marks and backslashes '\\\\', some <strong>important</strong> javadoc<br> and an\n"
70                          + "inline link to foo";
71          assertEquals(
72                  "Some \"quotation\" marks and backslashes '\\\\', some important javadoc\n"
73                          + "and an inline link to foo",
74                  converter.convert(test));
75      }
76  }