Skip to content

Commit

Permalink
Make JBakeConfiguration.addConfiguration() values take precedence
Browse files Browse the repository at this point in the history
This closes jbake-org#717
  • Loading branch information
kwin committed Jul 26, 2021
1 parent cec1009 commit 3fb5f8e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public List<Property> getJbakeProperties() {

@Override
public void addConfiguration(Properties properties) {
compositeConfiguration.addConfiguration(new MapConfiguration(properties));
compositeConfiguration.addConfigurationFirst(new MapConfiguration(properties));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public interface JBakeConfiguration {
String getVersion();

/**
* Set a property value for the given key
* Set a property value for the given key.
*
* @param key the key for the property
* @param value the value of the property
Expand Down Expand Up @@ -371,6 +371,10 @@ public interface JBakeConfiguration {

List<Property> getJbakeProperties();

/**
* Adds another configuration whose properties take precedence over the ones already set.
* @param properties
*/
void addConfiguration(Properties properties);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.jbake.app.configuration;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.util.Properties;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class DefaultJBakeConfigurationTest {

@TempDir
File root;

private JBakeConfiguration jBakeConfig;

@BeforeEach
public void setup() {
jBakeConfig = new ConfigUtil().loadConfig(root, null);
}

@Test
public void testAddConfiguration() {
Properties props = new Properties();
props.setProperty("version", "overwritten"); // overwrite property from default.properties
props.setProperty("foo", "bar");
jBakeConfig.addConfiguration(props);
assertEquals("overwritten", jBakeConfig.get("version"));
assertEquals("bar", jBakeConfig.get("foo"));
}

@Test
public void testSetProperty() {
jBakeConfig.setProperty("version", "overwritten"); // overwrite property from default.properties
jBakeConfig.setProperty("foo", "bar");
assertEquals("overwritten", jBakeConfig.get("version"));
assertEquals("bar", jBakeConfig.get("foo"));
}
}

0 comments on commit 3fb5f8e

Please sign in to comment.