1. Project Clover database mer. févr. 4 2026 12:48:28 CET
  2. Package org.devacfr.maven.skins.reflow.snippet

File BaseSnippetTest.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
38
2
1
96
72
2
0,05
19
2
1

Classes

Class Line # Actions
BaseSnippetTest 33 38 0% 2 2
0.9595%
 

Contributing tests

This file is covered by 34 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 java.sql.Date;
19    import org.apache.maven.doxia.site.Body;
20    import org.apache.maven.doxia.site.LinkItem;
21    import org.apache.maven.doxia.site.PublishDate;
22    import org.apache.maven.doxia.site.SiteModel;
23    import org.apache.maven.doxia.site.Version;
24    import org.apache.maven.project.MavenProject;
25    import org.apache.velocity.tools.ToolContext;
26    import org.devacfr.maven.skins.reflow.ISkinConfig;
27    import org.devacfr.maven.skins.reflow.context.PageContext;
28    import org.devacfr.maven.skins.reflow.context.PositionType;
29    import org.devacfr.testing.jupiter.MockitoTestCase;
30    import org.junit.jupiter.api.BeforeEach;
31    import org.mockito.Mock;
32   
 
33    public abstract class BaseSnippetTest extends MockitoTestCase {
34   
35    @Mock(lenient = true)
36    protected ISkinConfig config;
37   
38    protected ToolContext velocityContext;
39   
40    protected SiteModel siteModel;
41   
42    protected PageContext context;
43   
44    @Mock(lenient = true)
45    protected MavenProject mavenProject;
46   
 
47  16 toggle @SuppressWarnings("unchecked")
48    @BeforeEach
49    public void setup() throws Exception {
50  16 velocityContext = SnippetContext.createToolManaged().createContext();
51  16 siteModel = new SiteModel();
52  16 when(config.getSiteModel()).thenReturn(siteModel);
53  16 when(config.getProject()).thenReturn(mavenProject);
54  16 when(config.getVelocityContext()).thenReturn(velocityContext);
55  16 when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any())).then((a) -> {
56  224 Object[] args = a.getArguments();
57  224 return args[3];
58    });
59  16 when(config.getPropertyValue(any(String.class), any(Class.class), any())).then((a) -> {
60  32 Object[] args = a.getArguments();
61  32 return args[2];
62    });
63  16 when(config.relativeLink(any())).then((a) -> {
64  24 Object[] args = a.getArguments();
65  24 return args[0];
66    });
67  16 context = new PageContext(config);
68  16 when(config.getContext()).thenReturn(context);
69  16 when(config.getToolbox(any(), any())).then((a) -> {
70  0 Object[] args = a.getArguments();
71  0 return velocityContext.getToolbox().get(args[0]);
72    });
73  16 when(config.not("breadcrumbs")).thenReturn(false);
74  16 PublishDate publishDate = new PublishDate();
75  16 publishDate.setPosition(PositionType.none.toString());
76  16 siteModel.setPublishDate(publishDate);
77  16 when(config.getVersion()).thenReturn("1.0.0");
78  16 when(config.getVersionMessage()).thenReturn("Version: 1.0.0");
79  16 when(config.getBuildOutputTimestamp()).thenReturn(Date.valueOf("2025-11-16"));
80  16 when(config.getPublishDateMessage()).thenReturn("Last Published: 2025-11-16");
81  16 when(config.getShortTitle()).thenReturn("Documentation");
82  16 Body body = new Body();
83  16 Version version = new Version();
84  16 version.setPosition(PositionType.none.toString());
85  16 siteModel.setVersion(version);
86  16 LinkItem linkItem = new LinkItem();
87  16 linkItem.setName("Reflow");
88  16 linkItem.setHref("../..");
89  16 body.addBreadcrumb(linkItem);
90  16 siteModel.setBody(body);
91    }
92   
 
93  34 toggle protected SnippetParser createParser() {
94  34 return new SnippetParser().insertResourcePath(0, getPackagePath().toString());
95    }
96    }