/*
 * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
 * 
 * #SNAPSHOT#
 */
package fr.jayasoft.ivy.latest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import junit.framework.TestCase;

public class LatestRevisionStrategyTest extends TestCase {
    public void testComparator() {
        String[] revs = new String[] {
                "0.2a", 
                "0.2_b", 
                "0.2rc1", 
                "0.2-final", 
                "1.0-dev1", 
                "1.0-dev2", 
                "1.0-alpha1", 
                "1.0-alpha2", 
                "1.0-beta1", 
                "1.0-beta2", 
                "1.0-gamma",
                "1.0-rc1",
                "1.0-rc2",
                "1.0", 
                "1.0.1", 
                "2.0" 
                };
        
        List shuffled = new ArrayList(Arrays.asList(revs)); 
        Collections.shuffle(shuffled);
        Collections.sort(shuffled, new LatestRevisionStrategy().COMPARATOR);
        assertEquals(Arrays.asList(revs), shuffled);
    }
    
    public void testSpecialMeaningComparator() {
        String[] revs = new String[] {
                "0.1", 
                "0.2-pre", 
                "0.2-dev", 
                "0.2-rc1", 
                "0.2-final", 
                "0.2-QA", 
                "1.0-dev1", 
                };
        
        List shuffled = new ArrayList(Arrays.asList(revs)); 
        Collections.shuffle(shuffled);
        LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy();
        LatestRevisionStrategy.SpecialMeaning specialMeaning = new LatestRevisionStrategy.SpecialMeaning();
        specialMeaning.setName("pre");
        specialMeaning.setValue(new Integer(-2));
        latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning);
        specialMeaning = new LatestRevisionStrategy.SpecialMeaning();
        specialMeaning.setName("QA");
        specialMeaning.setValue(new Integer(4));
        latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning);
        Collections.sort(shuffled, latestRevisionStrategy.COMPARATOR);
        assertEquals(Arrays.asList(revs), shuffled);
    }
}

@@ -264,24 +264,64 @@
 il.List;%0D%0A%0D%0A
+import fr.jayasoft.ivy.ArtifactInfo;%0D%0A%0D%0A
 import junit
@@ -342,16 +342,16 @@
 tCase;%0D%0A
-
 %0D%0Apublic
@@ -440,38 +440,44 @@
 or() %7B%0D%0A        
-String
+ArtifactInfo
 %5B%5D revs = new St
@@ -462,32 +462,41 @@
 ctInfo%5B%5D revs = 
+toMockAI(
 new String%5B%5D %7B%0D%0A
@@ -964,32 +964,33 @@
                %7D
+)
 ;%0D%0A        %0D%0A   
@@ -1291,22 +1291,28 @@
         
-String
+ArtifactInfo
 %5B%5D revs 
@@ -1313,16 +1313,25 @@
  revs = 
+toMockAI(
 new Stri
@@ -1556,16 +1556,17 @@
        %7D
+)
 ;%0D%0A     
@@ -2399,18 +2399,801 @@
 fled);%0D%0A
-
     %7D%0D%0A
+%0D%0A    %0D%0A    %0D%0A    private static class MockArtifactInfo implements ArtifactInfo %7B%0D%0A%0D%0A        private long _lastModified;%0D%0A        private String _rev;%0D%0A%0D%0A        public MockArtifactInfo(String rev, long lastModified) %7B%0D%0A            _rev = rev;%0D%0A            _lastModified = lastModified;%0D%0A        %7D%0D%0A%0D%0A        public String getRevision() %7B%0D%0A            return _rev;%0D%0A        %7D%0D%0A%0D%0A        public long getLastModified() %7B%0D%0A            return _lastModified;%0D%0A        %7D%0D%0A        %0D%0A    %7D%0D%0A    private ArtifactInfo%5B%5D toMockAI(String%5B%5D revs) %7B%0D%0A        ArtifactInfo%5B%5D artifactInfos = new ArtifactInfo%5Brevs.length%5D;%0D%0A        for (int i = 0; i %3C artifactInfos.length; i++) %7B%0D%0A            artifactInfos%5Bi%5D = new MockArtifactInfo(revs%5Bi%5D, 0);%0D%0A        %7D%0D%0A        return artifactInfos;%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

integrate comparator api change