diff --git a/.gitignore b/.gitignore index d7f0f2a4..e73a9e03 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target .classpath .project .settings +test-output diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 3b95e87a..e060d195 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -16,6 +16,30 @@ ### API Changes + * [Fixed Issue 215][issue-215] + + The JenkinsServer class will return `JenkinsVersion` instead of String if you + call `getJenkinsVersion()`. + +```java +public class JenkinsVersion ... { + public boolean isGreaterThan(String version); + public boolean isGreaterOrEqual(String version); + public boolean isLessThan(String version); + public boolean isLessOrEqual(String version); + public boolean isEqualTo(String version); +} +``` + + The `JenkinsVersion` class can be used to compare different versions with + each other. + +```java +JenkinsVersion jv = new JenkinsVersion("1.651.1"); +assertThat(jv.isGreaterThan("1.651.1")).isFalse(); +``` + + * [Fixed issue 184][issue-184] Based on the differences between getting a TestReport for a MavenJob type and @@ -916,6 +940,7 @@ TestReport testReport = mavenJob.getLastSuccessfulBuild().getTestReport(); [issue-207]: https://github.com/jenkinsci/java-client-api/issues/207 [issue-209]: https://github.com/jenkinsci/java-client-api/issues/209 [issue-211]: https://github.com/jenkinsci/java-client-api/issues/211 +[issue-215]: https://github.com/jenkinsci/java-client-api/issues/215 [pull-123]: https://github.com/jenkinsci/java-client-api/pull/123 [pull-149]: https://github.com/jenkinsci/java-client-api/pull/149 [pull-158]: https://github.com/jenkinsci/java-client-api/pull/158 diff --git a/jenkins-client-it-docker/pom.xml b/jenkins-client-it-docker/pom.xml index f5ee00c9..ff75e20b 100644 --- a/jenkins-client-it-docker/pom.xml +++ b/jenkins-client-it-docker/pom.xml @@ -82,7 +82,7 @@ - http://192.168.99.100:8080 + http://127.0.0.1:8080 diff --git a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java index 279b844d..451e7585 100644 --- a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java +++ b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedGetJobXmlIT.java @@ -19,15 +19,31 @@ public void beforeMethod() throws IOException { jobXml = jenkinsServer.getJobXml("test"); } - private static final String[] CONFIG_XML = { "", "", " ", - " This is the description with umlauts äöü", - " false", " ", " ", - " true", " false", - " false", - " false", " ", - " false", " ", " ", - " echo "test"", " ", " ", - " ", " ", "" }; + //@formatter:off + private static final String[] CONFIG_XML = { + "", + "", + " ", + " This is the description with umlauts äöü", + " false", + " ", + " ", + " true", + " false", + " false", + " false", + " ", + " false", + " ", + " ", + " echo "test"", + " ", + " ", + " ", + " ", + "" + }; + //@formatter:on @Test public void getJobXmlShouldReturnTheExpectedConfigXml() { diff --git a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedPluginManagerIT.java b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedPluginManagerIT.java index 9c44a71e..bf39e06e 100644 --- a/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedPluginManagerIT.java +++ b/jenkins-client-it-docker/src/test/java/com/offbytwo/jenkins/integration/NoExecutorStartedPluginManagerIT.java @@ -3,13 +3,13 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; -import java.util.Arrays; import java.util.List; import org.testng.SkipException; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import com.offbytwo.jenkins.helper.JenkinsVersion; import com.offbytwo.jenkins.model.Plugin; import com.offbytwo.jenkins.model.PluginManager; @@ -26,18 +26,17 @@ public void beforeMethod() throws IOException { @Test public void getPluginsShouldReturn9ForJenkins20() { // TODO: Check why there is such a difference in the number of Plugins? - if (!jenkinsServer.getVersion().equals("2.0")) { - throw new SkipException("Not Version 2.0"); + if (jenkinsServer.getVersion().isLessThan("2.0")) { + throw new SkipException("Not Version 2.0 (" + jenkinsServer.getVersion() + ")"); } assertThat(pluginManager.getPlugins()).hasSize(9); } @Test public void getPluginsShouldReturn27ForJenkins1651() { - List asList = Arrays.asList("1.651", "1.651.1", "1.651.2", "1.651.3"); - // TODO: Check why there is such a difference in the number of Plugins? - if (!asList.contains(jenkinsServer.getVersion())) { - throw new SkipException("Not Version 1.651"); + JenkinsVersion jv = jenkinsServer.getVersion(); + if (jv.isLessThan("1.651") && jv.isGreaterThan("1.651.3")) { + throw new SkipException("Not Version 1.651 (" + jv.toString() + ")"); } assertThat(pluginManager.getPlugins()).hasSize(27); } @@ -52,8 +51,8 @@ private Plugin createPlugin(String shortName, String version) { @Test public void getPluginsShouldReturnTheListOfInstalledPluginsForJenkins20() { - if (!jenkinsServer.getVersion().equals("2.0")) { - throw new SkipException("Not Version 2.0"); + if (jenkinsServer.getVersion().isLessThan("2.0")) { + throw new SkipException("Not Version 2.0 (" + jenkinsServer.getVersion() + ")"); } // TODO: The list of plugins is contained in the plugin.txt @@ -91,12 +90,12 @@ public void getPluginsShouldReturnTheListOfInstalledPluginsForJenkins20() { @Test public void getPluginsShouldReturnTheListOfInstalledPluginsFor1651() { - List asList = Arrays.asList("1.651", "1.651.1", "1.651.2", "1.651.3"); + JenkinsVersion jv = jenkinsServer.getVersion(); + if (jv.isLessThan("1.651") && jv.isGreaterThan("1.651.3")) { + throw new SkipException("Not Version 1.651 (" + jv + ")"); + } // TODO: Check why there is such a difference in the number of Plugins? - if (!asList.contains(jenkinsServer.getVersion())) { - throw new SkipException("Not Version 1.651"); - } // TODO: The list of plugins is contained in the plugin.txt // which should be read and used as base of comparison. // instead of maintaining at two locations. diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java index 5be7961a..5982408e 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/JenkinsServer.java @@ -26,6 +26,7 @@ import com.google.common.collect.Maps; import com.offbytwo.jenkins.client.JenkinsHttpClient; import com.offbytwo.jenkins.client.util.EncodingUtils; +import com.offbytwo.jenkins.helper.JenkinsVersion; import com.offbytwo.jenkins.model.Build; import com.offbytwo.jenkins.model.Computer; import com.offbytwo.jenkins.model.ComputerSet; @@ -100,15 +101,16 @@ public boolean isRunning() { } /** - * @return The Jenkins version. + * @return {@link JenkinsVersion} */ - public String getVersion() { + public JenkinsVersion getVersion() { if (client.getJenkinsVersion().isEmpty()) { // Force a request to get at least once // HttpHeader isRunning(); } - return client.getJenkinsVersion(); + JenkinsVersion jv = new JenkinsVersion(client.getJenkinsVersion()); + return jv; } /** diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/ComparableVersion.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/ComparableVersion.java new file mode 100644 index 00000000..53579aa0 --- /dev/null +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/ComparableVersion.java @@ -0,0 +1,505 @@ +package com.offbytwo.jenkins.helper; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Properties; +import java.util.Stack; + +/** + * This code is copied from Maven Core with slight modifications. Generic implementation of version comparison. + *

+ * Features: + *

    + *
  • mixing of '-' (hyphen) and '.' (dot) separators,
  • + *
  • transition between characters and digits also constitutes a separator: + * 1.0alpha1 => [1, 0, alpha, 1]
  • + *
  • unlimited number of version components,
  • + *
  • version components in the text can be digits or strings,
  • + *
  • strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering. Well-known + * qualifiers (case insensitive) are: + *
      + *
    • alpha or a
    • + *
    • beta or b
    • + *
    • milestone or m
    • + *
    • rc or cr
    • + *
    • snapshot
    • + *
    • (the empty string) or ga or final
    • + *
    • sp
    • + *
    + * Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive),
  • + *
  • a hyphen usually precedes a qualifier, and is always less important than something preceded with a dot.
  • + *
+ *

+ * + * @see "Versioning" on Maven Wiki + * @author Kenney Westerhof + * @author Hervé Boutemy + */ +public class ComparableVersion + implements Comparable +{ + private String value; + + private String canonical; + + private ListItem items; + + interface Item + { + int INTEGER_ITEM = 0; + + int STRING_ITEM = 1; + + int LIST_ITEM = 2; + + int compareTo( Item item ); + + int getType(); + + boolean isNull(); + } + + /** + * Represents a numeric item in the version item list. + */ + static class IntegerItem + implements Item + { + private static final BigInteger BIG_INTEGER_ZERO = new BigInteger( "0" ); + + private final BigInteger value; + + public static final IntegerItem ZERO = new IntegerItem(); + + private IntegerItem() + { + this.value = BIG_INTEGER_ZERO; + } + + public IntegerItem( String str ) + { + this.value = new BigInteger( str ); + } + + public int getType() + { + return INTEGER_ITEM; + } + + public boolean isNull() + { + return BIG_INTEGER_ZERO.equals( value ); + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + return BIG_INTEGER_ZERO.equals( value ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + } + + switch ( item.getType() ) + { + case INTEGER_ITEM: + return value.compareTo( ( (IntegerItem) item ).value ); + + case STRING_ITEM: + return 1; // 1.1 > 1-sp + + case LIST_ITEM: + return 1; // 1.1 > 1-1 + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + return value.toString(); + } + } + + /** + * Represents a string in the version item list, usually a qualifier. + */ + static class StringItem + implements Item + { + private static final List QUALIFIERS = + Arrays.asList( "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" ); + + private static final Properties ALIASES = new Properties(); + static + { + ALIASES.put( "ga", "" ); + ALIASES.put( "final", "" ); + ALIASES.put( "cr", "rc" ); + } + + /** + * A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes + * the version older than one without a qualifier, or more recent. + */ + private static final String RELEASE_VERSION_INDEX = String.valueOf( QUALIFIERS.indexOf( "" ) ); + + private String value; + + public StringItem( String value, boolean followedByDigit ) + { + if ( followedByDigit && value.length() == 1 ) + { + // a1 = alpha-1, b1 = beta-1, m1 = milestone-1 + switch ( value.charAt( 0 ) ) + { + case 'a': + value = "alpha"; + break; + case 'b': + value = "beta"; + break; + case 'm': + value = "milestone"; + break; + default: + } + } + this.value = ALIASES.getProperty( value, value ); + } + + public int getType() + { + return STRING_ITEM; + } + + public boolean isNull() + { + return ( comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ) == 0 ); + } + + /** + * Returns a comparable value for a qualifier. This method takes into account the ordering of known qualifiers + * then unknown qualifiers with lexical ordering. just returning an Integer with the index here is faster, but + * requires a lot of if/then/else to check for -1 or QUALIFIERS.size and then resort to lexical ordering. Most + * comparisons are decided by the first character, so this is still fast. If more characters are needed then it + * requires a lexical sort anyway. + * + * @param qualifier + * @return an equivalent value that can be used with lexical comparison + */ + public static String comparableQualifier( String qualifier ) + { + int i = QUALIFIERS.indexOf( qualifier ); + + return i == -1 ? ( QUALIFIERS.size() + "-" + qualifier ) : String.valueOf( i ); + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + // 1-rc < 1, 1-ga > 1 + return comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ); + } + switch ( item.getType() ) + { + case INTEGER_ITEM: + return -1; // 1.any < 1.1 ? + + case STRING_ITEM: + return comparableQualifier( value ).compareTo( comparableQualifier( ( (StringItem) item ).value ) ); + + case LIST_ITEM: + return -1; // 1.any < 1-1 + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + return value; + } + } + + /** + * Represents a version list item. This class is used both for the global item list and for sub-lists (which start + * with '-(number)' in the version specification). + */ + public static class ListItem + extends ArrayList + implements Item + { + public int getType() + { + return LIST_ITEM; + } + + public boolean isNull() + { + return ( size() == 0 ); + } + + void normalize() + { + for ( int i = size() - 1; i >= 0; i-- ) + { + Item lastItem = get( i ); + + if ( lastItem.isNull() ) + { + // remove null trailing items: 0, "", empty list + remove( i ); + } + else if ( !( lastItem instanceof ListItem ) ) + { + break; + } + } + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + if ( size() == 0 ) + { + return 0; // 1-0 = 1- (normalize) = 1 + } + Item first = get( 0 ); + return first.compareTo( null ); + } + switch ( item.getType() ) + { + case INTEGER_ITEM: + return -1; // 1-1 < 1.0.x + + case STRING_ITEM: + return 1; // 1-1 > 1-sp + + case LIST_ITEM: + Iterator left = iterator(); + Iterator right = ( (ListItem) item ).iterator(); + + while ( left.hasNext() || right.hasNext() ) + { + Item l = left.hasNext() ? left.next() : null; + Item r = right.hasNext() ? right.next() : null; + + // if this is shorter, then invert the compare and mul with -1 + int result = l == null ? ( r == null ? 0 : -1 * r.compareTo( l ) ) : l.compareTo( r ); + + if ( result != 0 ) + { + return result; + } + } + + return 0; + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + StringBuilder buffer = new StringBuilder(); + for ( Item item : this ) + { + if ( buffer.length() > 0 ) + { + buffer.append( ( item instanceof ListItem ) ? '-' : '.' ); + } + buffer.append( item ); + } + return buffer.toString(); + } + } + + public ComparableVersion( String version ) + { + parseVersion( version ); + } + + public final void parseVersion( String version ) + { + this.value = version; + + items = new ListItem(); + + version = version.toLowerCase( Locale.ENGLISH ); + + ListItem list = items; + + Stack stack = new Stack<>(); + stack.push( list ); + + boolean isDigit = false; + + int startIndex = 0; + + for ( int i = 0; i < version.length(); i++ ) + { + char c = version.charAt( i ); + + if ( c == '.' ) + { + if ( i == startIndex ) + { + list.add( IntegerItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + } + else if ( c == '-' ) + { + if ( i == startIndex ) + { + list.add( IntegerItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + + list.add( list = new ListItem() ); + stack.push( list ); + } + else if ( Character.isDigit( c ) ) + { + if ( !isDigit && i > startIndex ) + { + list.add( new StringItem( version.substring( startIndex, i ), true ) ); + startIndex = i; + + list.add( list = new ListItem() ); + stack.push( list ); + } + + isDigit = true; + } + else + { + if ( isDigit && i > startIndex ) + { + list.add( parseItem( true, version.substring( startIndex, i ) ) ); + startIndex = i; + + list.add( list = new ListItem() ); + stack.push( list ); + } + + isDigit = false; + } + } + + if ( version.length() > startIndex ) + { + list.add( parseItem( isDigit, version.substring( startIndex ) ) ); + } + + while ( !stack.isEmpty() ) + { + list = (ListItem) stack.pop(); + list.normalize(); + } + + canonical = items.toString(); + } + + private static Item parseItem( boolean isDigit, String buf ) + { + return isDigit ? new IntegerItem( buf ) : new StringItem( buf, false ); + } + + public int compareTo( ComparableVersion o ) + { + return items.compareTo( o.items ); + } + + public String toString() + { + return value; + } + + public String getCanonical() + { + return canonical; + } + + public boolean equals( Object o ) + { + return ( o instanceof ComparableVersion ) && canonical.equals( ( (ComparableVersion) o ).canonical ); + } + + public int hashCode() + { + return canonical.hashCode(); + } + + public ListItem getItems() + { + return this.items; + } + + /** + * Main to test version parsing and comparison. + * + * @param args the version strings to parse and compare + */ + public static void main( String... args ) + { + System.out.println( "Display parameters as parsed by Maven (in canonical form) and comparison result:" ); + if ( args.length == 0 ) + { + return; + } + + ComparableVersion prev = null; + int i = 1; + for ( String version : args ) + { + ComparableVersion c = new ComparableVersion( version ); + + if ( prev != null ) + { + int compare = prev.compareTo( c ); + System.out.println( " " + prev.toString() + ' ' + + ( ( compare == 0 ) ? "==" : ( ( compare < 0 ) ? "<" : ">" ) ) + ' ' + version ); + } + + System.out.println( String.valueOf( i++ ) + ". " + version + " == " + c.getCanonical() ); + + prev = c; + } + } +} diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/JenkinsVersion.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/JenkinsVersion.java new file mode 100644 index 00000000..66d1fc95 --- /dev/null +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/JenkinsVersion.java @@ -0,0 +1,114 @@ +package com.offbytwo.jenkins.helper; + +public class JenkinsVersion implements Comparable { + private ComparableVersion cv; + private String literalVersion; + + public final static JenkinsVersion create(String version) { + JenkinsVersion jv = new JenkinsVersion(version); + return jv; + } + + public JenkinsVersion() { + this.cv = new ComparableVersion("0"); + } + + public JenkinsVersion(String version) { + this.literalVersion = version; + this.cv = new ComparableVersion(version); + } + + /** + * This will check if the current instance version is > the + * given version. + * + * @param version The version to compare with. + * @return true or false. + */ + public boolean isGreaterThan(String version) { + JenkinsVersion create = create(version); + return this.cv.compareTo(create.cv) > 0; + } + + public boolean isGreaterThan(JenkinsVersion jv) { + return this.cv.compareTo(jv.cv) > 0; + } + + /** + * This will check if the current instance version is >= the + * given version. + * + * @param version The version to compare with. + * @return true or false. + */ + public boolean isGreaterOrEqual(String version) { + JenkinsVersion create = create(version); + return this.cv.compareTo(create.cv) >= 0; + } + + public boolean isGreaterOrEqual(JenkinsVersion jv) { + return this.cv.compareTo(jv.cv) >= 0; + } + + /** + * This will check if the current instance version is < the + * given version. + * + * @param version The version to compare with. + * @return true or false. + */ + public boolean isLessThan(String version) { + JenkinsVersion create = create(version); + return this.cv.compareTo(create.cv) < 0; + } + + public boolean isLessThan(JenkinsVersion jv) { + return this.cv.compareTo(jv.cv) < 0; + } + + /** + * This will check if the current instance version is <= the + * given version. + * + * @param version The version to compare with. + * @return true or false. + */ + public boolean isLessOrEqual(String version) { + JenkinsVersion create = create(version); + return this.cv.compareTo(create.cv) <= 0; + } + + public boolean isLessOrEqual(JenkinsVersion jv) { + return this.cv.compareTo(jv.cv) <= 0; + } + + /** + * This will check if the current instance version is = the + * given version. + * + * @param version The version to compare with. + * @return true or false. + */ + public boolean isEqualTo(String version) { + JenkinsVersion create = create(version); + return this.cv.compareTo(create.cv) == 0; + } + + public boolean isEqualTo(JenkinsVersion jv) { + return this.cv.compareTo(jv.cv) == 0; + } + + @Override + public int compareTo(JenkinsVersion o) { + return this.compareTo(o); + } + + public String getLiteralVersion() { + return literalVersion; + } + + @Override + public String toString() { + return literalVersion; + } +} \ No newline at end of file diff --git a/jenkins-client/src/test/java/com/offbytwo/jenkins/helper/JenkinsVersionTest.java b/jenkins-client/src/test/java/com/offbytwo/jenkins/helper/JenkinsVersionTest.java new file mode 100644 index 00000000..e55a24ae --- /dev/null +++ b/jenkins-client/src/test/java/com/offbytwo/jenkins/helper/JenkinsVersionTest.java @@ -0,0 +1,139 @@ +package com.offbytwo.jenkins.helper; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class JenkinsVersionTest { + + @Test + public void isGreaterThanTrue() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isGreaterThan("1.548")).isTrue(); + } + + @Test + public void isGreaterThanFalse() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isGreaterThan("1.651.1")).isFalse(); + } + + @Test + public void isGreaterThanTrueJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.548"); + assertThat(a.isGreaterThan(b)).isTrue(); + } + + @Test + public void isGreaterThanFalseJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.1"); + assertThat(a.isGreaterThan(b)).isFalse(); + } + + @Test + public void isEqualToTrue() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isEqualTo("1.651.1")).isTrue(); + } + + @Test + public void isEqualToFalse() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isEqualTo("1.651.0")).isFalse(); + } + + @Test + public void isEqualToTrueJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.1"); + assertThat(a.isEqualTo(b)).isTrue(); + } + + @Test + public void isEqualToFalseJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.0"); + assertThat(a.isEqualTo(b)).isFalse(); + } + + @Test + public void isGreaterOrEqualTrue() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isGreaterOrEqual("1.651.1")).isTrue(); + } + + @Test + public void isGreaterOrEqualFalse() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isGreaterOrEqual("1.651.2")).isFalse(); + } + + @Test + public void isGreaterOrEqualTrueJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.1"); + assertThat(a.isGreaterOrEqual(b)).isTrue(); + } + + @Test + public void isGreaterOrEqualFalseJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.2"); + assertThat(a.isGreaterOrEqual(b)).isFalse(); + } + + @Test + public void isLessOrEqualTrue() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isLessOrEqual("1.651.1")).isTrue(); + } + + @Test + public void isLessOrEqualFalse() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isLessOrEqual("1.651.0")).isFalse(); + } + + @Test + public void isLessOrEqualTrueJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.1"); + assertThat(a.isLessOrEqual(b)).isTrue(); + } + + @Test + public void isLessOrEqualFalseJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.0"); + assertThat(a.isLessOrEqual(b)).isFalse(); + } + + @Test + public void isLessThanTrue() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isLessThan("1.651.2")).isTrue(); + } + + @Test + public void isLessThanFalse() { + JenkinsVersion jv = new JenkinsVersion("1.651.1"); + assertThat(jv.isLessThan("1.651.1")).isFalse(); + } + + @Test + public void isLessThanTrueJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.2"); + assertThat(a.isLessThan(b)).isTrue(); + } + + @Test + public void isLessThanFalseJenkinsVersion() { + JenkinsVersion a = new JenkinsVersion("1.651.1"); + JenkinsVersion b = new JenkinsVersion("1.651.1"); + assertThat(a.isLessThan(b)).isFalse(); + } + +}