コード例 #1
0
  @Test
  public void testToProperties() throws IOException {
    com.mastfrog.settings.Settings config =
        new SettingsBuilder()
            .addDefaultsFromClasspath()
            .addGeneratedDefaultsFromClasspath()
            .add("com/mastfrog/configuration/others.properties")
            .add("com/mastfrog/configuration/more.properties")
            .add("com/mastfrog/configuration/andmore.properties")
            .build();

    Properties p = config.toProperties();
    assertEquals(
        new HashSet<>(
            Arrays.asList("age", "auto", "bang", "whee", "foo", "abc", "liesel", "monkey")),
        new HashSet<>(p.stringPropertyNames()));
    assertEquals("fiz", p.getProperty("foo"));
  }
コード例 #2
0
  @Test
  public void testLoad() throws IOException {
    com.mastfrog.settings.Settings config =
        new SettingsBuilder()
            .add("com/mastfrog/configuration/others.properties")
            .add("com/mastfrog/configuration/more.properties")
            .build();
    for (String s : config) {
      System.out.println(s + "=" + config.getString(s));
    }
    assertTrue(config.allKeys().contains("whee"));
    assertEquals("oobiedoobie", config.getString("whee"));
    assertTrue(config.allKeys().contains("foo"));
    assertEquals("fiz", config.getString("foo"));

    config =
        new SettingsBuilder()
            .add("com/mastfrog/configuration/others.properties")
            .add("com/mastfrog/configuration/more.properties")
            .add("com/mastfrog/configuration/andmore.properties")
            .build();
    assertTrue(config.allKeys().contains("abc"));
    assertEquals("def", config.getString("abc"));
  }