1 /*
2  * Copyright (C) 2022 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package util
18 
19 import com.google.common.truth.Truth.assertThat
20 import dagger.hilt.android.plugin.util.SimpleAGPVersion
21 import org.junit.Test
22 
23 class SimpleAGPVersionTest {
24 
25   @Test
parsingnull26   fun parsing() {
27     assertThat(SimpleAGPVersion.parse("4.2"))
28       .isEqualTo(SimpleAGPVersion(4, 2))
29     assertThat(SimpleAGPVersion.parse("4.2.1"))
30       .isEqualTo(SimpleAGPVersion(4, 2))
31     assertThat(SimpleAGPVersion.parse("7.0.0-alpha01"))
32       .isEqualTo(SimpleAGPVersion(7, 0))
33   }
34 
35   @Test
comparingnull36   fun comparing() {
37     assertThat(SimpleAGPVersion(4, 2))
38       .isEqualTo(SimpleAGPVersion(4, 2))
39     assertThat(SimpleAGPVersion(4, 2))
40       .isGreaterThan(SimpleAGPVersion(3, 4))
41     assertThat(SimpleAGPVersion(4, 2))
42       .isLessThan(SimpleAGPVersion(7, 0))
43 
44     assertThat(SimpleAGPVersion.parse("4.2.1"))
45       .isEqualTo(SimpleAGPVersion.parse("4.2.2"))
46     assertThat(SimpleAGPVersion.parse("4.2.1"))
47       .isGreaterThan(SimpleAGPVersion.parse("3.4.1"))
48     assertThat(SimpleAGPVersion.parse("4.2.1"))
49       .isLessThan(SimpleAGPVersion.parse("7.0.1"))
50 
51     assertThat(SimpleAGPVersion.parse("4.2.1"))
52       .isLessThan(SimpleAGPVersion.parse("7.0.0-alpha01"))
53     assertThat(SimpleAGPVersion.parse("7.0.0-alpha01"))
54       .isEqualTo(SimpleAGPVersion.parse("7.0.0-alpha02"))
55   }
56 }
57