1 /*
2  * Copyright (C) 2020 The Android Open Source Project
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 com.android.documentsui.base;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import androidx.test.filters.SmallTest;
22 import androidx.test.runner.AndroidJUnit4;
23 
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 
27 @RunWith(AndroidJUnit4.class)
28 @SmallTest
29 public class RootInfoTest {
30 
31     @Test
testEquals_sameUser()32     public void testEquals_sameUser() {
33         RootInfo rootInfo = new RootInfo();
34         rootInfo.userId = UserId.of(100);
35         rootInfo.authority = "authority";
36         rootInfo.rootId = "root";
37 
38         RootInfo rootInfo2 = new RootInfo();
39         rootInfo2.userId = UserId.of(100);
40         rootInfo2.authority = "authority";
41         rootInfo2.rootId = "root";
42 
43         assertThat(rootInfo).isEqualTo(rootInfo2);
44     }
45 
46     @Test
testNotEquals_differentUser()47     public void testNotEquals_differentUser() {
48         RootInfo rootInfo = new RootInfo();
49         rootInfo.userId = UserId.of(100);
50         rootInfo.authority = "authority";
51         rootInfo.rootId = "root";
52 
53         RootInfo rootInfo2 = new RootInfo();
54         rootInfo2.userId = UserId.of(101);
55         rootInfo2.authority = "authority";
56         rootInfo2.rootId = "root";
57 
58         assertThat(rootInfo).isNotEqualTo(rootInfo2);
59     }
60 
61     @Test
testCopyInfo_equal()62     public void testCopyInfo_equal() {
63         RootInfo rootInfo = new RootInfo();
64         rootInfo.userId = UserId.of(100);
65         rootInfo.authority = "authority";
66         rootInfo.rootId = "root";
67 
68         RootInfo copied = RootInfo.copyRootInfo(rootInfo);
69         assertThat(copied).isEqualTo(rootInfo);
70         assertThat(copied).isNotSameAs(rootInfo);
71     }
72 }
73