1 8 9 package com.sleepycat.je.util; 10 11 import java.util.HashSet ; 12 import java.util.Properties ; 13 import java.util.Set ; 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 props = new Properties (); 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 props = new Properties (); 37 38 props.setProperty("foo", "true"); 39 props.setProperty("bar", "True"); 40 props.setProperty("baz", "false"); 41 42 Set allowedSet = new HashSet (); 43 allowedSet.add("foo"); 44 allowedSet.add("bar"); 45 allowedSet.add("baz"); 46 47 PropUtil.validateProps(props, allowedSet, "test"); 48 49 allowedSet.remove("foo"); 51 52 try { 53 PropUtil.validateProps(props, allowedSet, "test"); 54 fail(); 55 } catch (DatabaseException e) { 56 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 |