Procházet zdrojové kódy

add comparison test

tags/2.0.1
Jonathan Cobb před 3 roky
rodič
revize
4bd7d4c2ab
1 změnil soubory, kde provedl 27 přidání a 6 odebrání
  1. +27
    -6
      wizard-server/src/test/java/org/cobbzilla/model/SemanticVersionTest.java

+ 27
- 6
wizard-server/src/test/java/org/cobbzilla/model/SemanticVersionTest.java Zobrazit soubor

@@ -1,10 +1,12 @@
package org.cobbzilla.model;

import org.apache.bcel.generic.NEW;
import org.apache.commons.lang3.StringUtils;
import org.cobbzilla.wizard.model.SemanticVersion;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.cobbzilla.wizard.model.SemanticVersion.isNewerVersion;
import static org.junit.Assert.*;

public class SemanticVersionTest {

@@ -12,16 +14,22 @@ public class SemanticVersionTest {
{ "0.0.0", new SemanticVersion(0, 0, 0) },
{ "1.2.3" , new SemanticVersion(1, 2, 3) },
{ "12.1.0", new SemanticVersion(12, 1, 0) },
{ "1.2.3.4", new SemanticVersion(1, 2, 3, 4) },
};

@Test
public void testValidVersions () {
@Test public void testValidVersions () {
for (Object[] test : VALID_VERSIONS) {
final SemanticVersion v = new SemanticVersion(test[0].toString());
final SemanticVersion expected = (SemanticVersion) test[1];
assertEquals(expected.getMajor(), v.getMajor());
assertEquals(expected.getMinor(), v.getMinor());
assertEquals(expected.getPatch(), v.getPatch());
if (StringUtils.countMatches(test[0].toString(), '.') == 3) {
assertEquals(expected.getBuild(), v.getBuild());
} else {
assertNull(expected.getBuild());
assertNull(v.getBuild());
}
assertEquals(expected, v);
}
}
@@ -30,8 +38,7 @@ public class SemanticVersionTest {
"", ".", "0.", "1.0", "0.0.", "a.1.0", "1. 0 . 5", "1.0.0.x"
};

@Test
public void testInvalidVersions () {
@Test public void testInvalidVersions () {
for (String test : INVALID_VERSIONS) {
try {
final SemanticVersion v = new SemanticVersion(test);
@@ -40,4 +47,18 @@ public class SemanticVersionTest {
}
}

public static final String[][] NEWER_COMPARISONS = {
{"1.0.1", "1.0.0"},
{"1.0.1.1", "1.0.0"},
{"1.2.3", "1.2.2"},
};

@Test public void testNewerVersions () {
for (String[] versions : NEWER_COMPARISONS) {
final String v1 = versions[0];
final String v2 = versions[1];
assertTrue("expected "+v1+ " to be considered newer than "+v2, isNewerVersion(v2, v1));
}
}

}

Načítá se…
Zrušit
Uložit