KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > util > PropUtilTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: PropUtilTest.java,v 1.18 2006/11/28 18:16:33 mark Exp $
7  */

8
9 package com.sleepycat.je.util;
10
11 import java.util.HashSet JavaDoc;
12 import java.util.Properties JavaDoc;
13 import java.util.Set JavaDoc;
14
15 import junit.framework.TestCase;
16
17 import com.sleepycat.je.DatabaseException;
18 import com.sleepycat.je.utilint.PropUtil;
19
20 public class PropUtilTest extends TestCase {
21     public void testGetBoolean() {
22         Properties JavaDoc props = new Properties JavaDoc();
23
24         props.setProperty("foo", "true");
25         props.setProperty("bar", "True");
26         props.setProperty("baz", "false");
27
28         assertTrue(PropUtil.getBoolean(props, "foo"));
29         assertTrue(PropUtil.getBoolean(props, "bar"));
30         assertFalse(PropUtil.getBoolean(props, "baz"));
31     }
32
33     public void testValidate()
34         throws DatabaseException {
35
36         Properties JavaDoc props = new Properties JavaDoc();
37
38         props.setProperty("foo", "true");
39         props.setProperty("bar", "True");
40         props.setProperty("baz", "false");
41
42         Set JavaDoc allowedSet = new HashSet JavaDoc();
43         allowedSet.add("foo");
44         allowedSet.add("bar");
45         allowedSet.add("baz");
46
47         PropUtil.validateProps(props, allowedSet, "test");
48
49         // test negative case
50
allowedSet.remove("foo");
51
52         try {
53             PropUtil.validateProps(props, allowedSet, "test");
54             fail();
55         } catch (DatabaseException e) {
56             //System.out.println(e);
57
assertEquals(DatabaseException.getVersionHeader() +
58                          "foo is not a valid property for test",
59                          e.getMessage());
60         }
61     }
62
63     public void testMicrosToMillis() {
64
65         assertEquals(0, PropUtil.microsToMillis(0));
66         assertEquals(1, PropUtil.microsToMillis(1));
67         assertEquals(1, PropUtil.microsToMillis(999));
68         assertEquals(1, PropUtil.microsToMillis(1000));
69         assertEquals(2, PropUtil.microsToMillis(1001));
70     }
71 }
72
Popular Tags