Merge branch 'feature-version-compatibility' into bpMaster

This commit is contained in:
martin-rueegg 2017-04-21 22:24:39 +01:00
commit f4a5d34095
2 changed files with 51 additions and 0 deletions

View File

@ -560,6 +560,39 @@ public class Version implements Comparable<Version> {
return compareTo(other) <= 0;
}
/**
* Checks if this version is compatible with the
* other version in terms of their major versions.
*
* When checking compatibility no assumptions
* are made about the versions' precedence.
*
* @param other the other version to check with
* @return {@code true} if this version is compatible with
* the other version or {@code false} otherwise
* @since 0.10.0
*/
public boolean isMajorVersionCompatible(Version other) {
return this.getMajorVersion() == other.getMajorVersion();
}
/**
* Checks if this version is compatible with the
* other version in terms of their minor versions.
*
* When checking compatibility no assumptions
* are made about the versions' precedence.
*
* @param other the other version to check with
* @return {@code true} if this version is compatible with
* the other version or {@code false} otherwise
* @since 0.10.0
*/
public boolean isMinorVersionCompatible(Version other) {
return this.getMajorVersion() == other.getMajorVersion()
&& this.getMinorVersion() == other.getMinorVersion();
}
/**
* Checks if this version equals the other version.
*

View File

@ -314,6 +314,24 @@ public class VersionTest {
assertTrue(v.satisfies(gte("1.0.0").and(lt("2.0.0"))));
assertFalse(v.satisfies(gte("2.0.0").and(lt("3.0.0"))));
}
@Test
public void shouldCheckIfMajorVersionCompatible() {
Version v1 = Version.valueOf("1.0.0");
Version v2 = Version.valueOf("1.2.3");
Version v3 = Version.valueOf("2.0.0");
assertTrue(v1.isMajorVersionCompatible(v2));
assertFalse(v1.isMajorVersionCompatible(v3));
}
@Test
public void shouldCheckIfMinorVersionCompatible() {
Version v1 = Version.valueOf("1.1.1");
Version v2 = Version.valueOf("1.1.2");
Version v3 = Version.valueOf("1.2.3");
assertTrue(v1.isMinorVersionCompatible(v2));
assertFalse(v1.isMinorVersionCompatible(v3));
}
}
public static class EqualsMethodTest {