KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > util > variable > test > SystemPropertyExpanderTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.util.variable.test;
8
9
10 import junit.framework.TestCase;
11
12 import com.inversoft.util.variable.ExpanderException;
13 import com.inversoft.util.variable.ExpanderStrategy;
14 import com.inversoft.util.variable.SystemPropertyExpanderStrategy;
15
16
17 /**
18  * This class test the SystemPropertyExpanderStrategy class
19  *
20  * @author Brian Pontarelli
21  * @since 1.0
22  * @version 1.0
23  */

24 public class SystemPropertyExpanderTest extends TestCase {
25
26     /**
27      * Constructs a new <code>SystemPropertyExpanderTest</code>.
28      */

29     public SystemPropertyExpanderTest(String JavaDoc name) {
30         super(name);
31     }
32
33
34     /**
35      * Test the expand method with common properties
36      */

37     public void testCommon() {
38
39         ExpanderStrategy strat = new SystemPropertyExpanderStrategy();
40
41         try {
42             assertTrue("Should not have been null", strat.expand("java.home") != null);
43             assertTrue("Should not have been null", strat.expand("user.home") != null);
44         } catch (ExpanderException ee) {
45             fail(ee.toString());
46         }
47     }
48
49     /**
50      * Test the expand method with non-existant properties
51      */

52     public void testFailure() {
53
54         ExpanderStrategy strat = new SystemPropertyExpanderStrategy();
55
56         try {
57             strat.expand("foo.bar");
58             fail("Should have failed");
59         } catch (ExpanderException ee) {
60             assertTrue("SHould have a message", ee.getMessage() != null);
61         }
62     }
63
64     /**
65      * Test the expand method asserts
66      */

67     public void testAssert() {
68
69         ExpanderStrategy strat = new SystemPropertyExpanderStrategy();
70
71         try {
72             strat.expand(null);
73             fail("Should have failed");
74         } catch (ExpanderException ee) {
75             fail("Shouldn't have thrown this");
76         } catch (AssertionError JavaDoc ae) {
77             // Expected
78
}
79
80         try {
81             strat.expand("");
82             fail("Should have failed");
83         } catch (ExpanderException ee) {
84             fail("Shouldn't have thrown this");
85         } catch (AssertionError JavaDoc ae) {
86             // Expected
87
}
88     }
89 }
90
Popular Tags