Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #73 from SpigotMC/master
Browse files Browse the repository at this point in the history
Implicitly convert Map to Configuration
  • Loading branch information
sleiss authored Aug 25, 2016
2 parents f5be0e0 + 98e3c70 commit 1f65678
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public Object getDefault(String path)

public void set(String path, Object value)
{
if ( value instanceof Map )
{
value = new Configuration( (Map) value, ( defaults == null ) ? null : defaults.getSection( path ) );
}

Configuration section = getSectionFor( path );
if ( section == this )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.StringReader;
import java.io.StringWriter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
Expand Down Expand Up @@ -125,4 +126,18 @@ public void testNull()
Assert.assertEquals( null, conf.get( "null.object" ) );
Assert.assertEquals( "", conf.getString( "null.object" ) );
}

@Test
public void testMapAddition()
{
Configuration conf = ConfigurationProvider.getProvider( YamlConfiguration.class ).load( TEST_DOCUMENT );

conf.set( "addition", Collections.singletonMap( "foo", "bar" ) );

// Order matters
Assert.assertEquals( "bar", conf.getSection( "addition" ).getString( "foo" ) );
Assert.assertEquals( "bar", conf.getString( "addition.foo" ) );

Assert.assertTrue( conf.get( "addition" ) instanceof Configuration );
}
}

0 comments on commit 1f65678

Please sign in to comment.