View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.javadoc;
20  
21  import java.util.regex.Matcher;
22  import java.util.regex.Pattern;
23  
24  import org.junit.Test;
25  
26  import static org.assertj.core.api.Assertions.assertThat;
27  
28  public class JavadocVersionTest {
29      /**
30       * Parsing is lazy, only triggered when comparing
31       */
32      @Test
33      @SuppressWarnings("deprecation")
34      public void testParse() {
35          assertThat(JavadocVersion.parse("1.4"))
36                  .isLessThan(JavadocVersion.parse("1.4.2"))
37                  .isLessThan(JavadocVersion.parse("1.5"));
38  
39          assertThat(JavadocVersion.parse("1.8")).isLessThan(JavadocVersion.parse("9"));
40  
41          assertThat(JavadocVersion.parse("1.4")).isEqualByComparingTo(JavadocVersion.parse("1.4"));
42          assertThat(JavadocVersion.parse("1.4.2")).isEqualByComparingTo(JavadocVersion.parse("1.4.2"));
43          assertThat(JavadocVersion.parse("9")).isEqualByComparingTo(JavadocVersion.parse("9"));
44  
45          assertThat(JavadocVersion.parse("1.4.2")).isGreaterThan(JavadocVersion.parse("1.4"));
46          assertThat(JavadocVersion.parse("1.5")).isGreaterThan(JavadocVersion.parse("1.4"));
47          assertThat(JavadocVersion.parse("9")).isGreaterThan(JavadocVersion.parse("1.8"));
48      }
49  
50      @Test
51      public void testApiVersion() {
52          Pattern p = Pattern.compile("(1\\.\\d|\\d\\d*)");
53          Matcher m = p.matcher("9");
54          assertThat(m.find()).isTrue();
55          assertThat(m.group(1)).isEqualTo("9");
56  
57          m = p.matcher("1.4");
58          assertThat(m.find()).isTrue();
59          assertThat(m.group(1)).isEqualTo("1.4");
60  
61          m = p.matcher("1.4.2");
62          assertThat(m.find()).isTrue();
63          assertThat(m.group(1)).isEqualTo("1.4");
64      }
65  }