1. Project Clover database Fri Jul 3 2015 14:17:25 CEST
  2. Package info.magnolia.module.blossom.template

File TemplateDefinitionBuilderAvailableTest.java

 

Code metrics

0
29
13
8
176
100
13
0.45
2.23
1.62
1

Classes

Class Line # Actions
TemplateDefinitionBuilderAvailableTest 51 22 0% 6 0
1.0100%
TemplateDefinitionBuilderAvailableTest.TestTemplate 54 1 0% 1 2
0.00%
TemplateDefinitionBuilderAvailableTest.BaseTemplate 62 1 0% 1 2
0.00%
TemplateDefinitionBuilderAvailableTest.InheritsAndOverrides 71 1 0% 1 2
0.00%
TemplateDefinitionBuilderAvailableTest.InheritsAndReuses 80 0 - 0 0
-1.0 -
TemplateDefinitionBuilderAvailableTest.InheritsAndOverridesWithAnnotation 84 1 0% 1 0
1.0100%
TemplateDefinitionBuilderAvailableTest.InheritsWithAnnotation 94 1 0% 1 0
1.0100%
TemplateDefinitionBuilderAvailableTest.TemplateWithMultipleAvailableMethods 158 2 0% 2 4
0.00%
 

Contributing tests

This file is covered by 6 tests. .

Source view

1    /**
2    * This file Copyright (c) 2010-2015 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.module.blossom.template;
35   
36    import static org.junit.Assert.assertEquals;
37    import static org.junit.Assert.assertFalse;
38    import static org.junit.Assert.assertNotNull;
39   
40    import info.magnolia.module.blossom.annotation.Available;
41    import info.magnolia.module.blossom.annotation.Template;
42    import info.magnolia.test.mock.jcr.MockNode;
43   
44    import javax.jcr.Node;
45   
46    import org.junit.Test;
47   
48    /**
49    * @since 1.1
50    */
 
51    public class TemplateDefinitionBuilderAvailableTest {
52   
53    @Template(title = "Text", id = "base")
 
54    public static class TestTemplate {
55   
 
56  0 toggle @Available
57    public boolean isAvailable(Node node) {
58  0 return true;
59    }
60    }
61   
 
62    public static class BaseTemplate {
63   
 
64  0 toggle @Available
65    public boolean isAvailable(Node node) {
66  0 return true;
67    }
68    }
69   
70    @Template(title = "Overrides", id = "overrides")
 
71    public static class InheritsAndOverrides extends BaseTemplate {
72   
 
73  0 toggle @Override
74    public boolean isAvailable(Node node) {
75  0 return false;
76    }
77    }
78   
79    @Template(title = "Inherits", id = "inherits")
 
80    public static class InheritsAndReuses extends BaseTemplate {
81    }
82   
83    @Template(title = "InheritsAndOverridesWithAnnotation", id = "InheritsAndOverridesWithAnnotation")
 
84    public static class InheritsAndOverridesWithAnnotation extends BaseTemplate {
85   
 
86  1 toggle @Override
87    @Available
88    public boolean isAvailable(Node node) {
89  1 return false;
90    }
91    }
92   
93    @Template(title = "InheritsWithAnnotation", id = "InheritsWithAnnotation")
 
94    public static class InheritsWithAnnotation extends BaseTemplate {
95   
 
96  1 toggle @Available
97    public boolean available(Node node) {
98  1 return false;
99    }
100    }
101   
 
102  1 toggle @Test
103    public void testTemplateAvailability() throws Exception {
104   
105  1 TestTemplate template = new TestTemplate();
106   
107  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(template);
108   
109  1 assertNotNull(description.getTemplateAvailability());
110    }
111   
 
112  1 toggle @Test
113    public void testAvailableOverriding() throws Exception {
114  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsAndOverrides());
115   
116  1 assertEquals("Overrides", description.getTitle());
117  1 assertEquals("overrides", description.getId());
118   
119  1 assertFalse("info.magnolia.module.blossom.template.TemplateDefinitionBuilder.DefaultTemplateAvailability".equals(description.getTemplateAvailability().getClass().getName()));
120    }
121   
 
122  1 toggle @Test
123    public void testAvailableInheritance() throws Exception {
124   
125  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsAndReuses());
126   
127  1 assertEquals("Inherits", description.getTitle());
128  1 assertEquals("inherits", description.getId());
129   
130  1 assertNotNull(description.getTemplateAvailability());
131    }
132   
 
133  1 toggle @Test
134    public void testAvailableOverridingWithAnnotation() throws Exception {
135   
136  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsAndOverridesWithAnnotation());
137   
138  1 assertEquals("InheritsAndOverridesWithAnnotation", description.getTitle());
139  1 assertEquals("InheritsAndOverridesWithAnnotation", description.getId());
140   
141  1 assertNotNull(description.getTemplateAvailability());
142  1 assertFalse(description.getTemplateAvailability().isAvailable(new MockNode("mock"), description));
143    }
144   
 
145  1 toggle @Test
146    public void testAvailableInheritsAndOverridesWithAnnotation() throws Exception {
147   
148  1 BlossomTemplateDefinition description = TemplateDefinitionBuilderTest.buildTemplateDefinition(new InheritsWithAnnotation());
149   
150  1 assertEquals("InheritsWithAnnotation", description.getTitle());
151  1 assertEquals("InheritsWithAnnotation", description.getId());
152   
153  1 assertNotNull(description.getTemplateAvailability());
154  1 assertFalse(description.getTemplateAvailability().isAvailable(new MockNode("mock"), description));
155    }
156   
157    @Template(title = "Too many available methods", id = "notUsed")
 
158    public static class TemplateWithMultipleAvailableMethods {
159   
 
160  0 toggle @Available
161    public boolean available1(Node content) {
162  0 return true;
163    }
164   
 
165  0 toggle @Available
166    public boolean available2(Node content) {
167  0 return false;
168    }
169    }
170   
 
171  1 toggle @Test(expected = IllegalStateException.class)
172    public void testAvailableMultiple() {
173  1 TemplateDefinitionBuilderTest.buildTemplateDefinition(new TemplateWithMultipleAvailableMethods());
174    }
175   
176    }