import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
public class TemplateTest {
@Test
public void testFormat() throws Exception {
Template template = new Template();
String text = "Hello {who}, {saluto}";
String result = "Hello ReVo_, ok?";
Map<String, String> vars = new HashMap<>();
vars.put("who", "ReVo_");
vars.put("saluto", "ok?");
assertEquals(result, template.format(text, vars));
}
@Test
public void testWithoutAnyArgument() throws Exception {
Template template = new Template();
String text = "Hello world!";
String result = "Hello world!";
Map<String, String> vars = new HashMap<>();
vars.put("who", "ReVo_");
vars.put("saluto", "ok?");
assertEquals(result, template.format(text, vars));
}
@Test
public void testWithSomeArgumentsWithoutBind() throws Exception {
Template template = new Template();
String text = "Hello {world}!";
String result = "Hello {world}!";
Map<String, String> vars = new HashMap<>();
vars.put("who", "ReVo_");
vars.put("saluto", "ok?");
assertEquals(result, template.format(text, vars));
}
@Test
public void testWithADifferentStartEnd() throws Exception {
Template template = new Template("|", "|");
String text = "Hello |world|!";
String result = "Hello ReVo_!";
Map<String, String> vars = new HashMap<>();
vars.put("world", "ReVo_");
assertEquals(result, template.format(text, vars));
}
@Test
public void testWithADifferentStartEnd2() throws Exception {
Template template = new Template("|", "-");
String text = "Hello |world-!";
String result = "Hello ReVo_!";
Map<String, String> vars = new HashMap<>();
vars.put("world", "ReVo_");
assertEquals(result, template.format(text, vars));
}
}