ElasticVersion: Say 'Unsupported' rather than 'Invalid'

If a version number is not recognized, it is not necessarily invalid,
but could just be because we didn't yet add support for it.

Change the error message to be less aggressive.

Change-Id: I904ff165b7e04ae0c5e7514923a75f6a74e8b005
This commit is contained in:
David Pursehouse
2018-09-04 10:01:22 +09:00
parent 088f2d438a
commit 0753f99d13
2 changed files with 7 additions and 7 deletions

View File

@@ -31,23 +31,23 @@ public enum ElasticVersion {
this.pattern = Pattern.compile(version);
}
public static class InvalidVersion extends ElasticException {
public static class UnsupportedVersion extends ElasticException {
private static final long serialVersionUID = 1L;
InvalidVersion(String version) {
UnsupportedVersion(String version) {
super(
String.format(
"Invalid version: [%s]. Supported versions: %s", version, supportedVersions()));
"Unsupported version: [%s]. Supported versions: %s", version, supportedVersions()));
}
}
public static ElasticVersion forVersion(String version) throws InvalidVersion {
public static ElasticVersion forVersion(String version) throws UnsupportedVersion {
for (ElasticVersion value : ElasticVersion.values()) {
if (value.pattern.matcher(version).matches()) {
return value;
}
}
throw new InvalidVersion(version);
throw new UnsupportedVersion(version);
}
public static String supportedVersions() {

View File

@@ -41,9 +41,9 @@ public class ElasticVersionTest {
@Test
public void unsupportedVersion() throws Exception {
exception.expect(ElasticVersion.InvalidVersion.class);
exception.expect(ElasticVersion.UnsupportedVersion.class);
exception.expectMessage(
"Invalid version: [4.0.0]. Supported versions: " + ElasticVersion.supportedVersions());
"Unsupported version: [4.0.0]. Supported versions: " + ElasticVersion.supportedVersions());
ElasticVersion.forVersion("4.0.0");
}