1 22 package test.dbc; 23 24 import junit.framework.TestCase; 25 import test.dbc.java.Sorter; 26 import test.dbc.office.Computer; 27 import test.dbc.office.Developer; 28 import test.dbc.office.OfficeManager; 29 import test.dbc.stack.Stack; 30 import test.dbc.stack.StackImpl; 31 32 37 public class DbcTest extends TestCase 38 { 39 public DbcTest(String name) { 40 super(name); 41 42 } 43 44 public void testOffice()throws Exception 45 { 46 System.out.println("****************** TEST OFFICE ******************"); 47 OfficeManager officeManager = new OfficeManager(); 48 49 Computer compA = officeManager.createComputer("comp A"); 50 Developer kabir = officeManager.createDeveloper("Kabir"); 52 53 officeManager.assignComputer(compA, kabir); 54 55 56 Developer bill = officeManager.createDeveloper("Bill"); 57 58 Computer compB = officeManager.createComputer("comp B"); 59 officeManager.assignComputer(compB, bill); 60 61 try 62 { 63 officeManager.createDeveloper(null); 64 if (true)throw new Exception ("Did not validate developer null name"); 65 } 66 catch(RuntimeException e) 67 { 68 } 69 70 } 71 72 public void testStack()throws Exception 73 { 74 System.out.println("****************** TEST STACK ******************"); 75 Stack s = new StackImpl(); 76 s.push("one"); 77 s.push("two"); 78 s.pop(); 79 80 s.push("two"); 81 s.push("three"); 82 s.pop(); 83 s.pop(); 84 s.pop(); 85 try 86 { 87 s.pop(); 88 throw new Exception ("Did not validate empty stack before pop"); 89 } 90 catch(RuntimeException e) 91 { 92 System.out.println(e.getMessage()); 93 } 94 } 95 96 public void testJavaExpression()throws Exception 97 { 98 System.out.println("****************** TEST SORTER ******************"); 99 100 int[] unsorted = new int[]{4, 1, 5, 3}; 101 Sorter.sort(unsorted); 102 103 try 104 { 105 Sorter.brokenSort(unsorted); 106 throw new Exception ("Did not validate list was not sorted"); 107 } 108 catch(RuntimeException e) 109 { 110 System.out.println(e.getMessage()); 111 } 112 } 113 114 115 } | Popular Tags |