Added more checks around parsed versions, added better exception descriptions

This commit is contained in:
Marcin Grzejszczak
2019-01-23 15:03:33 +01:00
parent f4a2ff11a9
commit edd12d85e5
3 changed files with 41 additions and 10 deletions

View File

@@ -180,10 +180,10 @@ public class ProjectVersion {
assertVersionSet();
String[] split = version.split("\\.");
String thatName = split[0];
String thatValue = split[1];
String thatValue = split.length > 1 ? split[1] : "";
String[] thisSplit = this.version.split("\\.");
String thisName = thisSplit[0];
String thisValue = thisSplit[1];
String thisValue = thisSplit.length > 1 ? thisSplit[1] : "";
int nameComparison = thisName.compareTo(thatName);
if (nameComparison != 0) {
return nameComparison;
@@ -218,15 +218,24 @@ class VersionNumber implements Comparable<VersionNumber> {
@Override
public int compareTo(VersionNumber o) {
char thisFirst = this.version.toLowerCase().charAt(0);
char thatFirst = o.version.toLowerCase().charAt(0);
String thisLower = this.version.toLowerCase();
char thisFirst = thisLower.isEmpty() ? ' ' : thisLower.charAt(0);
String thatLower = o.version.toLowerCase();
char thatFirst = thatLower.isEmpty() ? ' ' : thatLower.charAt(0);
// B < M < RC < R < S
int charComparison = Character.compare(thisFirst, thatFirst);
if (charComparison != 0) {
return charComparison;
}
Integer thisNumber = Integer.valueOf(this.version.replaceAll("\\D+",""));
Integer thatNumber = Integer.valueOf(o.version.replaceAll("\\D+",""));
String thisVersion = this.version.replaceAll("\\D+", "");
boolean thisVersionEmpty = StringUtils.isEmpty(this.version);
String thatVersion = o.version.replaceAll("\\D+", "");
boolean thatVersionEmpty = StringUtils.isEmpty(o.version);
if (thisVersionEmpty || thatVersionEmpty) {
return thisVersion.compareTo(thatVersion);
}
Integer thisNumber = Integer.valueOf(thisVersion);
Integer thatNumber = Integer.valueOf(thatVersion);
return thisNumber.compareTo(thatNumber);
}
}

View File

@@ -1,16 +1,17 @@
package org.springframework.cloud.release.internal.pom;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.release.internal.git.GitRepoTests;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
/**
* @author Marcin Grzejszczak
*/
@@ -338,6 +339,27 @@ public class ProjectVersionTests {
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isNegative();
}
@Test
public void should_return_minus_1_when_this_train_is_empty() {
String thisVersion = "";
String thatVersion = "Finchley.SR2";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isNegative();
thisVersion = "";
thatVersion = "";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isZero();
}
@Test
public void should_return_plus_1_when_that_train_is_empty() {
String thisVersion = "Finchley.SR1";
String thatVersion = "";
then(projectVersion(thisVersion).compareToReleaseTrainName(thatVersion)).isPositive();
}
private ProjectVersion projectVersion(String version) {
return new ProjectVersion("foo", version);
}

View File

@@ -91,7 +91,7 @@ class Table {
Exception exception;
Table(String projectName, TaskAndException tae) {
this.projectName = projectName;
this.projectName = StringUtils.hasText(projectName) ? projectName : "Post Release";
this.taskCaption = tae.task.name;
this.taskDescription = tae.task.description;
this.taskState = tae.taskState.name().toLowerCase();