1 20 package org.enhydra.barracuda; 21 22 import java.util.*; 23 24 import junit.framework.*; 25 26 import org.apache.log4j.*; 27 import org.enhydra.barracuda.testbed.*; 28 29 30 41 public class TestExample extends DefaultTestCase { 42 private static final String testClass = TestExample.class.getName(); 44 private static final Logger logger = Logger.getLogger("test."+testClass); 45 46 private static boolean demonstrateFailure = false; private static boolean demonstrateException = false; 50 54 public TestExample(String name) { 55 super(name); 56 } 57 58 65 public static void main(String args[]) { 66 TestUtil.parseParams(args); 68 69 if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String [] {testClass}); 71 else junit.swingui.TestRunner.main(new String [] {testClass}); 72 } 73 74 75 79 protected void setUp() throws Exception { 80 if (logger.isDebugEnabled()) logger.debug("Setting up test case"); 81 super.setUp(); 82 83 } 87 88 91 protected void tearDown() throws Exception { 92 if (logger.isDebugEnabled()) logger.debug("Tearing down test case"); 93 super.tearDown(); 94 95 } 99 100 101 107 111 public void testSample() { 112 if (logger.isInfoEnabled()) logger.info("running testSample()"); 113 114 try { 117 if (logger.isInfoEnabled()) logger.info("testing true!=false"); 119 assertTrue("true not equal false", true!=false); 120 121 if (demonstrateFailure) { 123 if (logger.isInfoEnabled()) logger.info("testing intentional failure"); 124 assertTrue("intentionally failed assertion", 1==0); 125 } 126 127 if (demonstrateException) { 129 if (logger.isInfoEnabled()) logger.info("generating sample exception"); 130 throw new Exception ("Sample Exception"); 131 } 132 133 if (logger.isInfoEnabled()) logger.info("tests complete!"); 135 } catch (Exception e) { 136 logger.error("Unexpected Test Exception", e); 139 fail("Unexpected Test Exception:"+e); 140 } 141 } 142 } 143 | Popular Tags |