KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > latest > LatestRevisionStrategyTest


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.latest;
7
8 import java.util.ArrayList JavaDoc;
9 import java.util.Arrays JavaDoc;
10 import java.util.Collections JavaDoc;
11 import java.util.List JavaDoc;
12
13 import fr.jayasoft.ivy.ArtifactInfo;
14
15 import junit.framework.TestCase;
16
17 public class LatestRevisionStrategyTest extends TestCase {
18     public void testComparator() {
19         ArtifactInfo[] revs = toMockAI(new String JavaDoc[] {
20                 "0.2a",
21                 "0.2_b",
22                 "0.2rc1",
23                 "0.2-final",
24                 "1.0-dev1",
25                 "1.0-dev2",
26                 "1.0-alpha1",
27                 "1.0-alpha2",
28                 "1.0-beta1",
29                 "1.0-beta2",
30                 "1.0-gamma",
31                 "1.0-rc1",
32                 "1.0-rc2",
33                 "1.0",
34                 "1.0.1",
35                 "2.0"
36                 });
37         
38         List JavaDoc shuffled = new ArrayList JavaDoc(Arrays.asList(revs));
39         Collections.shuffle(shuffled);
40         Collections.sort(shuffled, new LatestRevisionStrategy().COMPARATOR);
41         assertEquals(Arrays.asList(revs), shuffled);
42     }
43     
44     public void testSpecialMeaningComparator() {
45         ArtifactInfo[] revs = toMockAI(new String JavaDoc[] {
46                 "0.1",
47                 "0.2-pre",
48                 "0.2-dev",
49                 "0.2-rc1",
50                 "0.2-final",
51                 "0.2-QA",
52                 "1.0-dev1",
53                 });
54         
55         List JavaDoc shuffled = new ArrayList JavaDoc(Arrays.asList(revs));
56         Collections.shuffle(shuffled);
57         LatestRevisionStrategy latestRevisionStrategy = new LatestRevisionStrategy();
58         LatestRevisionStrategy.SpecialMeaning specialMeaning = new LatestRevisionStrategy.SpecialMeaning();
59         specialMeaning.setName("pre");
60         specialMeaning.setValue(new Integer JavaDoc(-2));
61         latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning);
62         specialMeaning = new LatestRevisionStrategy.SpecialMeaning();
63         specialMeaning.setName("QA");
64         specialMeaning.setValue(new Integer JavaDoc(4));
65         latestRevisionStrategy.addConfiguredSpecialMeaning(specialMeaning);
66         Collections.sort(shuffled, latestRevisionStrategy.COMPARATOR);
67         assertEquals(Arrays.asList(revs), shuffled);
68     }
69
70     
71     
72     private static class MockArtifactInfo implements ArtifactInfo {
73
74         private long _lastModified;
75         private String JavaDoc _rev;
76
77         public MockArtifactInfo(String JavaDoc rev, long lastModified) {
78             _rev = rev;
79             _lastModified = lastModified;
80         }
81
82         public String JavaDoc getRevision() {
83             return _rev;
84         }
85
86         public long getLastModified() {
87             return _lastModified;
88         }
89         
90     }
91     private ArtifactInfo[] toMockAI(String JavaDoc[] revs) {
92         ArtifactInfo[] artifactInfos = new ArtifactInfo[revs.length];
93         for (int i = 0; i < artifactInfos.length; i++) {
94             artifactInfos[i] = new MockArtifactInfo(revs[i], 0);
95         }
96         return artifactInfos;
97     }
98
99 }
100
Popular Tags