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