1 package org.nuiton.version;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import com.google.common.collect.Lists;
26 import org.junit.Assert;
27 import org.junit.Test;
28
29
30
31
32
33
34
35 public class VersionBuilderTest {
36
37 @Test
38 public void testBuildVersionFromString() {
39
40 buildVersion(VersionBuilder.create().build(), "0", 1, false, 0);
41 buildVersion(VersionBuilder.create().setSnapshot(true).build(), "0-SNAPSHOT", 1, true, 0);
42 buildVersion(VersionBuilder.create("0").build(), "0", 1, false, 0);
43 buildVersion(VersionBuilder.create("1").build(), "1", 1, false, 1);
44 buildVersion(VersionBuilder.create("12.3").build(), "12.3", 2, false, 12, 3);
45 buildVersion(VersionBuilder.create("12.34-alpha-56").build(), "12.34-alpha-56", 4, false, 12, 34, "alpha", 56);
46 buildVersion(VersionBuilder.create("1.1-beta-1").build(), "1.1-beta-1", 4, false, 1, 1, "beta", 1);
47 buildVersion(VersionBuilder.create("1.1-rc-1").build(), "1.1-rc-1", 4, false, 1, 1, "rc", 1);
48 buildVersion(VersionBuilder.create("1.1-rc-1-SNAPSHOT").build(), "1.1-rc-1-SNAPSHOT", 4, true, 1, 1, "rc", 1);
49 buildVersion(VersionBuilder.create("1.1-rc2").build(), "1.1-rc2", 4, false, 1, 1, "rc", 2);
50 buildVersion(VersionBuilder.create("1.1-rc2a").build(), "1.1-rc2a", 5, false, 1, 1, "rc", 2, "a");
51
52 }
53
54 @Test
55 public void testBuildVersionFromComponants() {
56
57 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(0)).build(), "0", 1, false, 0);
58 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1)).build(), "1", 1, false, 1);
59 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(12, 3)).build(), "12.3", 2, false, 12, 3);
60 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(12, 34, "alpha", 56)).build(), "12.34.alpha.56", 4, false, 12, 34, "alpha", 56);
61 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "beta", 1)).build(), "1.1.beta.1", 4, false, 1, 1, "beta", 1);
62 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 1)).build(), "1.1.rc.1", 4, false, 1, 1, "rc", 1);
63 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 1)).setSnapshot(true).build(), "1.1.rc.1-SNAPSHOT", 4, true, 1, 1, "rc", 1);
64 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 2)).build(), "1.1.rc.2", 4, false, 1, 1, "rc", 2);
65 buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 2, "a")).build(), "1.1.rc.2.a", 5, false, 1, 1, "rc", 2, "a");
66
67 }
68
69
70 protected void buildVersion(Version version,
71 String stringRepresentation,
72 int nbComponants,
73 boolean snapshot,
74 Comparable... componants) {
75
76 Assert.assertEquals("Bad string represetion", stringRepresentation, version.getVersion());
77 Assert.assertEquals("Bad number of componants", nbComponants, version.getComponantCount());
78 Assert.assertEquals("Bad snapshot value", snapshot, version.isSnapshot());
79 for (int i = 0; i < componants.length; i++) {
80 Comparable componant = componants[i];
81 Assert.assertEquals("Bad componant value at index " + i, componant, version.getComponant(i).getValue());
82 }
83
84 }
85
86 }