コード例 #1
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testDouble() {
    final MyProperties props = new MyProperties();

    // Default value.
    Assert.assertEquals(-3.14, props.doubleProp.get());
    Assert.assertEquals(.789, props.doubleProp.get(.789));

    double prev = props.doubleProp.set(.8);
    Assert.assertEquals(.8, props.doubleProp.get());
    Assert.assertEquals(-3.14, prev);

    prev = props.doubleProp.set(.0);
    Assert.assertEquals(.8, prev);
  }
コード例 #2
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testInt() {
    final MyProperties props = new MyProperties();

    // Default value.
    Assert.assertEquals(5, props.intProp.get());
    Assert.assertEquals(789, props.intProp.get(789));

    int prev = props.intProp.set(8);
    Assert.assertEquals(8, props.intProp.get());
    Assert.assertEquals(5, prev);

    prev = props.intProp.set(0);
    Assert.assertEquals(8, prev);
  }
コード例 #3
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testBooleanNoDefault() {
    final MyProperties props = new MyProperties();

    // As above, on property with no default value.
    Assert.assertEquals(false, props.booleanPropNoDefault.get());
    Assert.assertEquals(true, props.booleanPropNoDefault.get(true));
    Assert.assertEquals(false, props.booleanPropNoDefault.get(false));

    boolean prev = props.booleanPropNoDefault.set(true);
    Assert.assertEquals(false, prev);
    Assert.assertEquals(true, props.booleanPropNoDefault.get());
    Assert.assertEquals(true, props.booleanPropNoDefault.get(false));

    // Second time set returns the previous value.
    prev = props.booleanPropNoDefault.set(false);
    Assert.assertEquals(true, prev);

    // Setting null is not OK.
    try {
      props.booleanPropNoDefault.setString(null);
      fail("expected NPE");
    } catch (NullPointerException e) {
      // ok
    }
  }
コード例 #4
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testString() {
    final MyProperties props = new MyProperties();

    // Default value.
    Assert.assertEquals("foo", props.stringProp.get());
    Assert.assertEquals("xxxxx", props.stringProp.get("xxxxx"));

    // First time set returns the default value.
    String prev = props.stringProp.set("bar");
    Assert.assertEquals("bar", props.stringProp.get());
    Assert.assertEquals("foo", prev);

    // Second time set returns the previous value.
    prev = props.stringProp.set("baz");
    Assert.assertEquals("bar", prev);

    // Setting null is not OK.
    try {
      prev = props.stringProp.set(null);
      fail("expected NPE");
    } catch (NullPointerException e) {
      // ok
    }
  }
コード例 #5
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testTrigger() {
    final MyProperties props = new MyProperties();
    final int[] ints = {0};
    final Trigger trigger =
        new Trigger() {
          public boolean isPersistent() {
            return false;
          }

          public int phase() {
            return 0;
          }

          public void execute(Property property, String value) throws VetoRT {
            int intValue = Integer.parseInt(value);
            if (intValue > 10) {
              ints[0] = intValue;
            }
            if (intValue > 100) {
              throw new VetoRT("too big");
            }
          }
        };
    props.intProp.addTrigger(trigger);
    props.intProp.set(5);
    assertEquals(0, ints[0]); // unchanged
    props.intProp.set(15);
    assertEquals(15, ints[0]); // changed by trigger
    try {
      props.intProp.set(120);
      fail("expecting exception");
    } catch (Trigger.VetoRT e) {
      assertEquals("too big", e.getMessage());
    }
    Assert.assertEquals(15, props.intProp.get()); // change was rolled back
  }
コード例 #6
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testIntNoDefault() {
    final MyProperties props = new MyProperties();

    // As above, on property with no default value.
    Assert.assertEquals(0, props.intPropNoDefault.get());
    Assert.assertEquals(17, props.intPropNoDefault.get(17));

    int prev = props.intPropNoDefault.set(-56);
    Assert.assertEquals(0, prev);
    Assert.assertEquals(-56, props.intPropNoDefault.get());
    Assert.assertEquals(-56, props.intPropNoDefault.get(17));

    // Second time set returns the previous value.
    prev = props.intPropNoDefault.set(12345);
    Assert.assertEquals(-56, prev);

    // Setting null is not OK.
    try {
      props.intPropNoDefault.setString(null);
      fail("expected NPE");
    } catch (NullPointerException e) {
      // ok
    }
  }
コード例 #7
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testStringNoDefault() {
    final MyProperties props = new MyProperties();

    // As above, on property with no default value.
    Assert.assertEquals(null, props.stringPropNoDefault.get());
    Assert.assertEquals("xx", props.stringPropNoDefault.get("xx"));

    String prev = props.stringPropNoDefault.set("paul");
    Assert.assertEquals(null, prev);
    Assert.assertEquals("paul", props.stringPropNoDefault.get());
    Assert.assertEquals("paul", props.stringPropNoDefault.get("xx"));

    // Second time set returns the previous value.
    prev = props.stringPropNoDefault.set("ringo");
    Assert.assertEquals("paul", prev);

    // Setting null is not OK.
    try {
      prev = props.stringPropNoDefault.set(null);
      fail("expected NPE");
    } catch (NullPointerException e) {
      // ok
    }
  }
コード例 #8
0
ファイル: PropertyTest.java プロジェクト: Jach/luciddb
  public void testBoolean() {
    final MyProperties props = new MyProperties();

    // Default value.
    Assert.assertEquals(true, props.booleanProp.get());
    Assert.assertEquals(false, props.booleanProp.get(false));

    // First time set returns the default value.
    boolean prev = props.booleanProp.set(false);
    Assert.assertEquals(false, props.booleanProp.get());
    Assert.assertEquals(true, prev);

    // Second time set returns the previous value.
    prev = props.booleanProp.set(true);
    Assert.assertEquals(false, prev);

    // Various values all mean true.
    String prevString = props.booleanProp.setString("1");
    Assert.assertEquals(true, props.booleanProp.get());
    prevString = props.booleanProp.setString("true");
    Assert.assertEquals(true, props.booleanProp.get());
    prevString = props.booleanProp.setString("TRUE");
    Assert.assertEquals(true, props.booleanProp.get());
    prevString = props.booleanProp.setString("yes");
    Assert.assertEquals(true, props.booleanProp.get());
    prevString = props.booleanProp.setString("Yes");
    Assert.assertEquals(true, props.booleanProp.get());

    // Leading and trailing spaces are ignored.
    prevString = props.booleanProp.setString("  yes  ");
    Assert.assertEquals(true, props.booleanProp.get());
    prevString = props.booleanProp.setString("false   ");
    Assert.assertEquals(false, props.booleanProp.get());
    prevString = props.booleanProp.setString("true ");
    Assert.assertEquals(true, props.booleanProp.get());

    // All other values mean false.
    prevString = props.booleanProp.setString("");
    Assert.assertEquals(false, props.booleanProp.get());
    prevString = props.booleanProp.setString("no");
    Assert.assertEquals(false, props.booleanProp.get());
    prevString = props.booleanProp.setString("wombat");
    Assert.assertEquals(false, props.booleanProp.get());
    prevString = props.booleanProp.setString("0");
    Assert.assertEquals(false, props.booleanProp.get());
    prevString = props.booleanProp.setString("false");
    Assert.assertEquals(false, props.booleanProp.get());

    // Setting null is not OK.
    try {
      props.booleanProp.setString(null);
      fail("expected NPE");
    } catch (NullPointerException e) {
      // ok
    }
  }