-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTemplatingAutoConfigurationTest.java
More file actions
75 lines (59 loc) · 2.56 KB
/
TemplatingAutoConfigurationTest.java
File metadata and controls
75 lines (59 loc) · 2.56 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.blibli.oss.template.autoconfigurer;
import com.blibli.oss.template.properties.TemplateProperties;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Options;
import com.github.jknack.handlebars.cache.ConcurrentMapTemplateCache;
import com.github.jknack.handlebars.cache.TemplateCache;
import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
import com.github.jknack.handlebars.io.TemplateLoader;
import com.github.jknack.handlebars.io.TemplateSource;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Eko Kurniawan Khannedy
*/
public class TemplatingAutoConfigurationTest {
private TemplatingAutoConfiguration configuration = new TemplatingAutoConfiguration();
@InjectMocks
private TemplatingAutoConfiguration templatingAutoConfiguration;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void testTemplateLoader() throws Exception {
TemplateProperties templateProperties = new TemplateProperties();
TemplateLoader templateLoader = configuration.templateLoader(templateProperties);
assertEquals("/templates/", templateLoader.getPrefix());
assertEquals(".hbs", templateLoader.getSuffix());
ClassPathTemplateLoader loader = (ClassPathTemplateLoader) templateLoader;
TemplateSource hello = loader.sourceAt("hello");
assertEquals("Hello {{name}}", hello.content());
assertEquals("/templates/hello.hbs", hello.filename());
}
@Test
public void testHandlebars() throws Exception {
TemplateProperties templateProperties = new TemplateProperties();
TemplateCache templateCache = configuration.templateCache();
TemplateLoader templateLoader = configuration.templateLoader(templateProperties);
Handlebars handlebars = configuration.handlebars(templateLoader, templateCache);
assertNotNull(handlebars);
assertTrue(handlebars.getCache() instanceof ConcurrentMapTemplateCache);
assertEquals(templateLoader, handlebars.getLoader());
}
@Test
public void testCustomSeparator() throws Exception {
Map<String,Object> hash = new HashMap<>();
hash.put("separator",".");
Options options = new Options(null, null, null, null, null, null, null, hash, new ArrayList<>());
String result = templatingAutoConfiguration.customSeparator(10500.50d, options);
assertEquals("10.500",result);
}
}