YamlConfiguration extends FileConfiguration { @Override public void loadFromString(final String contents) throws InvalidConfigurationException { Validate.notNull(contents, "Contents cannot be null"); final Map<?, ?> input; try { input = this.yaml.load(contents); } catch (final YAMLException e) { throw new InvalidConfigurationException(e); } catch (final ClassCastException e) { throw new InvalidConfigurationException("Top level is not a Map."); } final String header = YamlConfiguration.parseHeader(contents); if (!header.isEmpty()) { this.options().header(header); } if (input != null) { this.convertMapsToSections(input, this); } }  static YamlConfiguration loadConfiguration(final File file); static YamlConfiguration loadConfiguration(final InputStream stream); static YamlConfiguration loadConfiguration(final Reader reader); @Override String saveToString(); @Override void loadFromString(final String contents); @Override YamlConfigurationOptions options();  }
@Test void loadFromString() throws InvalidConfigurationException { final InputStreamOf stream = new InputStreamOf( new ResourceOf("test.yml")); final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(stream); final String newcontent = "test:\n" + " number: 10\n" + " string: Hello world!\n" + " boolean: false\n" + " list:\n" + " - Eachs\n" + " - words\n" + " - wills\n" + " - bes\n" + " - ins\n" + " - as\n" + " - separateds\n" + " - entrys\n" + "math:\n" + " pi: 3.141592653589793\n" + "timestamp:\n" + " canonicalDate: 2020-07-04T13:18:04.458Z\n" + " formattedDate: 04/07/2020 15:18:04\n"; MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getInt("test.number"), new IsEqual<>(5) ); MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getString("test.string"), new IsEqual<>("Hello world") ); MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getBoolean("test.boolean"), new IsEqual<>(true) ); MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getStringList("test.list"), new HasValues<>( "Each", "word", "will", "be", "in", "a", "separated", "entry" ) ); configuration.loadFromString(newcontent); MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getInt("test.number"), new IsEqual<>(10) ); MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getString("test.string"), new IsEqual<>("Hello world!") ); MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getBoolean("test.boolean"), new IsEqual<>(false) ); MatcherAssert.assertThat( "Couldn't load the input stream!", configuration.getStringList("test.list"), new HasValues<>( "Eachs", "words", "wills", "bes", "ins", "as", "separateds", "entrys" ) ); }