1. Project Clover database mer. févr. 4 2026 12:48:28 CET
  2. Package org.apache.maven.doxia.module.markdown

File MarkdownParserTest.java

 

Code metrics

0
28
8
1
111
74
13
0,46
3,5
8
1,62

Classes

Class Line # Actions
MarkdownParserTest 29 28 0% 13 6
0.833333383,3%
 

Contributing tests

This file is covered by 6 tests. .

Source view

1    /*
2    * Copyright 2012-2025 Christophe Friederich
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.apache.maven.doxia.module.markdown;
17   
18    import static org.junit.jupiter.api.Assertions.assertNotNull;
19   
20    import com.google.common.base.Throwables;
21    import java.io.Reader;
22    import java.io.StringReader;
23    import javax.inject.Inject;
24    import org.apache.maven.doxia.parser.AbstractParser;
25    import org.devacfr.testing.jupiter.ParserTestCase;
26    import org.jsoup.Jsoup;
27    import org.junit.jupiter.api.Test;
28   
 
29    public class MarkdownParserTest extends ParserTestCase {
30   
31    @Inject
32    private MarkdownParser parser;
33   
34    /**
35    * {@inheritDoc}
36    */
 
37  6 toggle @Override
38    protected AbstractParser createParser() {
39  6 return parser;
40    }
41   
42    /**
43    * {@inheritDoc}
44    */
 
45  6 toggle @Override
46    protected String outputExtension() {
47  6 return MarkdownParserModule.FILE_EXTENSION;
48    }
49   
 
50  2 toggle @Test
51    public void shouldParseToHtml() {
52  2 assertNotNull(parser);
53  2 verify(content -> {
54  2 try {
55  2 final String html = parseFileToHtml(content);
56  2 return Jsoup.parse(html).html();
57    } catch (final Exception e) {
58  0 Throwables.throwIfUnchecked(e);
59  0 throw new RuntimeException(e);
60    }
61    }, "md", "html");
62    }
63   
 
64  2 toggle @Test
65    public void shouldParseSnippetToHtml() {
66  2 assertNotNull(parser);
67  2 verify(content -> {
68  2 try {
69  2 final String html = parseFileToHtml(content);
70  2 return Jsoup.parse(html).html();
71    } catch (final Exception e) {
72  0 Throwables.throwIfUnchecked(e);
73  0 throw new RuntimeException(e);
74    }
75    }, "md", "html");
76    }
77   
 
78  2 toggle @Test
79    public void test() {
80  2 assertNotNull(parser);
81  2 verify(content -> {
82  2 try {
83  2 final String html = parseFileToHtml(content);
84  2 return Jsoup.parse(html).html();
85    } catch (final Exception e) {
86  0 Throwables.throwIfUnchecked(e);
87  0 throw new RuntimeException(e);
88    }
89    }, "md", "html");
90    }
91   
 
92  6 toggle protected String parseFileToHtml(final String content) throws Exception {
93  6 try (Reader reader = new StringReader(content)) {
94  6 return parser.toHtml(reader).toString();
95    }
96    }
97   
 
98  2 toggle @Override
99    protected String getVerbatimSource() {
100    /**
101    * Markdown doesn't support verbatim text which is not code: https://spec.commonmark.org/0.31.2/#fenced-code-blocks
102    * and https://spec.commonmark.org/0.31.2/#indented-code-blocks
103    */
104  2 return null;
105    }
106   
 
107  2 toggle @Override
108    protected String getVerbatimCodeSource() {
109  2 return null;
110    }
111    }