1 15 package org.apache.tapestry.form.translator; 16 17 import org.apache.tapestry.valid.ValidatorException; 18 19 25 public class TestStringTranslator extends TranslatorTestCase 26 { 27 private StringTranslator _translator = new StringTranslator(); 28 29 public void testFormat() 30 { 31 replay(); 32 33 String result = _translator.format(_component, "Test this"); 34 35 assertEquals("Test this", result); 36 37 verify(); 38 } 39 40 public void testNullFormat() 41 { 42 replay(); 43 44 String result = _translator.format(_component, null); 45 46 assertEquals("", result); 47 48 verify(); 49 } 50 51 public void testParse() 52 { 53 replay(); 54 55 try 56 { 57 String result = (String ) _translator.parse(_component, "Test this"); 58 59 assertEquals("Test this", result); 60 } 61 catch (ValidatorException e) 62 { 63 unreachable(); 64 } 65 finally 66 { 67 verify(); 68 } 69 } 70 71 public void testTrimmedParse() 72 { 73 _translator.setTrim(true); 74 75 replay(); 76 77 try 78 { 79 String result = (String ) _translator.parse(_component, " Test this "); 80 81 assertEquals("Test this", result); 82 } 83 catch (ValidatorException e) 84 { 85 unreachable(); 86 } 87 finally 88 { 89 verify(); 90 } 91 } 92 93 public void testEmptyParse() 94 { 95 replay(); 96 97 try 98 { 99 String result = (String ) _translator.parse(_component, ""); 100 101 assertEquals(null, result); 102 } 103 catch (ValidatorException e) 104 { 105 unreachable(); 106 } 107 finally 108 { 109 verify(); 110 } 111 } 112 113 public void testCustomEmptyParse() 114 { 115 _translator.setEmpty(""); 116 117 replay(); 118 119 try 120 { 121 String result = (String ) _translator.parse(_component, ""); 122 123 assertEquals("", result); 124 } 125 catch (ValidatorException e) 126 { 127 unreachable(); 128 } 129 finally 130 { 131 verify(); 132 } 133 } 134 135 public void testRenderContribution() 136 { 137 replay(); 138 139 _translator.renderContribution(null, _cycle, null, _component); 140 141 verify(); 142 } 143 144 public void testTrimRenderContribution() 145 { 146 _translator.setTrim(true); 147 trim(); 148 149 replay(); 150 151 _translator.renderContribution(null, _cycle, null, _component); 152 153 verify(); 154 } 155 } 156 | Popular Tags |