1 /* 2 * Copyright (C) 2023 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.settings.localepicker; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.spy; 22 23 import android.content.Context; 24 25 import org.junit.After; 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 import org.mockito.MockitoAnnotations; 30 import org.robolectric.RobolectricTestRunner; 31 import org.robolectric.RuntimeEnvironment; 32 33 import java.util.Map; 34 import java.util.Set; 35 36 @RunWith(RobolectricTestRunner.class) 37 public class LocaleNotificationDataManagerTest { 38 private Context mContext; 39 private LocaleNotificationDataManager mDataManager; 40 41 @Before setUp()42 public void setUp() throws Exception { 43 MockitoAnnotations.initMocks(this); 44 mContext = spy(RuntimeEnvironment.application); 45 mDataManager = new LocaleNotificationDataManager(mContext); 46 } 47 48 @After tearDown()49 public void tearDown() { 50 mDataManager.clearLocaleNotificationMap(); 51 } 52 53 @Test testPutGetNotificationInfo()54 public void testPutGetNotificationInfo() { 55 String locale = "en-US"; 56 Set<Integer> uidSet = Set.of(101); 57 NotificationInfo info = new NotificationInfo(uidSet, 1, 1, 100L, 1000); 58 59 mDataManager.putNotificationInfo(locale, info); 60 NotificationInfo expected = mDataManager.getNotificationInfo(locale); 61 62 assertThat(info.equals(expected)).isTrue(); 63 assertThat(expected.getNotificationId()).isEqualTo(info.getNotificationId()); 64 assertThat(expected.getDismissCount()).isEqualTo(info.getDismissCount()); 65 assertThat(expected.getNotificationCount()).isEqualTo(info.getNotificationCount()); 66 assertThat(expected.getUidCollection()).isEqualTo(info.getUidCollection()); 67 assertThat(expected.getLastNotificationTimeMs()).isEqualTo( 68 info.getLastNotificationTimeMs()); 69 } 70 71 @Test testRemoveNotificationInfo()72 public void testRemoveNotificationInfo() { 73 String locale = "en-US"; 74 Set<Integer> uidSet = Set.of(101); 75 NotificationInfo info = new NotificationInfo(uidSet, 1, 1, 100L, 1000); 76 77 mDataManager.putNotificationInfo(locale, info); 78 assertThat(mDataManager.getNotificationInfo(locale)).isEqualTo(info); 79 mDataManager.removeNotificationInfo(locale); 80 assertThat(mDataManager.getNotificationInfo(locale)).isNull(); 81 } 82 83 @Test testGetNotificationMap()84 public void testGetNotificationMap() { 85 String enUS = "en-US"; 86 Set<Integer> uidSet1 = Set.of(101, 102); 87 NotificationInfo info1 = new NotificationInfo(uidSet1, 1, 1, 1000L, 1234); 88 String jaJP = "ja-JP"; 89 Set<Integer> uidSet2 = Set.of(103, 104); 90 NotificationInfo info2 = new NotificationInfo(uidSet2, 1, 0, 2000L, 5678); 91 mDataManager.putNotificationInfo(enUS, info1); 92 mDataManager.putNotificationInfo(jaJP, info2); 93 94 Map<String, NotificationInfo> map = mDataManager.getLocaleNotificationInfoMap(); 95 96 assertThat(map.size()).isEqualTo(2); 97 assertThat(mDataManager.getNotificationInfo(enUS).equals(map.get(enUS))).isTrue(); 98 assertThat(mDataManager.getNotificationInfo(jaJP).equals(map.get(jaJP))).isTrue(); 99 } 100 } 101