blob: 9b88e209286ba84d19e54b4ad2963fa86f17ff85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package org.apache.velocity.runtime;
import static org.junit.Assert.assertEquals;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.ResourceManager;
import org.junit.Test;
public class RuntimeInstanceTest {
@Test
public void givenOverridenInputEncoding_whenInitializing_defaultEncodingIsOverridden() {
RuntimeInstance instance = new RuntimeInstance();
MockResourceManager manager = new MockResourceManager();
String value = "testDummyEncoding";
instance.addProperty(RuntimeConstants.INPUT_ENCODING, value);
instance.addProperty(RuntimeConstants.RESOURCE_MANAGER_INSTANCE, manager);
instance.init();
instance.getTemplate("some template");
assertEquals(value, manager.encoding);
}
class MockResourceManager implements ResourceManager {
String encoding = null;
@Override
public String getLoaderNameForResource(String resourceName) {
return null;
}
@Override
public Resource getResource(String resourceName, int resourceType, String encoding)
throws ResourceNotFoundException, ParseErrorException {
this.encoding = encoding;
return null;
}
@Override
public void initialize(RuntimeServices rs) {
}
}
}
|