Debian Codegraph @

library/src/test/java/org/kravemir/svg/labels/utils/ExpressionEvaluatorTest.java

raw
1 package org.kravemir.svg.labels.utils;
2
3 import org.junit.Before;
4 import org.junit.Test;
5
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import static org.junit.Assert.assertEquals;
10
11 public class ExpressionEvaluatorTest {
12
13 private static final Map<String,String> VALUES = new HashMap<>();
14 static {
15 VALUES.put("name", "The Name");
16 VALUES.put("weight", "80");
17 }
18
19 private ExpressionEvaluator expressionEvaluator = null;
20
21 @Before
22 public void setUp() throws Exception {
23 expressionEvaluator = new ExpressionEvaluator();
24 }
25
26 @Test
27 public void test() {
28 testEvaluation("The Name", "$name");
29 testEvaluation("The Name", "${name}");
30 testEvaluation("The Name, 80g", "$name, ${weight}g");
31 testEvaluation("The Name, 80g", "${name}, ${weight}g");
32 }
33
34 private void testEvaluation(String expected, String expression) {
35 assertEquals(
36 "Evaluation of `" + expression + "`",
37 expected,
38 expressionEvaluator.evaluateExpression(expression,VALUES)
39 );
40 }
41 }