1 15 package org.apache.hivemind.util; 16 17 import org.apache.hivemind.service.BodyBuilder; 18 19 import hivemind.test.FrameworkTestCase; 20 21 27 public class TestBodyBuilder extends FrameworkTestCase 28 { 29 private BodyBuilder _b = new BodyBuilder(); 30 31 public void testBasic() 32 { 33 _b.begin(); 34 _b.addln("invoke();"); 35 _b.end(); 36 37 assertEquals("{\n invoke();\n}\n", _b.toString()); 38 } 39 40 public void testQuoted() 41 { 42 _b.add("invoke("); 43 _b.addQuoted("fred"); 44 _b.add(");"); 45 46 assertEquals("invoke(\"fred\");", _b.toString()); 47 } 48 49 public void testNested() 50 { 51 _b.begin(); 52 53 _b.add("while(true)"); 54 _b.begin(); 55 _b.add("_i += 1;"); 56 _b.end(); 57 58 _b.end(); 59 60 assertEquals("{\n while(true)\n {\n _i += 1;\n }\n}\n", _b.toString()); 61 } 62 63 public void testAddln() 64 { 65 _b.begin(); 66 _b.addln("invoke(fred);"); 67 _b.addln("invoke(barney);"); 68 _b.end(); 69 70 assertEquals("{\n invoke(fred);\n invoke(barney);\n}\n", _b.toString()); 71 } 72 73 public void testClear() 74 { 75 _b.add("fred"); 76 77 assertEquals("fred", _b.toString()); 78 79 _b.clear(); 80 81 _b.add("barney"); 82 83 assertEquals("barney", _b.toString()); 84 } 85 86 public void testAddPattern1() 87 { 88 _b.add("today is {0}.", "tuesday"); 89 90 assertEquals("today is tuesday.", _b.toString()); 91 } 92 93 public void testAddlnPattern1() 94 { 95 _b.addln("The capital of France is {0}.", "Paris"); 96 97 assertEquals("The capital of France is Paris.\n", _b.toString()); 98 } 99 100 public void testAddPattern2() 101 { 102 _b.add("Current suspects are: {0} and {1}.", "Tony", "Junior"); 103 104 assertEquals("Current suspects are: Tony and Junior.", _b.toString()); 105 } 106 107 public void testAddlnPattern2() 108 { 109 _b.addln("The capital of {0} is {1}.", "Germany", "Berlin"); 110 111 assertEquals("The capital of Germany is Berlin.\n", _b.toString()); 112 } 113 114 public void testAddPattern3() 115 { 116 _b.add("{0} + {1} = {2}", new Integer (5), new Integer (7), new Integer (13)); 117 118 assertEquals("5 + 7 = 13", _b.toString()); 119 } 120 121 public void testAddlnPattern3() 122 { 123 _b.addln("The Holy Trinity: {0}, {1} and {2}.", "Tapestry", "HiveMind", "Hibernate"); 124 125 assertEquals("The Holy Trinity: Tapestry, HiveMind and Hibernate.\n", _b.toString()); 126 } 127 128 } 129 | Popular Tags |