@org.junit.Test
  public void testGetMissingProperty() {
    FileConfiguration config = new FileConfiguration();

    String val = config.getProperty("test.missing.property");

    if (val != null) {
      fail("'test.missing.property' should not be found");
    }
  }
Esempio n. 2
0
  @Test
  public void testSaveToString() {
    FileConfiguration config = getConfig();

    for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
      config.set(entry.getKey(), entry.getValue());
    }

    String result = config.saveToString();
    String expected = getTestValuesString();

    assertEquals(expected, result);
  }
Esempio n. 3
0
  @Test
  public void testSave_String() throws Exception {
    FileConfiguration config = getConfig();
    File file = testFolder.newFile("test.config");

    for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
      config.set(entry.getKey(), entry.getValue());
    }

    config.save(file.getAbsolutePath());

    assertTrue(file.isFile());
  }
  @org.junit.Test
  public void testGetProperty() {
    FileConfiguration config = new FileConfiguration();

    String val = config.getProperty("test.property");

    if (val == null) {
      fail("'test.property' not found");
    }

    if (val.equals("testvalue") == false) {
      fail("Unexpected value '" + val + "', expecting 'testvalue'");
    }
  }
Esempio n. 5
0
  @Test
  public void testLoadFromString() throws Exception {
    FileConfiguration config = getConfig();
    Map<String, Object> values = getTestValues();
    String saved = getTestValuesString();

    config.loadFromString(saved);

    for (Map.Entry<String, Object> entry : values.entrySet()) {
      assertEquals(entry.getValue(), config.get(entry.getKey()));
    }

    assertEquals(values.keySet(), config.getKeys(true));
  }
Esempio n. 6
0
  @Test
  public void testLoad_String() throws Exception {
    FileConfiguration config = getConfig();
    File file = testFolder.newFile("test.config");
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    String saved = getTestValuesString();
    Map<String, Object> values = getTestValues();

    try {
      writer.write(saved);
    } finally {
      writer.close();
    }

    config.load(file.getAbsolutePath());

    for (Map.Entry<String, Object> entry : values.entrySet()) {
      assertEquals(entry.getValue(), config.get(entry.getKey()));
    }

    assertEquals(values.keySet(), config.getKeys(true));
  }