Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make JBakeConfiguration.addConfiguration() values take precedence #718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}