1 /*
2  * Copyright (C) 2022 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.adservices.service.adid;
18 
19 import static org.mockito.Mockito.verify;
20 
21 import android.adservices.adid.AdId;
22 import android.adservices.adid.IGetAdIdCallback;
23 import android.adservices.common.UpdateAdIdRequest;
24 
25 import com.android.adservices.common.AdServicesMockitoTestCase;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mock;
30 
31 /** Unit test for {@link com.android.adservices.service.adid.AdIdWorker}. */
32 public final class AdIdWorkerTest extends AdServicesMockitoTestCase {
33     private static final String PACKAGE_NAME = "package_name";
34     private static final int DUMMY_CALLER_UID = 0;
35     private static final IGetAdIdCallback CALLBACK = new IGetAdIdCallback.Default();
36 
37     private AdIdWorker mAdIdWorker;
38 
39     @Mock private AdIdCacheManager mMockAdIdCacheManager;
40 
41     @Before
setup()42     public void setup() {
43         mAdIdWorker = new AdIdWorker(mMockAdIdCacheManager);
44     }
45 
46     @Test
testGetAdId()47     public void testGetAdId() {
48         mAdIdWorker.getAdId(PACKAGE_NAME, DUMMY_CALLER_UID, CALLBACK);
49 
50         verify(mMockAdIdCacheManager).getAdId(PACKAGE_NAME, DUMMY_CALLER_UID, CALLBACK);
51     }
52 
53     @Test
testUpdateAdId()54     public void testUpdateAdId() {
55         UpdateAdIdRequest request = new UpdateAdIdRequest.Builder(AdId.ZERO_OUT).build();
56 
57         mAdIdWorker.updateAdId(request);
58 
59         verify(mMockAdIdCacheManager).updateAdId(request);
60     }
61 }
62