1. Project Clover database mar. janv. 20 2026 12:32:22 CET
  2. Package org.devacfr.maven.skins.reflow.snippet

File ComponentResolverTest.java

 

Code metrics

0
18
14
1
103
71
14
0,78
1,29
14
1

Classes

Class Line # Actions
ComponentResolverTest 25 18 0% 14 0
1.0100%
 

Contributing tests

This file is covered by 13 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.devacfr.maven.skins.reflow.snippet;
17   
18    import org.devacfr.maven.skins.reflow.snippet.ComponentToken.Tag;
19    import org.devacfr.testing.jupiter.MockitoTestCase;
20    import org.jsoup.nodes.Element;
21    import org.junit.jupiter.api.Assertions;
22    import org.junit.jupiter.api.Test;
23    import org.mockito.Mock;
24   
 
25    public class ComponentResolverTest extends MockitoTestCase {
26   
27    @Mock
28    private SnippetContext context;
29   
 
30  1 toggle @Test
31    public void shouldBeStartWebComponent() {
32  1 check("{{% component %}}", "component", Tag.start);
33    }
34   
 
35  1 toggle @Test
36    public void shouldBeStartWebComponentWithAttributes() {
37  1 check("{{% component style=\"width: 18rem;\" attr2=\"val\" %}}", "component", Tag.start);
38    }
39   
 
40  1 toggle @Test
41    public void shouldBeStartWebComponentWithAttributesLeftAndRightDoubleQuote() {
42  1 check("{{% component style=“width: 18rem;” attr2=“val” %}}", "component", Tag.start);
43    }
44   
 
45  1 toggle @Test
46    public void shouldBeStartWebComponentWithAttributeWithoutValue() {
47  1 check("{{% component pill %}}", "component", Tag.start);
48    }
49   
 
50  1 toggle @Test
51    public void shouldBeStartWebComponentWithNumberAttributes() {
52  1 check("{{% component length=\"120\" %}}", "component", Tag.start);
53    }
54   
 
55  1 toggle @Test
56    public void shouldBeEndWebComponent() {
57  1 check("{{% /component %}}", "component", Tag.end);
58    }
59   
 
60  1 toggle @Test
61    public void shouldBeEmptyWebComponent() {
62  1 check("{{% component /%}}", "component", Tag.empty);
63    }
64   
 
65  1 toggle @Test
66    public void shouldBeStartShortcode() {
67  1 check("{{< component >}}", "component", Tag.start);
68    }
69   
 
70  1 toggle @Test
71    public void shouldBeEndShortcode() {
72  1 check("{{< /component >}}", "component", Tag.end);
73    }
74   
 
75  1 toggle @Test
76    public void shouldBeEmptyShortcode() {
77  1 check("{{< component />}}", "component", Tag.empty);
78    }
79   
 
80  1 toggle @Test
81    public void shouldFailedOnMalformed() {
82  1 Assertions.assertThrows(RuntimeException.class, () -> {
83  1 new ComponentResolver().create(new Element("p").text("{{% /component /%}}"));
84    });
85    }
86   
 
87  1 toggle @Test
88    public void shouldFailedUnknownComponent() {
89  1 assertNull(new ComponentResolver().create(new Element("p").text("{{- /component -}}")));
90    }
91   
 
92  1 toggle @Test
93    public void shouldElementStartWebComponentContainingAttributes() {
94  1 check("{{% component attr=\"value\" attr1=\"value1\" %}}", "component", Tag.start);
95    }
96   
 
97  11 toggle private ComponentToken check(final String text, final String name, final Tag state) {
98  11 final ComponentToken element = new ComponentResolver().create(new Element("p").text(text));
99  11 assertEquals(name, element.name());
100  11 assertEquals(state, element.tag());
101  11 return element;
102    }
103    }