1. Project Clover database mar. avr. 16 2024 08:19:06 CEST
  2. Package org.apache.maven.doxia.module.markdown

File MarkdownParserTest.java

 

Code metrics

0
19
5
1
91
53
9
0,47
3,8
5
1,8

Classes

Class Line # Actions
MarkdownParserTest 34 19 0% 9 4
0.833333383,3%
 

Contributing tests

This file is covered by 2 tests. .

Source view

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.doxia.module.markdown;
20   
21    import javax.inject.Inject;
22   
23    import java.io.Reader;
24    import java.io.StringReader;
25   
26    import com.google.common.base.Throwables;
27    import org.apache.maven.doxia.parser.Parser;
28    import org.devacfr.testing.jupiter.ParserTestCase;
29    import org.jsoup.Jsoup;
30    import org.junit.jupiter.api.Test;
31   
32    import static org.junit.jupiter.api.Assertions.assertNotNull;
33   
 
34    public class MarkdownParserTest extends ParserTestCase {
35   
36    @Inject
37    private MarkdownParser parser;
38   
39    /**
40    * {@inheritDoc}
41    */
 
42  2 toggle @Override
43    protected Parser createParser() {
44  2 return parser;
45    }
46   
47    /**
48    * {@inheritDoc}
49    */
 
50  2 toggle @Override
51    protected String outputExtension() {
52  2 return MarkdownParserModule.FILE_EXTENSION;
53    }
54   
 
55  1 toggle @Test
56    public void shouldParseToHtml() {
57  1 assertNotNull(parser);
58  1 verify(content -> {
59  1 try {
60  1 final String html = parseFileToHtml(content);
61  1 return Jsoup.parse(html).html();
62    } catch (final Exception e) {
63  0 Throwables.throwIfUnchecked(e);
64  0 throw new RuntimeException(e);
65    }
66    }, "md");
67    }
68   
 
69  1 toggle @Test
70    public void shouldParseSnippetToHtml() {
71  1 assertNotNull(parser);
72  1 verify(content -> {
73  1 try {
74  1 final String html = parseFileToHtml(content);
75  1 return Jsoup.parse(html).html();
76    } catch (final Exception e) {
77  0 Throwables.throwIfUnchecked(e);
78  0 throw new RuntimeException(e);
79    }
80    }, "md");
81    }
82   
 
83  2 toggle protected String parseFileToHtml(final String content) throws Exception {
84  2 try (Reader reader = new StringReader(content)) {
85    // final Method toHtml = parser.getClass().getDeclaredMethod("toHtml", Reader.class);
86    // toHtml.setAccessible(true);
87    // return (String) toHtml.invoke(parser, reader);
88  2 return parser.toHtml(reader).toString();
89    }
90    }
91    }