View Javadoc
1   package org.nuiton.version;
2   
3   /*
4    * #%L
5    * Nuiton Version
6    * %%
7    * Copyright (C) 2016 CodeLutin, Tony Chemit
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.collect.Lists;
26  import org.junit.Assert;
27  import org.junit.Test;
28  
29  /**
30   * Created on 7/10/14.
31   *
32   * @author Tony Chemit - chemit@codelutin.com
33   * @since 3.0
34   */
35  public class VersionTest {
36  
37      @Test
38      public void testEquals() {
39  
40          // Ignore case on string componants
41          assertEquals(Versions.valueOf("1.1-rc"), Versions.valueOf("1.1-Rc"));
42  
43          // Ignore componants join separator
44          assertEquals(Versions.valueOf("1.1"), VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1)).setJoinSeparator(' ').build());
45  
46      }
47  
48      protected void buildVersion(Version version,
49                                  String stringRepresentation,
50                                  int nbComponants,
51                                  boolean snapshot,
52                                  Comparable... componants) {
53  
54          Assert.assertEquals("Bad string represetion", stringRepresentation, version.getVersion());
55          Assert.assertEquals("Bad number of componants", nbComponants, version.getComponantCount());
56          Assert.assertEquals("Bad snapshot value", snapshot, version.isSnapshot());
57          for (int i = 0; i < componants.length; i++) {
58              Comparable componant = componants[i];
59              Assert.assertEquals("Bad componant value at index " + i, componant, version.getComponant(i).getValue());
60          }
61  
62      }
63  
64      protected void assertEquals(Version v1, Version v2) {
65          Assert.assertEquals(v1 + " equals to " + v2, v1, v2);
66      }
67  
68  }