| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.devacfr.maven.skins.reflow.context; |
| 20 |
|
|
| 21 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
| 22 |
|
import static org.hamcrest.Matchers.isA; |
| 23 |
|
|
| 24 |
|
import java.io.StringReader; |
| 25 |
|
|
| 26 |
|
import org.apache.maven.doxia.site.SiteModel; |
| 27 |
|
import org.apache.maven.project.MavenProject; |
| 28 |
|
import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 29 |
|
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; |
| 30 |
|
import org.devacfr.maven.skins.reflow.ISkinConfig; |
| 31 |
|
import org.devacfr.maven.skins.reflow.model.Footer; |
| 32 |
|
import org.devacfr.maven.skins.reflow.model.Navbar; |
| 33 |
|
import org.devacfr.maven.skins.reflow.model.ScrollTop; |
| 34 |
|
import org.devacfr.maven.skins.reflow.model.Toc; |
| 35 |
|
import org.devacfr.maven.skins.reflow.model.TocSidebar; |
| 36 |
|
import org.devacfr.testing.jupiter.MockitoTestCase; |
| 37 |
|
import org.junit.jupiter.api.BeforeEach; |
| 38 |
|
import org.junit.jupiter.api.Test; |
| 39 |
|
import org.mockito.Mock; |
| 40 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 2 |
Complexity Density: 0,05 |
|
| 41 |
|
public class FrameContextTest extends MockitoTestCase { |
| 42 |
|
|
| 43 |
|
@Mock |
| 44 |
|
private ISkinConfig config; |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
|
| 46 |
1 |
@SuppressWarnings("unchecked")... |
| 47 |
|
@BeforeEach |
| 48 |
|
public void setup() { |
| 49 |
1 |
final MavenProject project = new MavenProject(); |
| 50 |
1 |
project.setName("reflow"); |
| 51 |
1 |
project.setArtifactId("reflow-artifact"); |
| 52 |
1 |
when(config.getProject()).thenReturn(project); |
| 53 |
|
|
| 54 |
1 |
final SiteModel model = new SiteModel(); |
| 55 |
1 |
when(config.getSiteModel()).thenReturn(model); |
| 56 |
1 |
when(config.getAttributeValue(any(String.class), any(String.class), any(Class.class), any(Object.class))) |
| 57 |
|
.then(invocation -> invocation.getArguments()[3]); |
| 58 |
1 |
when(config.getPropertyValue(any(String.class), any(Class.class), any(Object.class))) |
| 59 |
|
.then(invocation -> invocation.getArguments()[2]); |
| 60 |
|
} |
| 61 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 1 |
Complexity Density: 0,03 |
1PASS
|
|
| 62 |
1 |
@Test... |
| 63 |
|
public void shouldBuildFrameContext() throws Exception { |
| 64 |
1 |
final String xml = "<reflowSkin><pages>" + |
| 65 |
|
"<development-documentation type=\"doc\">" + |
| 66 |
|
" <menu name=\"Development Documentation\">" + |
| 67 |
|
" <item name=\"Contribute\" href=\"dev/contribute.html\" />" + |
| 68 |
|
" <item name=\"Code Conventions\" href=\"dev/code-conventions.html\"/>" + |
| 69 |
|
" <item name=\"Release Management\" href=\"dev/release-management.html\"/>" + |
| 70 |
|
" </menu>" + |
| 71 |
|
" </development-documentation>" + |
| 72 |
|
"</pages></reflowSkin>"; |
| 73 |
1 |
final Xpp3Dom globalProperties = Xpp3DomBuilder.build(new StringReader(xml)); |
| 74 |
1 |
when(config.getPageProperties()).thenReturn(new Xpp3Dom("dev-contribute")); |
| 75 |
1 |
when(config.getGlobalProperties()).thenReturn(globalProperties); |
| 76 |
1 |
when(config.getFileId()).thenReturn("dev-contribute"); |
| 77 |
1 |
when(config.getNamespace()).thenReturn(""); |
| 78 |
|
|
| 79 |
1 |
final Context<?> context = Context.buildContext(config); |
| 80 |
1 |
assertThat((FrameContext) context, isA(FrameContext.class)); |
| 81 |
1 |
final FrameContext frameContext = (FrameContext) context; |
| 82 |
|
|
| 83 |
1 |
assertEquals("development-documentation", frameContext.getDocumentParent()); |
| 84 |
|
|
| 85 |
1 |
final Toc<?> toc = frameContext.getToc(); |
| 86 |
1 |
assertNotNull(toc, "toc should be exist"); |
| 87 |
1 |
assertThat((TocSidebar) frameContext.getToc(), isA(TocSidebar.class)); |
| 88 |
|
|
| 89 |
1 |
final TocSidebar tocSidebar = (TocSidebar) toc; |
| 90 |
1 |
assertEquals(Integer.MAX_VALUE, tocSidebar.getLevel()); |
| 91 |
1 |
assertEquals("sidebar-light bg-light", tocSidebar.getCssClass()); |
| 92 |
1 |
assertEquals("m-toc-sidebar-enabled m-toc-sidebar-expanded m-toc-sidebar-autoexpandable toc-sidebar-fixed", |
| 93 |
|
tocSidebar.getCssOptions()); |
| 94 |
|
|
| 95 |
1 |
final Footer footer = frameContext.getFooter(); |
| 96 |
1 |
assertNotNull(footer, "footer should be exist"); |
| 97 |
1 |
assertEquals("footer-light bg-light", footer.getCssClass()); |
| 98 |
1 |
assertEquals("", footer.getCssOptions()); |
| 99 |
|
|
| 100 |
1 |
final Navbar navbar = frameContext.getNavbar(); |
| 101 |
1 |
assertNotNull(navbar, "Navbar should be exist"); |
| 102 |
1 |
assertEquals("navbar-light bg-light", navbar.getCssClass()); |
| 103 |
1 |
assertEquals("", navbar.getCssOptions()); |
| 104 |
|
|
| 105 |
1 |
final ScrollTop scrollTop = frameContext.getScrollTop(); |
| 106 |
1 |
assertNotNull(scrollTop, "ScrollTop should be exist"); |
| 107 |
1 |
assertEquals("", scrollTop.getCssClass()); |
| 108 |
1 |
assertEquals(true, scrollTop.isSmooth()); |
| 109 |
1 |
assertEquals("scrolltop-smooth-enabled", scrollTop.getCssOptions()); |
| 110 |
|
} |
| 111 |
|
} |