Skip to main content
summaryrefslogtreecommitdiffstats
blob: f1ed1fa13e1d0fe2605ffeb24ac54fbdbfeac34b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*******************************************************************************
 * Copyright (c) 2013, 2015 Tasktop Technologies and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.gerrit.tests.core.client;

import static org.eclipse.mylyn.internal.gerrit.core.client.GerritVersion.isVersion2112OrLater;
import static org.eclipse.mylyn.internal.gerrit.core.client.GerritVersion.parseGerritVersion;
import junit.framework.TestCase;

import org.junit.Test;
import org.osgi.framework.Version;

public class GerritVersionTest extends TestCase {

	@Test
	public void testParse_null() throws Exception {
		try {
			parseGerritVersion(null);
			fail("Expected IllegalArgumentException");
		} catch (IllegalArgumentException e) {
			// expected
		}
	}

	@Test
	public void testParse_empty() throws Exception {
		try {
			parseGerritVersion("");
			fail("Expected IllegalArgumentException");
		} catch (IllegalArgumentException e) {
			// expected
		}
	}

	@Test
	public void testParse_invalid() throws Exception {
		try {
			parseGerritVersion("invalid");
			fail("Expected IllegalArgumentException");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().startsWith("Unrecognized version"));
		}
	}

	@Test
	public void testParse_21() throws Exception {
		Version v = parseGerritVersion("2.1");
		assertEquals(2, v.getMajor());
		assertEquals(1, v.getMinor());
		assertEquals(0, v.getMicro());
		assertTrue(v.getQualifier().isEmpty());
	}

	@Test
	public void testParse_254() throws Exception {
		Version v = parseGerritVersion("2.5.4");
		assertEquals(2, v.getMajor());
		assertEquals(5, v.getMinor());
		assertEquals(4, v.getMicro());
		assertTrue(v.getQualifier().isEmpty());
	}

	@Test
	public void testParse_26rc3() throws Exception {
		Version v = parseGerritVersion("2.6-rc3");
		assertEquals(2, v.getMajor());
		assertEquals(6, v.getMinor());
		assertEquals(0, v.getMicro());
		assertEquals("rc3", v.getQualifier());
	}

	@Test
	public void testParse_27rc2637g76c7890() throws Exception {
		Version v = parseGerritVersion("2.7-rc2-637-g76c7890");
		assertEquals(2, v.getMajor());
		assertEquals(7, v.getMinor());
		assertEquals(0, v.getMicro());
		assertEquals("rc2-637-g76c7890", v.getQualifier());
	}

	@Test
	public void testParse_V221NQT012() throws Exception {
		Version v = parseGerritVersion("V2.2.1-NQT-012");
		assertEquals(2, v.getMajor());
		assertEquals(2, v.getMinor());
		assertEquals(1, v.getMicro());
		assertEquals("NQT-012", v.getQualifier());
	}

	@Test
	public void testParse_123q() throws Exception {
		Version v = parseGerritVersion("1.2.3-q");
		assertEquals(1, v.getMajor());
		assertEquals(2, v.getMinor());
		assertEquals(3, v.getMicro());
		assertEquals("q", v.getQualifier());
	}

	@Test
	public void testParse_27xxx31() throws Exception {
		Version v = parseGerritVersion("2.7-xxx3.1");
		assertEquals(2, v.getMajor());
		assertEquals(7, v.getMinor());
		assertEquals(0, v.getMicro());
		assertEquals("xxx3", v.getQualifier()); // '.1' is lost as '.' cannot be part of a qualifier
	}

	@Test
	public void testParse_2861() throws Exception {
		Version v = parseGerritVersion("2.8.6.1");
		assertEquals(2, v.getMajor());
		assertEquals(8, v.getMinor());
		assertEquals(6, v.getMicro());
		assertEquals("1", v.getQualifier());
	}

	@Test
	public void testIsVersion2112OrLater() throws Exception {
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.9.9")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.9.9-q")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10-q")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10.0")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10.0-q")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10.0-rc2")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10.1")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10.1-q")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.10.1-rc2")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.11")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.11.0")));
		assertFalse(isVersion2112OrLater(parseGerritVersion("2.11-rc2")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.2")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.2-q")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.2")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.2-q")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.2-rc2")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.3")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.3-q")));
		assertTrue(isVersion2112OrLater(parseGerritVersion("2.11.3-rc2")));
	}

}

Back to the top