Exemplo n.º 1
0
  public static void testGetProperty() {
    Properties props = new Properties();
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");

    System.setProperty("name", "Michelle");
    System.setProperty("name2", "Nicole");
    String retval;

    retval = Util.getProperty(new String[] {"name", "name2"}, props, "name", "Jeannette");
    Assert.assertEquals("Bela", retval);
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");

    retval = Util.getProperty(new String[] {"name2", "name"}, props, "name", "Jeannette");
    Assert.assertEquals("Bela", retval);
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");

    retval = Util.getProperty(new String[] {"name3", "name"}, props, "name", "Jeannette");
    Assert.assertEquals("Bela", retval);
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");

    retval = Util.getProperty(new String[] {"name3", "name4"}, props, "name", "Jeannette");
    Assert.assertEquals("Bela", retval);
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");

    retval = Util.getProperty(new String[] {"name2", "name"}, props, "name", "Jeannette");
    Assert.assertEquals("Bela", retval);
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");

    retval = Util.getProperty(new String[] {"name2", "name"}, props, "name2", "Jeannette");
    Assert.assertEquals("Nicole", retval);
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");

    retval = Util.getProperty(new String[] {"name2", "name"}, props, "name2", null);
    Assert.assertEquals("Nicole", retval);
    props.setProperty("name", "Bela");
    props.setProperty("key", "val");
  }
Exemplo n.º 2
0
  public static void testGetProperty2() {
    String input = "foo, bar,  foobar: 1000";
    String result = Util.getProperty(input);
    assert result != null && result.equals("1000");

    input = "foo, bar,  foobar";
    result = Util.getProperty(input);
    assert result == null;

    System.setProperty("foobar", "900");

    input = "foo, bar,  foobar: 1000";
    result = Util.getProperty(input);
    assert result != null && result.equals("900");

    input = "foo, bar,  foobar";
    result = Util.getProperty(input);
    assert result != null && result.equals("900");

    System.setProperty("bar", "500");
    input = "foo, bar,  foobar: 1000";
    result = Util.getProperty(input);
    assert result != null && result.equals("500");

    input = "foo, bar,  foobar";
    result = Util.getProperty(input);
    assert result != null && result.equals("500");

    System.setProperty("foo", "200");
    input = "foo, bar,  foobar: 1000";
    result = Util.getProperty(input);
    assert result != null && result.equals("200");

    input = "foo, bar,  foobar";
    result = Util.getProperty(input);
    assert result != null && result.equals("200");
  }