package org.cobbzilla.model;

import org.cobbzilla.wizard.model.SemanticVersion;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class SemanticVersionTest {

    public static final Object[][] VALID_VERSIONS = {
            { "0.0.0", new SemanticVersion(0, 0, 0) },
            { "1.2.3" , new SemanticVersion(1, 2, 3) },
            { "12.1.0", new SemanticVersion(12, 1, 0) },
    };

    @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());
            assertEquals(expected, v);
        }
    }

    public static final String[] INVALID_VERSIONS = {
            "", ".", "0.", "1.0", "0.0.", "a.1.0", "1. 0 . 5", "1.0.0.x"
    };

    @Test
    public void testInvalidVersions () {
        for (String test : INVALID_VERSIONS) {
            try {
                final SemanticVersion v = new SemanticVersion(test);
                fail("expected version to be invalid: "+test+", got version="+v);
            } catch (Exception ignored) {}
        }
    }

}

@@ -23,16 +23,97 @@
 model;%0A%0A
+import org.apache.bcel.generic.NEW;%0Aimport org.apache.commons.lang3.StringUtils;%0A
 import o
@@ -201,33 +201,61 @@
 org.
-junit.Assert.assertEquals
+cobbzilla.wizard.model.SemanticVersion.isNewerVersion
 ;%0Aim
@@ -283,20 +283,17 @@
 .Assert.
-fail
+*
 ;%0A%0Apubli
@@ -541,24 +541,84 @@
 2, 1, 0) %7D,%0A
+            %7B %221.2.3.4%22, new SemanticVersion(1, 2, 3, 4) %7D,%0A
     %7D;%0A%0A    
@@ -614,36 +614,32 @@
    %7D;%0A%0A    @Test
-%0A   
  public void tes
@@ -1035,24 +1035,289 @@
 etPatch());%0A
+            if (StringUtils.countMatches(test%5B0%5D.toString(), '.') == 3) %7B%0A                assertEquals(expected.getBuild(), v.getBuild());%0A            %7D else %7B%0A                assertNull(expected.getBuild());%0A                assertNull(v.getBuild());%0A            %7D%0A
             
@@ -1504,20 +1504,16 @@
    @Test
-%0A   
  public 
@@ -1818,10 +1818,475 @@
 %0A    %7D%0A%0A
+    public static final String%5B%5D%5B%5D NEWER_COMPARISONS = %7B%0A            %7B%221.0.1%22, %221.0.0%22%7D,%0A            %7B%221.0.1.1%22, %221.0.0%22%7D,%0A            %7B%221.2.3%22, %221.2.2%22%7D,%0A    %7D;%0A%0A    @Test public void testNewerVersions () %7B%0A        for (String%5B%5D versions : NEWER_COMPARISONS) %7B%0A            final String v1 = versions%5B0%5D;%0A            final String v2 = versions%5B1%5D;%0A            assertTrue(%22expected %22+v1+ %22 to be considered newer than %22+v2, isNewerVersion(v2, v1));%0A        %7D%0A    %7D%0A%0A
 %7D%0A

add comparison test