| 1 | 
    
            
    
     | 
    
           | 
  
            
  
    | 2 | 
    
            
    
     | 
    
           | 
  
            
  
    | 3 | 
    
            
    
     | 
    
           | 
  
            
  
    | 4 | 
    
            
    
     | 
    
           | 
  
            
  
    | 5 | 
    
            
    
     | 
    
           | 
  
            
  
    | 6 | 
    
            
    
     | 
    
           | 
  
            
  
    | 7 | 
    
            
    
     | 
    
           | 
  
            
  
    | 8 | 
    
            
    
     | 
    
           | 
  
            
  
    | 9 | 
    
            
    
     | 
    
           | 
  
            
  
    | 10 | 
    
            
    
     | 
    
           | 
  
            
  
    | 11 | 
    
            
    
     | 
    
           | 
  
            
  
    | 12 | 
    
            
    
     | 
    
           | 
  
            
  
    | 13 | 
    
            
    
     | 
    
           | 
  
            
  
    | 14 | 
    
            
    
     | 
    
           | 
  
            
  
    | 15 | 
    
            
    
     | 
    
           | 
  
            
  
    | 16 | 
    
            
    
     | 
    
      package org.kuali.student.common.util;     | 
  
            
  
    | 17 | 
    
            
    
     | 
    
           | 
  
            
  
    | 18 | 
    
            
    
     | 
    
      import java.io.StringReader;     | 
  
            
  
    | 19 | 
    
            
    
     | 
    
      import java.math.BigDecimal;     | 
  
            
  
    | 20 | 
    
            
    
     | 
    
      import java.util.Arrays;     | 
  
            
  
    | 21 | 
    
            
    
     | 
    
      import java.util.Calendar;     | 
  
            
  
    | 22 | 
    
            
    
     | 
    
      import java.util.HashMap;     | 
  
            
  
    | 23 | 
    
            
    
     | 
    
      import java.util.List;     | 
  
            
  
    | 24 | 
    
            
    
     | 
    
      import java.util.Map;     | 
  
            
  
    | 25 | 
    
            
    
     | 
    
           | 
  
            
  
    | 26 | 
    
            
    
     | 
    
      import org.apache.velocity.tools.generic.DateTool;     | 
  
            
  
    | 27 | 
    
            
    
     | 
    
      import org.junit.Assert;     | 
  
            
  
    | 28 | 
    
            
    
     | 
    
      import org.junit.Test;     | 
  
            
  
    | 29 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 81 (81) | 
           Complexity: 11 | 
           Complexity Density: 0.16 | 
                        
            
        | 
    
  
  
    | 30 | 
    
            
    
     | 
    
      public class TestVelocityTemplateEngine {     | 
  
            
  
    | 31 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 7 (7) | 
           Complexity: 1 | 
           Complexity Density: 0.14 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 32 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 33 | 
    
            
    
     | 
    
          public void testEvaluateString_ContextMap() throws Exception {     | 
  
            
  
    | 34 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 35 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 36 | 
    
           0
    
     | 
    
              map.put("prop.1", "Kamal");     | 
  
            
  
    | 37 | 
    
           0
    
     | 
    
              map.put("prop.2", "Larry");     | 
  
            
  
    | 38 | 
    
            
    
     | 
    
           | 
  
            
  
    | 39 | 
    
           0
    
     | 
    
              String s = "List of Developers: $prop.1, $prop.2";     | 
  
            
  
    | 40 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 41 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 42 | 
    
           0
    
     | 
    
              Assert.assertEquals("List of Developers: $prop.1, $prop.2", eval);     | 
  
            
  
    | 43 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 44 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 6 (6) | 
           Complexity: 1 | 
           Complexity Density: 0.17 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 45 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 46 | 
    
            
    
     | 
    
          public void testEvaluateString1() throws Exception {     | 
  
            
  
    | 47 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 48 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 49 | 
    
           0
    
     | 
    
              map.put("developers", "Kamal, Larry, Len, Sherman, Zdenek");     | 
  
            
  
    | 50 | 
    
            
    
     | 
    
           | 
  
            
  
    | 51 | 
    
           0
    
     | 
    
              String s = "List of Developers: $developers";     | 
  
            
  
    | 52 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 53 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 54 | 
    
           0
    
     | 
    
              Assert.assertEquals("List of Developers: Kamal, Larry, Len, Sherman, Zdenek", eval);     | 
  
            
  
    | 55 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 56 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 7 (7) | 
           Complexity: 1 | 
           Complexity Density: 0.14 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 57 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 58 | 
    
            
    
     | 
    
          public void testEvaluateString2() throws Exception {     | 
  
            
  
    | 59 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 60 | 
    
           0
    
     | 
    
              List<String> devList = Arrays.asList(new String[] {"Kamal", "Larry", "Len", "Sherman", "Zdenek"});     | 
  
            
  
    | 61 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 62 | 
    
           0
    
     | 
    
              map.put("developers", devList);     | 
  
            
  
    | 63 | 
    
            
    
     | 
    
           | 
  
            
  
    | 64 | 
    
           0
    
     | 
    
              String s = "List of Developers: $developers";     | 
  
            
  
    | 65 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 66 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 67 | 
    
           0
    
     | 
    
              Assert.assertEquals("List of Developers: [Kamal, Larry, Len, Sherman, Zdenek]", eval);     | 
  
            
  
    | 68 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 69 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 6 (6) | 
           Complexity: 1 | 
           Complexity Density: 0.17 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 70 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 71 | 
    
            
    
     | 
    
          public void testEvaluateReader() throws Exception {     | 
  
            
  
    | 72 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 73 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 74 | 
    
           0
    
     | 
    
              map.put("developers", "Kamal, Larry, Len, Sherman, Zdenek");     | 
  
            
  
    | 75 | 
    
            
    
     | 
    
           | 
  
            
  
    | 76 | 
    
           0
    
     | 
    
              StringReader sr = new StringReader("List of Developers: $developers");     | 
  
            
  
    | 77 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, sr);     | 
  
            
  
    | 78 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 79 | 
    
           0
    
     | 
    
              Assert.assertEquals("List of Developers: Kamal, Larry, Len, Sherman, Zdenek", eval);     | 
  
            
  
    | 80 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 81 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 7 (7) | 
           Complexity: 1 | 
           Complexity Density: 0.14 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 82 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 83 | 
    
            
    
     | 
    
          public void testEvaluateNumber() throws Exception {     | 
  
            
  
    | 84 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 85 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 86 | 
    
           0
    
     | 
    
              map.put("expectedValue", new BigDecimal("100"));     | 
  
            
  
    | 87 | 
    
           0
    
     | 
    
              map.put("resultValue", new BigDecimal("60"));     | 
  
            
  
    | 88 | 
    
            
    
     | 
    
           | 
  
            
  
    | 89 | 
    
           0
    
     | 
    
              String s = "#set( $difference = ($expectedValue - $resultValue) )expectedValue=$expectedValue, resultValue=$resultValue, difference=$difference";     | 
  
            
  
    | 90 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 91 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 92 | 
    
           0
    
     | 
    
              Assert.assertEquals("expectedValue=100, resultValue=60, difference=40", eval);     | 
  
            
  
    | 93 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 94 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 7 (7) | 
           Complexity: 1 | 
           Complexity Density: 0.14 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 95 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 96 | 
    
            
    
     | 
    
          public void testEvaluate_MathTool() throws Exception {     | 
  
            
  
    | 97 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 98 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 99 | 
    
           0
    
     | 
    
              map.put("expectedValue", "100");     | 
  
            
  
    | 100 | 
    
           0
    
     | 
    
              map.put("resultValue", "60");     | 
  
            
  
    | 101 | 
    
            
    
     | 
    
           | 
  
            
  
    | 102 | 
    
           0
    
     | 
    
              String s = "#set( $difference = ( $mathTool.toNumber($expectedValue) - $mathTool.toNumber($resultValue)) )expectedValue=$expectedValue, resultValue=$resultValue, difference=$difference";     | 
  
            
  
    | 103 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 104 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 105 | 
    
           0
    
     | 
    
              Assert.assertEquals("expectedValue=100, resultValue=60, difference=40", eval);     | 
  
            
  
    | 106 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 107 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 7 (7) | 
           Complexity: 1 | 
           Complexity Density: 0.14 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 108 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 109 | 
    
            
    
     | 
    
          public void testEvaluate_DateTool() throws Exception {     | 
  
            
  
    | 110 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 111 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 112 | 
    
           0
    
     | 
    
              map.put("expectedValue", "100");     | 
  
            
  
    | 113 | 
    
           0
    
     | 
    
              map.put("resultValue", "60");     | 
  
            
  
    | 114 | 
    
            
    
     | 
    
           | 
  
            
  
    | 115 | 
    
           0
    
     | 
    
              String s = "Date created $dateTool.get('yyyy-MM-dd HH:mm z')";     | 
  
            
  
    | 116 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 117 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 118 | 
    
           0
    
     | 
    
              Assert.assertEquals("Date created " + new DateTool().get("yyyy-MM-dd HH:mm z"), eval);     | 
  
            
  
    | 119 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 120 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 6 (6) | 
           Complexity: 1 | 
           Complexity Density: 0.17 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 121 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 122 | 
    
            
    
     | 
    
          public void testEvaluate_DateComparisonTool() throws Exception {     | 
  
            
  
    | 123 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 124 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 125 | 
    
           0
    
     | 
    
              map.put("date1", Calendar.getInstance());     | 
  
            
  
    | 126 | 
    
            
    
     | 
    
           | 
  
            
  
    | 127 | 
    
           0
    
     | 
    
              String s = "$dateComparisonTool.whenIs($date1, $date1)";     | 
  
            
  
    | 128 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 129 | 
    
            
    
     | 
    
           | 
  
            
  
    | 130 | 
    
           0
    
     | 
    
              Assert.assertEquals("same time", eval);     | 
  
            
  
    | 131 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 132 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 4 (4) | 
           Complexity: 1 | 
           Complexity Density: 0.25 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 133 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 134 | 
    
            
    
     | 
    
          public void testEvaluate_DateComparisonTool_NullContextMap() throws Exception {     | 
  
            
  
    | 135 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 136 | 
    
            
    
     | 
    
           | 
  
            
  
    | 137 | 
    
           0
    
     | 
    
              String s = "$dateComparisonTool.difference($dateTool.calendar, $dateTool.calendar).hours";     | 
  
            
  
    | 138 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(null, s);     | 
  
            
  
    | 139 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 140 | 
    
           0
    
     | 
    
              Assert.assertEquals("0", eval);     | 
  
            
  
    | 141 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 142 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 6 (6) | 
           Complexity: 1 | 
           Complexity Density: 0.17 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 143 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 144 | 
    
            
    
     | 
    
          public void testEvaluate_NumberTool() throws Exception {     | 
  
            
  
    | 145 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 146 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 147 | 
    
           0
    
     | 
    
              map.put("expectedValue", "100.12");     | 
  
            
  
    | 148 | 
    
            
    
     | 
    
           | 
  
            
  
    | 149 | 
    
           0
    
     | 
    
              String s = "$numberTool.currency($expectedValue)";     | 
  
            
  
    | 150 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 151 | 
    
            
    
     | 
    
                   | 
  
            
  
    | 152 | 
    
           0
    
     | 
    
              Assert.assertEquals("$100.12", eval);     | 
  
            
  
    | 153 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 154 | 
    
            
    
     | 
    
           | 
  
               
        | 
             
         | 
        
       
        | 
       
           
           
            | 0% | 
           Uncovered Elements: 7 (7) | 
           Complexity: 1 | 
           Complexity Density: 0.14 | 
                            4
   -
 | 
                        
            
        | 
    
  
  
    | 155 | 
    
           0
    
     | 
    
           @Test...     | 
  
            
  
    | 156 | 
    
            
    
     | 
    
          public void testEvaluate_SortTool() throws Exception {     | 
  
            
  
    | 157 | 
    
           0
    
     | 
    
              VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();     | 
  
            
  
    | 158 | 
    
           0
    
     | 
    
              List<String> devList = Arrays.asList(new String[] {"Len", "Larry", "Kamal", "Zdenek", "Sherman"});     | 
  
            
  
    | 159 | 
    
           0
    
     | 
    
              Map<String, Object> map = new HashMap<String, Object>();     | 
  
            
  
    | 160 | 
    
           0
    
     | 
    
              map.put("developers", devList);     | 
  
            
  
    | 161 | 
    
            
    
     | 
    
           | 
  
            
  
    | 162 | 
    
           0
    
     | 
    
              String s = "$sortTool.sort($developers)";     | 
  
            
  
    | 163 | 
    
           0
    
     | 
    
              String eval = templateEngine.evaluate(map, s);     | 
  
            
  
    | 164 | 
    
            
    
     | 
    
           | 
  
            
  
    | 165 | 
    
           0
    
     | 
    
              Assert.assertEquals("[Kamal, Larry, Len, Sherman, Zdenek]", eval);     | 
  
            
  
    | 166 | 
    
            
    
     | 
    
          }     | 
  
            
  
    | 167 | 
    
            
    
     | 
    
      }     |