1. Project Clover database mar. avr. 16 2024 08:19:06 CEST
  2. Package org.devacfr.testing.jupiter

File AbstractVelocityTestCase.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
94% of files have more coverage

Code metrics

0
20
12
1
135
67
12
0,6
1,67
12
1

Classes

Class
Line #
Actions
AbstractVelocityTestCase 35 20 0% 12 32
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing,
13    * software distributed under the License is distributed on an
14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15    * KIND, either express or implied. See the License for the
16    * specific language governing permissions and limitations
17    * under the License.
18    */
19    package org.devacfr.testing.jupiter;
20   
21    import java.io.IOException;
22    import java.io.StringWriter;
23   
24    import org.apache.velocity.VelocityContext;
25    import org.apache.velocity.app.VelocityEngine;
26    import org.apache.velocity.context.Context;
27    import org.apache.velocity.exception.MethodInvocationException;
28    import org.apache.velocity.exception.ParseErrorException;
29    import org.apache.velocity.exception.ResourceNotFoundException;
30    import org.junit.jupiter.api.AfterEach;
31    import org.junit.jupiter.api.BeforeEach;
32    import org.slf4j.Logger;
33    import org.slf4j.LoggerFactory;
34   
 
35    public abstract class AbstractVelocityTestCase extends MockitoTestCase {
36   
37    private final Logger log = LoggerFactory.getLogger(this.getClass());
38   
39    private VelocityEngine engine = null;
40   
41    private String template = "";
42   
43    private Context context = null;
44   
45    private String expected = null;
46   
 
47  0 toggle protected final Logger getLog() {
48  0 return this.log;
49    }
50   
 
51  0 toggle @BeforeEach
52    protected void setUp() throws Exception {
53  0 this.setTemplate("");
54  0 this.setContext(new VelocityContext());
55  0 this.setExpected("");
56    }
57   
 
58  0 toggle @AfterEach
59    protected void tearDown() throws Exception {
60  0 this.setEngine(null);
61  0 this.setTemplate(null);
62  0 this.setContext(null);
63  0 this.setExpected(null);
64    }
65   
66    /**
67    * @return Returns the engine.
68    */
 
69  0 toggle protected VelocityEngine getEngine() {
70  0 return this.engine;
71    }
72   
73    /**
74    * @param engine
75    * The engine to set.
76    */
 
77  0 toggle protected void setEngine(final VelocityEngine engine) {
78  0 this.engine = engine;
79    }
80   
81    /**
82    * @return Returns the template.
83    */
 
84  0 toggle protected String getTemplate() {
85  0 return this.template;
86    }
87   
88    /**
89    * @param template
90    * The template to set.
91    */
 
92  0 toggle protected void setTemplate(final String template) {
93  0 this.template = template;
94    }
95   
96    /**
97    * @return Returns the context.
98    */
 
99  0 toggle protected Context getContext() {
100  0 return this.context;
101    }
102   
103    /**
104    * @param context
105    * The context to set.
106    */
 
107  0 toggle protected void setContext(final Context context) {
108  0 this.context = context;
109    }
110   
111    /**
112    * @return Returns the expected.
113    */
 
114  0 toggle protected String getExpected() {
115  0 return this.expected;
116    }
117   
118    /**
119    * @param expected
120    * The expected to set.
121    */
 
122  0 toggle protected void setExpected(final String expected) {
123  0 this.expected = expected;
124    }
125   
 
126  0 toggle protected void assertVelocity()
127    throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException, Exception {
128  0 this.getEngine().init();
129   
130  0 final StringWriter writer = new StringWriter();
131  0 assertTrue(this.getEngine().evaluate(this.getContext(), writer, this.getName(), this.getTemplate()));
132   
133  0 assertEquals(this.getExpected(), String.valueOf(writer));
134    }
135    }