Clover Coverage Report - magnolia-module-templating 4.4.5
Coverage timestamp: Mon Sep 12 2011 16:32:30 CEST
26   127   14   2.17
0   72   0.54   3
12     1.17  
4    
 
  AbstractRenderableTest       Line # 45 18 0% 4 2 90% 0.9
  AbstractRenderableTest.NoConstructorModel       Line # 82 4 0% 4 8 0% 0.0
  AbstractRenderableTest.WrongConstructorModel       Line # 100 0 0% 1 1 0% 0.0
  AbstractRenderableTest.StandardConstructorModel       Line # 106 4 0% 5 8 11.1% 0.11111111
 
  (2)
 
1    /**
2    * This file Copyright (c) 2010-2011 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.templating;
35   
36    import info.magnolia.cms.core.Content;
37    import info.magnolia.test.mock.MockContent;
38    import junit.framework.TestCase;
39   
40    /**
41    *
42    * @author gjoseph
43    * @version $Revision: $ ($Author: $)
44    */
 
45    public class AbstractRenderableTest extends TestCase {
46    private MockContent dummyContent = new MockContent("");
47    private Paragraph dummyDef = new Paragraph();
48    private final RenderingModelImpl dummyParentModel = new RenderingModelImpl(null, null, null);
49   
 
50  1 toggle public void testCanInstantiateModel() throws Exception {
51  1 final AbstractRenderable renderable = new AbstractRenderable() {
52    };
53  1 renderable.setModelClass(StandardConstructorModel.class);
54  1 final RenderingModel m = renderable.newModel(dummyContent, dummyDef, dummyParentModel);
55  1 assertNotNull(m);
56  1 assertTrue(m instanceof StandardConstructorModel);
57    }
58   
 
59  1 toggle public void testModelNeedSpecificConstructor() {
60  1 final AbstractRenderable renderable = new AbstractRenderable() {
61    };
62  1 renderable.setModelClass(NoConstructorModel.class);
63  1 try {
64  1 final RenderingModel m = renderable.newModel(dummyContent, dummyDef, dummyParentModel);
65  0 fail("should have failed");
66    } catch (Exception e) {
67  1 assertEquals("A model class must define a constructor with types {interface info.magnolia.cms.core.Content,interface info.magnolia.module.templating.RenderableDefinition,interface info.magnolia.module.templating.RenderingModel}. Can't instantiate class info.magnolia.module.templating.AbstractRenderableTest$NoConstructorModel", e.getMessage());
68  1 assertTrue(e instanceof IllegalArgumentException);
69    }
70   
71  1 renderable.setModelClass(WrongConstructorModel.class);
72  1 try {
73  1 final RenderingModel m = renderable.newModel(dummyContent, dummyDef, dummyParentModel);
74  0 fail("should have failed");
75    } catch (Exception e) {
76  1 assertEquals("A model class must define a constructor with types {interface info.magnolia.cms.core.Content,interface info.magnolia.module.templating.RenderableDefinition,interface info.magnolia.module.templating.RenderingModel}. " +
77    "Can't instantiate class info.magnolia.module.templating.AbstractRenderableTest$WrongConstructorModel", e.getMessage());
78  1 assertTrue(e instanceof IllegalArgumentException);
79    }
80    }
81   
 
82    public static class NoConstructorModel implements RenderingModel {
 
83  0 toggle public RenderingModel getParent() {
84  0 return null;
85    }
86   
 
87  0 toggle public Content getContent() {
88  0 return null;
89    }
90   
 
91  0 toggle public RenderableDefinition getDefinition() {
92  0 return null;
93    }
94   
 
95  0 toggle public String execute() {
96  0 return null;
97    }
98    }
99   
 
100    public static class WrongConstructorModel extends NoConstructorModel {
 
101  0 toggle public WrongConstructorModel(Content content) {
102    // semi random constructor - we might want to support this at some point (non mandatory arguments ?)
103    }
104    }
105   
 
106    public static class StandardConstructorModel implements RenderingModel {
 
107  1 toggle public StandardConstructorModel(Content content, RenderableDefinition definition, RenderingModel parent) {
108   
109    }
110   
 
111  0 toggle public RenderingModel getParent() {
112  0 return null;
113    }
114   
 
115  0 toggle public Content getContent() {
116  0 return null;
117    }
118   
 
119  0 toggle public RenderableDefinition getDefinition() {
120  0 return null;
121    }
122   
 
123  0 toggle public String execute() {
124  0 return null;
125    }
126    }
127    }