| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 12 |
Complexity Density: 0,6 |
|
| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 47 |
0 |
protected final Logger getLog() {... |
| 48 |
0 |
return this.log; |
| 49 |
|
} |
| 50 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 51 |
0 |
@BeforeEach... |
| 52 |
|
protected void setUp() throws Exception { |
| 53 |
0 |
this.setTemplate(""); |
| 54 |
0 |
this.setContext(new VelocityContext()); |
| 55 |
0 |
this.setExpected(""); |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
| 58 |
0 |
@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 |
| 68 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
0 |
protected VelocityEngine getEngine() {... |
| 70 |
0 |
return this.engine; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
@param |
| 75 |
|
|
| 76 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 77 |
0 |
protected void setEngine(final VelocityEngine engine) {... |
| 78 |
0 |
this.engine = engine; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
@return |
| 83 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
0 |
protected String getTemplate() {... |
| 85 |
0 |
return this.template; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
@param |
| 90 |
|
|
| 91 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 92 |
0 |
protected void setTemplate(final String template) {... |
| 93 |
0 |
this.template = template; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
@return |
| 98 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
0 |
protected Context getContext() {... |
| 100 |
0 |
return this.context; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
@param |
| 105 |
|
|
| 106 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
0 |
protected void setContext(final Context context) {... |
| 108 |
0 |
this.context = context; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
@return |
| 113 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 114 |
0 |
protected String getExpected() {... |
| 115 |
0 |
return this.expected; |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@param |
| 120 |
|
|
| 121 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 122 |
0 |
protected void setExpected(final String expected) {... |
| 123 |
0 |
this.expected = expected; |
| 124 |
|
} |
| 125 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
| 126 |
0 |
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 |
|
} |