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.cellbroadcastservice.tests; 18 19 import static org.mockito.Mockito.doReturn; 20 21 import android.telephony.SmsCbLocation; 22 import android.testing.AndroidTestingRunner; 23 import android.testing.TestableLooper; 24 25 import com.android.cellbroadcastservice.GsmCellBroadcastHandler.SmsCbConcatInfo; 26 import com.android.cellbroadcastservice.SmsCbHeader; 27 28 import org.junit.After; 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 import org.mockito.Mock; 34 import org.mockito.Mockito; 35 import org.mockito.MockitoAnnotations; 36 37 @RunWith(AndroidTestingRunner.class) 38 @TestableLooper.RunWithLooper 39 public class SmsCbContactInfoTest extends CellBroadcastServiceTestBase { 40 41 @Mock 42 private SmsCbHeader mSmsCbHeader; 43 private SmsCbLocation mSmsCbLocation; 44 private SmsCbConcatInfo mSmsCbConcatInfo; 45 46 @Before setUp()47 public void setUp() throws Exception { 48 super.setUp(); 49 MockitoAnnotations.initMocks(this); 50 doReturn(123).when(mSmsCbHeader).getSerialNumber(); 51 mSmsCbLocation = new SmsCbLocation("310999", 1234, 5678); 52 // construct a SmsCbContactInfo for test 53 mSmsCbConcatInfo = new SmsCbConcatInfo(mSmsCbHeader, mSmsCbLocation); 54 } 55 56 @After tearDown()57 public void tearDown() throws Exception { 58 super.tearDown(); 59 } 60 61 @Test testHasCode()62 public void testHasCode() throws Exception { 63 // construct another SmsCbContactInfo for comparison 64 SmsCbConcatInfo testInfo = new SmsCbConcatInfo( 65 Mockito.mock(SmsCbHeader.class), mSmsCbLocation); 66 assertNotSame(testInfo.hashCode(), mSmsCbConcatInfo.hashCode()); 67 } 68 69 @Test testEquals()70 public void testEquals() throws Exception { 71 // construct another SmsCbContactInfo for comparison 72 SmsCbConcatInfo testInfo = new SmsCbConcatInfo( 73 Mockito.mock(SmsCbHeader.class), mSmsCbLocation); 74 assertFalse(testInfo.equals(mSmsCbConcatInfo)); 75 } 76 77 @Test testMatchesLocation()78 public void testMatchesLocation() throws Exception { 79 assertTrue(mSmsCbConcatInfo.matchesLocation("310999", 1234, 5678)); 80 assertFalse(mSmsCbConcatInfo.matchesLocation("310000", 1234, 5678)); 81 assertFalse(mSmsCbConcatInfo.matchesLocation("310999", -1, -1)); 82 } 83 } 84 85