|
17 | 17 | package com.optimizely.ab.config.audience; |
18 | 18 |
|
19 | 19 | import com.optimizely.ab.config.audience.match.SemanticVersion; |
| 20 | +import com.optimizely.ab.config.audience.match.UnexpectedValueTypeException; |
20 | 21 | import org.junit.Rule; |
21 | 22 | import org.junit.Test; |
22 | 23 | import org.junit.rules.ExpectedException; |
@@ -141,108 +142,29 @@ public void semanticVersionInvalidShouldBeOfSizeLessThan3() throws Exception { |
141 | 142 | } |
142 | 143 |
|
143 | 144 | @Test |
144 | | - public void semanticVersionCompareTo() throws Exception { |
145 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1"); |
146 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1"); |
147 | | - assertTrue(actualSV.compare(targetSV) == 0); |
| 145 | + public void testEquals() throws Exception { |
| 146 | + assertEquals(0, SemanticVersion.compare("3.7.1", "3.7.1")); |
| 147 | + assertEquals(0, SemanticVersion.compare("3.7.1", "3.7")); |
| 148 | + assertEquals(0, SemanticVersion.compare("2.1.3+build", "2.1.3")); |
| 149 | + assertEquals(0, SemanticVersion.compare("3.7.1-beta.1+2.3", "3.7.1-beta.1+2.3")); |
148 | 150 | } |
149 | 151 |
|
150 | 152 | @Test |
151 | | - public void semanticVersionCompareToActualLess() throws Exception { |
152 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1"); |
153 | | - SemanticVersion actualSV = new SemanticVersion("3.7.0"); |
154 | | - assertTrue(actualSV.compare(targetSV) < 0); |
| 153 | + public void testLessThan() throws Exception { |
| 154 | + assertTrue(SemanticVersion.compare("3.7.0", "3.7.1") < 0); |
| 155 | + assertTrue(SemanticVersion.compare("3.7", "3.7.1") < 0); |
| 156 | + assertTrue(SemanticVersion.compare("2.1.3-beta+1", "2.1.3-beta+1.2.3") < 0); |
| 157 | + assertTrue(SemanticVersion.compare("2.1.3-beta-1", "2.1.3-beta-1.2.3") < 0); |
155 | 158 | } |
156 | 159 |
|
157 | 160 | @Test |
158 | | - public void semanticVersionCompareToActualGreater() throws Exception { |
159 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1"); |
160 | | - SemanticVersion actualSV = new SemanticVersion("3.7.2"); |
161 | | - assertTrue(actualSV.compare(targetSV) > 0); |
162 | | - } |
163 | | - |
164 | | - @Test |
165 | | - public void semanticVersionCompareToPatchMissing() throws Exception { |
166 | | - SemanticVersion targetSV = new SemanticVersion("3.7"); |
167 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1"); |
168 | | - assertTrue(actualSV.compare(targetSV) == 0); |
169 | | - } |
170 | | - |
171 | | - @Test |
172 | | - public void semanticVersionCompareToActualPatchMissing() throws Exception { |
173 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1"); |
174 | | - SemanticVersion actualSV = new SemanticVersion("3.7"); |
175 | | - assertTrue(actualSV.compare(targetSV) < 0); |
176 | | - } |
177 | | - |
178 | | - @Test |
179 | | - public void semanticVersionCompareToActualPreReleaseMissing() throws Exception { |
180 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1-beta"); |
181 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1"); |
182 | | - assertTrue(actualSV.compare(targetSV) > 0); |
183 | | - } |
184 | | - |
185 | | - @Test |
186 | | - public void semanticVersionCompareTargetBetaComplex() throws Exception { |
187 | | - SemanticVersion targetSV = new SemanticVersion("2.1.3-beta+1"); |
188 | | - SemanticVersion actualSV = new SemanticVersion("2.1.3-beta+1.2.3"); |
189 | | - assertTrue(actualSV.compare(targetSV) > 0); |
190 | | - } |
191 | | - |
192 | | - @Test |
193 | | - public void semanticVersionCompareTargetBuildIgnores() throws Exception { |
194 | | - SemanticVersion targetSV = new SemanticVersion("2.1.3"); |
195 | | - SemanticVersion actualSV = new SemanticVersion("2.1.3+build"); |
196 | | - assertTrue(actualSV.compare(targetSV) == 0); |
197 | | - } |
198 | | - |
199 | | - @Test |
200 | | - public void semanticVersionCompareTargetBuildComplex() throws Exception { |
201 | | - SemanticVersion targetSV = new SemanticVersion("2.1.3-beta+1.2.3"); |
202 | | - SemanticVersion actualSV = new SemanticVersion("2.1.3-beta+1"); |
203 | | - assertTrue(actualSV.compare(targetSV) < 0); |
204 | | - } |
205 | | - |
206 | | - @Test |
207 | | - public void semanticVersionCompareMultipleDash() throws Exception { |
208 | | - SemanticVersion targetSV = new SemanticVersion("2.1.3-beta-1.2.3"); |
209 | | - SemanticVersion actualSV = new SemanticVersion("2.1.3-beta-1"); |
210 | | - assertTrue(actualSV.compare(targetSV) < 0); |
211 | | - } |
212 | | - |
213 | | - @Test |
214 | | - public void semanticVersionCompareToAlphaBetaAsciiComparision() throws Exception { |
215 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1-alpha"); |
216 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1-beta"); |
217 | | - assertTrue(actualSV.compare(targetSV) > 0); |
218 | | - } |
219 | | - |
220 | | - @Test |
221 | | - public void semanticVersionComparePrereleaseSmallerThanBuild() throws Exception { |
222 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1-prerelease"); |
223 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1+build"); |
224 | | - assertTrue(actualSV.compare(targetSV) > 0); |
225 | | - } |
226 | | - |
227 | | - |
228 | | - @Test |
229 | | - public void semanticVersionCompareAgainstPreReleaseToPreRelease() throws Exception { |
230 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1-prerelease+build"); |
231 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1-prerelease-prerelease+rc"); |
232 | | - assertTrue(actualSV.compare(targetSV) > 0); |
233 | | - } |
234 | | - |
235 | | - @Test |
236 | | - public void semanticVersionCompareToIgnoreMetaComparision() throws Exception { |
237 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1-beta.1+2.3"); |
238 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1-beta.1+2.3"); |
239 | | - assertTrue(actualSV.compare(targetSV) == 0); |
240 | | - } |
241 | | - |
242 | | - @Test |
243 | | - public void semanticVersionCompareToPreReleaseComparision() throws Exception { |
244 | | - SemanticVersion targetSV = new SemanticVersion("3.7.1-beta.1"); |
245 | | - SemanticVersion actualSV = new SemanticVersion("3.7.1-beta.2"); |
246 | | - assertTrue(actualSV.compare(targetSV) > 0); |
| 161 | + public void testGreaterThan() throws Exception { |
| 162 | + assertTrue(SemanticVersion.compare("3.7.2", "3.7.1") > 0); |
| 163 | + assertTrue(SemanticVersion.compare("3.7.1", "3.7.1-beta") > 0); |
| 164 | + assertTrue(SemanticVersion.compare("2.1.3-beta+1.2.3", "2.1.3-beta+1") > 0); |
| 165 | + assertTrue(SemanticVersion.compare("3.7.1-beta", "3.7.1-alpha") > 0); |
| 166 | + assertTrue(SemanticVersion.compare("3.7.1+build", "3.7.1-prerelease") > 0); |
| 167 | + assertTrue(SemanticVersion.compare("3.7.1-prerelease-prerelease+rc", "3.7.1-prerelease+build") > 0); |
| 168 | + assertTrue(SemanticVersion.compare("3.7.1-beta.2", "3.7.1-beta.1") > 0); |
247 | 169 | } |
248 | 170 | } |
0 commit comments