1 /***
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions are
4 * met :
5 *
6 * . Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 *
9 * . Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * . The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id: ConfigurationTest.java 264 2005-09-26 20:51:16Z mat007 $
29 */
30
31 package palmed.option;
32
33 import junit.framework.TestCase;
34
35 /***
36 * Configuration test case.
37 *
38 * @author Mathieu Champlon
39 * @version $Revision: 264 $ $Date: 2005-09-27 05:51:16 +0900 (mar., 27 sept. 2005) $
40 */
41 public class ConfigurationTest extends TestCase
42 {
43 /***
44 * Tested object.
45 */
46 private Configuration configuration;
47
48 protected void setUp()
49 {
50 configuration = new Configuration();
51 }
52
53 public void testRetrieveNonExistingBooleanTrueValue()
54 {
55 assertTrue( configuration.get( "non-existing-key", true ) );
56 }
57
58 public void testRetrieveNonExistingBooleanFalseValue()
59 {
60 assertFalse( configuration.get( "non-existing-key", false ) );
61 }
62
63 public void testRetrieveNonExistingBooleanTrueValueAddsIt()
64 {
65 assertTrue( configuration.get( "key", true ) );
66 assertTrue( configuration.get( "key", true ) );
67 assertTrue( configuration.get( "key", false ) );
68 }
69
70 public void testRetrieveNonExistingBooleanFalseValueAddsIt()
71 {
72 assertFalse( configuration.get( "key", false ) );
73 assertFalse( configuration.get( "key", false ) );
74 assertFalse( configuration.get( "key", true ) );
75 }
76
77 public void testRetrieveNonExistingStringValue()
78 {
79 final String string = "string value";
80 assertEquals( string, configuration.get( "key", string ) );
81 }
82
83 public void testRetrieveNonExistingStringValueAddsIt()
84 {
85 final String string = "string value";
86 assertEquals( string, configuration.get( "key", string ) );
87 assertEquals( string, configuration.get( "key", "another initial value" ) );
88 }
89
90 public void testRetrieveExistingStringValueAsBooleanThrowsException()
91 {
92 configuration.get( "key", "string value" );
93 try
94 {
95 configuration.get( "key", true );
96 }
97 catch( Exception e )
98 {
99 return;
100 }
101 fail( "should throw an exception" );
102 }
103
104 public void testRetrieveExistingBooleanValueAsStringThrowsException()
105 {
106 configuration.get( "key", true );
107 try
108 {
109 configuration.get( "key", "string value" );
110 }
111 catch( Exception e )
112 {
113 return;
114 }
115 fail( "should throw an exception" );
116 }
117 }