Fixed overriding of properties

This commit is contained in:
Marcin Grzejszczak
2018-10-16 10:50:24 +02:00
parent 8a10d70ac3
commit 1fa3f9ebe7
5 changed files with 241 additions and 14 deletions

View File

@@ -22,6 +22,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
@@ -518,4 +519,29 @@ public class ReleaserProperties {
+ this.sagan + ", fixedVersions=" + this.fixedVersions + ", metaRelease="
+ this.metaRelease + '}';
}
public ReleaserProperties copy() {
ReleaserProperties copy = new ReleaserProperties();
copy.setFixedVersions(new HashMap<>(this.fixedVersions));
copy.setWorkingDir(this.workingDir);
Git git = new Git();
BeanUtils.copyProperties(this.git, git);
copy.setGit(git);
Gradle gradle = new Gradle();
BeanUtils.copyProperties(this.gradle, gradle);
copy.setGradle(gradle);
Maven maven = new Maven();
BeanUtils.copyProperties(this.maven, maven);
copy.setMaven(maven);
MetaRelease metaRelease = new MetaRelease();
BeanUtils.copyProperties(this.metaRelease, metaRelease);
copy.setMetaRelease(metaRelease);
Pom pom = new Pom();
BeanUtils.copyProperties(this.pom, pom);
copy.setPom(pom);
Sagan sagan = new Sagan();
BeanUtils.copyProperties(this.sagan, sagan);
copy.setSagan(sagan);
return copy;
}
}

View File

@@ -1,5 +1,12 @@
package org.springframework.cloud.release.internal;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Maps;
import org.assertj.core.api.BDDAssertions;
import org.junit.Test;
import static org.assertj.core.api.BDDAssertions.then;
@@ -25,4 +32,55 @@ public class ReleaserPropertiesTests {
then(properties.getWorkingDir()).isNotEmpty();
}
@Test
public void should_return_a_copy_of_properties() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.setWorkingDir("foo");
properties.setFixedVersions(map());
properties.getMaven().setBuildCommand("foo2");
properties.getGradle().setIgnoredGradleRegex(Arrays.asList("foo3", "foo4"));
properties.getMetaRelease().setProjectsToSkip(Arrays.asList("foo5", "foo6"));
properties.getGit().setPassword("foo7");
properties.getPom().setIgnoredPomRegex(Arrays.asList("foo8", "foo9"));
properties.getSagan().setBaseUrl("foo10");
ReleaserProperties copy = properties.copy();
copy.setWorkingDir("bar");
copy.setFixedVersions(map2());
copy.getMaven().setBuildCommand("bar2");
copy.getGradle().setIgnoredGradleRegex(Arrays.asList("bar3", "bar4"));
copy.getMetaRelease().setProjectsToSkip(Arrays.asList("bar5", "bar6"));
copy.getGit().setPassword("bar7");
copy.getPom().setIgnoredPomRegex(Arrays.asList("bar8", "bar9"));
copy.getSagan().setBaseUrl("bar10");
BDDAssertions.then(properties.getWorkingDir())
.isEqualTo("foo");
BDDAssertions.then(properties.getFixedVersions())
.isEqualTo(map());
BDDAssertions.then(properties.getMaven().getBuildCommand())
.isEqualTo("foo2");
BDDAssertions.then(properties.getGradle().getIgnoredGradleRegex())
.isEqualTo(Arrays.asList("foo3", "foo4"));
BDDAssertions.then(properties.getMetaRelease().getProjectsToSkip())
.isEqualTo(Arrays.asList("foo5", "foo6"));
BDDAssertions.then(properties.getGit().getPassword())
.isEqualTo("foo7");
BDDAssertions.then(properties.getPom().getIgnoredPomRegex())
.isEqualTo(Arrays.asList("foo8", "foo9"));
BDDAssertions.then(properties.getSagan().getBaseUrl())
.isEqualTo("foo10");
}
private Map<String, String> map() {
Map<String, String> map = new HashMap<>();
map.put("foo", "bar");
return map;
}
private Map<String, String> map2() {
Map<String, String> map = new HashMap<>();
map.put("bar", "foo");
return map;
}
}