• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
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 package com.google.android.libraries.mobiledatadownload.file.common;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 import static org.junit.Assert.assertThrows;
20 
21 import com.google.thirdparty.robolectric.GoogleRobolectricTestRunner;
22 import java.util.Date;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 
26 @RunWith(GoogleRobolectricTestRunner.class)
27 public class GcParamTest {
28 
29   @Test
none_shouldHaveNoneTagAndNoExpiration()30   public void none_shouldHaveNoneTagAndNoExpiration() {
31     GcParam none = GcParam.none();
32     assertThat(none).isNotNull();
33     assertThat(none.isExpiresAt()).isFalse();
34     assertThrows(IllegalStateException.class, () -> none.getExpiration());
35     assertThat(none.isNone()).isTrue();
36   }
37 
38   @Test
expiresAt_shouldHaveExpiresAtTagAndExpiration()39   public void expiresAt_shouldHaveExpiresAtTagAndExpiration() {
40 
41     Date date1 = new Date(1L);
42     Date date2 = new Date(2L);
43     GcParam expiresAt1 = GcParam.expiresAt(date1);
44     GcParam expiresAt2 = GcParam.expiresAt(date2);
45 
46     assertThat(expiresAt1).isNotNull();
47     assertThat(expiresAt2).isNotNull();
48     assertThat(expiresAt1.isNone()).isFalse();
49     assertThat(expiresAt2.isNone()).isFalse();
50     assertThat(expiresAt1.isExpiresAt()).isTrue();
51     assertThat(expiresAt2.isExpiresAt()).isTrue();
52     assertThat(expiresAt1.getExpiration()).isEqualTo(date1);
53     assertThat(expiresAt2.getExpiration()).isEqualTo(date2);
54   }
55 
56   @Test
equals_shouldCompareDataMembers()57   public void equals_shouldCompareDataMembers() {
58 
59     GcParam expiresAt1 = GcParam.expiresAt(new Date(1L));
60     GcParam expiresAt2 = GcParam.expiresAt(new Date(2L));
61     GcParam expiresAt1b = GcParam.expiresAt(new Date(1L));
62     GcParam none1 = GcParam.none();
63     GcParam none2 = GcParam.none();
64 
65     assertThat(expiresAt1).isNotEqualTo(null);
66     assertThat(expiresAt2).isNotEqualTo(null);
67     assertThat(expiresAt1b).isNotEqualTo(null);
68     assertThat(none1).isNotEqualTo(null);
69     assertThat(none2).isNotEqualTo(null);
70 
71     assertThat(expiresAt1).isNotEqualTo(expiresAt2);
72     assertThat(expiresAt1).isEqualTo(expiresAt1b);
73     assertThat(expiresAt1).isNotEqualTo(none1);
74     assertThat(expiresAt1).isNotEqualTo(none2);
75 
76     assertThat(expiresAt2).isNotEqualTo(expiresAt1);
77     assertThat(expiresAt2).isNotEqualTo(expiresAt1b);
78     assertThat(expiresAt2).isNotEqualTo(none1);
79     assertThat(expiresAt2).isNotEqualTo(none2);
80 
81     assertThat(expiresAt1b).isEqualTo(expiresAt1);
82     assertThat(expiresAt1b).isNotEqualTo(expiresAt2);
83     assertThat(expiresAt1b).isNotEqualTo(none1);
84     assertThat(expiresAt1b).isNotEqualTo(none2);
85 
86     assertThat(none1).isNotEqualTo(expiresAt1);
87     assertThat(none1).isNotEqualTo(expiresAt2);
88     assertThat(none1).isNotEqualTo(expiresAt1b);
89     assertThat(none1).isEqualTo(none2);
90 
91     assertThat(none2).isNotEqualTo(expiresAt1);
92     assertThat(none2).isNotEqualTo(expiresAt2);
93     assertThat(none2).isNotEqualTo(expiresAt1b);
94     assertThat(none2).isEqualTo(none1);
95   }
96 }
97