Ensuring that we don't set empty versions
This commit is contained in:
@@ -36,6 +36,7 @@ import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
|
||||
import org.codehaus.stax2.XMLInputFactory2;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
import static org.springframework.util.StringUtils.isEmpty;
|
||||
@@ -324,6 +325,10 @@ class PropertyStorer {
|
||||
|
||||
private boolean setPropertyVersion(String propertyName, String version) {
|
||||
try {
|
||||
if (StringUtils.isEmpty(version)) {
|
||||
this.log.warn("Version for [" + propertyName + "] is empty. Will not set it");
|
||||
return false;
|
||||
}
|
||||
return PomHelper.setPropertyVersion(this.pom, null, propertyName, version);
|
||||
}
|
||||
catch (XMLStreamException e) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.springframework.cloud.release.internal.pom;
|
||||
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.BDDMockito.then;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PropertyStorerTests {
|
||||
|
||||
@Mock Log log;
|
||||
@Mock ModifiedPomXMLEventReader pom;
|
||||
@InjectMocks PropertyStorer propertyStorer;
|
||||
|
||||
@Test public void should_not_set_a_version_when_its_empty() throws Exception {
|
||||
this.propertyStorer.setPropertyVersionIfApplicable(new Project("foo", ""));
|
||||
|
||||
then(this.log).should().warn(containsWarnMsgAboutEmptyVersion());
|
||||
}
|
||||
|
||||
private String containsWarnMsgAboutEmptyVersion() {
|
||||
return BDDMockito.argThat(new TypeSafeMatcher<String>() {
|
||||
@Override protected boolean matchesSafely(String item) {
|
||||
return item.contains("is empty. Will not set it");
|
||||
}
|
||||
|
||||
@Override public void describeTo(Description description) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user