1 28 29 package com.idaremedia.antx.ut.tests; 30 31 import java.io.File ; 32 import java.io.InputStream ; 33 34 import junit.framework.Assert; 35 import junit.framework.AssertionFailedError; 36 import junit.framework.TestSuite; 37 38 import com.idaremedia.antx.ut.*; 39 40 41 51 52 public final class HTCTest extends HTC 53 { 54 55 public static final String TEST_CATEGORY="CLASS"; 56 57 58 61 public HTCTest(String methodName) 62 { 63 super("HTC::",methodName); 64 } 65 66 67 70 public static TestSuite suite() 71 { 72 return new TestSuite(HTCTest.class); 73 } 74 75 76 79 public static TestSuite baseline() 80 { 81 return suite(); 82 } 83 84 85 88 public static void main(String [] argv) 89 { 90 HTCUtils.quickCheck(suite()); 91 } 92 93 94 98 99 public final static class HTCExposer extends HTC { 100 public HTCExposer() { 101 super(); 102 } 103 public HTCExposer(String meth) { 104 super(meth); 105 } 106 public HTCExposer(String grpid, String meth) { 107 super(grpid,meth); 108 } 109 } 110 111 public void testFailRequire() 112 { 113 try { require_(false,"@failRequire"); Assert.fail("require(false)"); } 114 catch(TestError x) { Assert.assertTrue(x.getMessage().indexOf("@failRequire")>=0); } 115 } 116 117 public void testFailEnsure() 118 { 119 try { ensure_(false,"@failEnsure"); Assert.fail("ensure(false)"); } 120 catch(TestError x) { Assert.assertTrue(x.getMessage().indexOf("@failEnsure")>=0); } 121 } 122 123 public void testFailVerify() 124 { 125 try { verify_(false,"@failVerify"); Assert.fail("verify(false)"); } 126 catch(TestError x) { Assert.assertTrue(x.getMessage().indexOf("@failVerify")>=0); } 127 } 128 129 public void testFailASAP() 130 { 131 try 132 { HTC.failASAP("@failASAP_"); } 133 catch(AssertionFailedError x) 134 { Assert.assertTrue(x.getMessage().indexOf("@failASAP_")>=0); 135 return; } 136 Assert.fail("failASAP broken"); 137 } 138 139 public void testFailEqualASAP() 140 { 141 try 142 { HTC.failEqualASAP("foo",new String ("foo"),"@failEqualASAP_"); } 143 catch(AssertionFailedError x) 144 { Assert.assertTrue(x.getMessage().indexOf("@failEqualASAP_")>=0); 145 return; } 146 Assert.fail("failEqualASAP broken"); 147 } 148 149 public void testFailNotEqualASAP() 150 { 151 try 152 { HTC.failEqualASAP("foo","bar","@failNotEqualASAP_"); } 153 catch(AssertionFailedError x) 154 { Assert.assertTrue(x.getMessage().indexOf("@failNotEqualASAP_")>=0); 155 return; } 156 Assert.fail("failNotEqualASAP broken"); 157 } 158 159 160 166 167 171 public void testPassAssertEqual() 172 { 173 HTC.assertEqual("foo", new String ("foo")); 174 } 175 176 public void testPassAssertNotEqual() 177 { 178 HTC.assertNotEqual("foo","bar"); 179 } 180 181 public void testPassIdent() 182 { 183 Object o= new Double (Math.PI); 184 HTC.assertIdent(o,o); 185 } 186 187 public void testPassNotIdent() 188 { 189 Object o1= new Double (Math.PI); 190 Object o2= new Double (Math.PI); 191 HTC.assertNotIdent(o1,o2); 192 HTC.assertEqual(o1,o2); 193 } 194 195 199 public void testFindExpected() 200 { 201 Throwable t= new Throwable ("Oh goody time to wreak havoc"); 202 assertExpected(t,"goody"); 203 } 204 205 public void testNotFindExpected() 206 { 207 Throwable t= new Throwable ("Peanut and Jelly"); 208 boolean happy=true; 209 try { assertExpected(t,"Bologna"); happy=false; } 210 catch(AssertionFailedError x) { assertExpected(x,"Barfage"); } 211 HTC.assertTrue("Didn't find missing token",happy); 212 } 213 214 public void testFindExpectedOfKind() 215 { 216 Throwable t= new NullPointerException ("Oh goody time to wreak havoc"); 217 assertExpected(t,RuntimeException .class,"havoc"); 218 } 219 220 public void testNotFindExpectedOfKind() 221 { 222 Throwable t= new NullPointerException ("Fish and Chips"); 223 boolean happy=true; 224 try { assertExpected(t,ClassNotFoundException .class,"Chips"); happy=false; } 225 catch(AssertionFailedError x) { assertExpected(x,"Barfage"); } 226 HTC.assertTrue("Didn't match throwable class",happy); 227 } 228 229 233 public void testCanLoadClassResourcesAsStreams() 234 throws Exception 235 { 236 InputStream ins = getFileResourceAsStream("HTCTest.xml"); 237 int Nc=0; 238 while (ins.read() != -1) { 239 m_stdout.print("."); 240 Nc++; 241 } 242 ins.close(); 243 assertNotEqual(Nc,0,"Number HTCTest.xml bytes read"); 244 } 245 246 247 public void testCanLoadClassResourcesAsFiles() 248 throws Exception 249 { 250 File f = getFileResource("HTCTest.xml"); 251 java.io.FileReader fr = new java.io.FileReader (f); 252 assertTrue(fr.ready(),"HTCTest reader ready"); 253 int Nc=0; 254 while (fr.read() != -1) { 255 m_stdout.print("."); 256 Nc++; 257 } 258 fr.close(); 259 assertNotEqual(Nc,0,"Number HTCTest.xml bytes read"); 260 } 261 262 266 267 public void testCanLoadBuildFileResources() 268 throws Exception 269 { 270 File f = getFileResource("HTCTest.xml"); 271 configureProject(f.getPath()); 272 } 273 274 275 public void testCanExecuteTargetInBuildFile() 276 throws Exception 277 { 278 configureProject(getFileResource("HTCTest.xml").getPath()); 279 executeTarget("geeksalute"); 280 assertNotEqual(getLog().indexOf("helloworld"),-1,"'geeksalute' target output"); 281 } 282 } 283 284 285 | Popular Tags |