KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dbc > Driver


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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 /**
33  *
34  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
35  * @version $Revision: 37406 $
36  */

37 public class Driver
38 {
39     public void testOffice()throws Exception JavaDoc
40     {
41        System.out.println("****************** TEST OFFICE ******************");
42        OfficeManager officeManager = new OfficeManager();
43
44        Computer compA = officeManager.createComputer("comp A");
45        Developer kabir = officeManager.createDeveloper("Kabir");
46
47        officeManager.assignComputer(compA, kabir);
48
49        
50        Developer bill = officeManager.createDeveloper("Bill");
51
52        Computer compB = officeManager.createComputer("comp B");
53        officeManager.assignComputer(compB, bill);
54             
55        try
56        {
57           officeManager.createDeveloper(null);
58           if (true)throw new Exception JavaDoc("Did not validate developer null name");
59        }
60        catch(RuntimeException JavaDoc e)
61        {
62        }
63        
64     }
65     
66    public void testStack()throws Exception JavaDoc
67    {
68        System.out.println("****************** TEST STACK ******************");
69       Stack s = new StackImpl();
70       s.push("one");
71       s.push("two");
72       s.pop();
73
74       s.push("two");
75       s.push("three");
76       s.pop();
77       s.pop();
78       s.pop();
79       try
80       {
81          s.pop();
82           throw new Exception JavaDoc("Did not validate empty stack before pop");
83       }
84       catch(RuntimeException JavaDoc e)
85       {
86          System.out.println(e.getMessage());
87       }
88    }
89    
90    public void testJavaExpression()throws Exception JavaDoc
91    {
92        System.out.println("****************** TEST SORTER ******************");
93        
94        int[] unsorted = new int[]{4, 1, 5, 3};
95        int[] sorted = Sorter.sort(unsorted);
96        
97        try
98        {
99           Sorter.brokenSort(unsorted);
100           throw new Exception JavaDoc("Did not validate list was not sorted");
101        }
102        catch(RuntimeException JavaDoc e)
103        {
104          System.out.println(e.getMessage());
105        }
106    }
107    
108    public static void main(String JavaDoc[] args)
109    {
110       try
111       {
112           Driver d = new Driver();
113           d.testOffice();
114           d.testStack();
115           d.testJavaExpression();
116       }
117       catch(Exception JavaDoc e)
118       {
119          System.out.println("Error: " + e.getMessage());
120          e.printStackTrace();
121       }
122    }
123 }
Popular Tags