KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > struts > tests > TestNullPointerAction


1 // StrutsTestCase - a JUnit extension for testing Struts actions
2
// within the context of the ActionServlet.
3
// Copyright (C) 2002 Deryl Seale
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the Apache Software License as
7
// published by the Apache Software Foundation; either version 1.1
8
// of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// Apache Software Foundation Licens for more details.
14
//
15
// You may view the full text here: http://www.apache.org/LICENSE.txt
16
package servletunit.struts.tests;
17
18 import servletunit.struts.*;
19 import java.io.File JavaDoc;
20
21 /**
22  * <p>Title: NullPointerActionTest</p>
23  * <p>Description: Tests to confirm a NullPointerException
24  * thrown from a misbehaving action reaches the test.</p>
25  * <p>Copyright: Copyright (c) 2003</p>
26  * @author Sean Pritchard
27  * @version 1.0
28  */

29 public class TestNullPointerAction extends MockStrutsTestCase {
30
31     public TestNullPointerAction() {
32     }
33
34     public void setUp() throws Exception JavaDoc {
35         super.setUp();
36         this.setContextDirectory(new File JavaDoc(System.getProperty("basedir") + "/src/examples"));
37         setConfigFile("/WEB-INF/struts-config-test.xml");
38     }
39
40     public void testNullPointer() throws Exception JavaDoc{
41         try{
42             this.setRequestPathInfo("/testNullPointer");
43             this.actionPerform();
44             fail("Exception expected");
45         }catch(ExceptionDuringTestError e){
46             //uncomment this to see a sample stack trace
47
//that users will see if their action throws an exception
48
// throw e;
49
}
50     }
51
52     public void testNullPointerFromForm() throws Exception JavaDoc{
53         try{
54             this.setRequestPathInfo("/testNullPointerForm");
55             this.actionPerform();
56             fail("Exception expected");
57         }catch(ExceptionDuringTestError e){
58             //uncomment this to see a sample stack trace
59
//that users will see if their action throws an exception
60
// throw e;
61
}
62     }
63
64
65     public static void main(String JavaDoc[] args) {
66         junit.textui.TestRunner.run(TestNullPointerAction.class);
67     }
68
69 }
70
Popular Tags