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.devicelockcontroller.activities; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.android.devicelockcontroller.activities.ProvisionInfo.ProvisionInfoType; 22 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 import org.junit.runners.JUnit4; 26 27 @RunWith(JUnit4.class) 28 public final class ProvisionInfoTest { 29 30 private static final int DRAWABLE_ID_1 = 0; 31 private static final int DRAWABLE_ID_2 = 1; 32 private static final int TEXT_ID_1 = 10; 33 private static final int TEXT_ID_2 = 11; 34 private static final int TYPE_1 = ProvisionInfoType.REGULAR; 35 private static final int TYPE_2 = ProvisionInfoType.TERMS_AND_CONDITIONS; 36 37 @Test equals_withOneDifferentFieldValue_returnsFalse()38 public void equals_withOneDifferentFieldValue_returnsFalse() { 39 ProvisionInfo p1 = new ProvisionInfo(DRAWABLE_ID_1, TEXT_ID_1, TYPE_1); 40 ProvisionInfo p10 = new ProvisionInfo(DRAWABLE_ID_2, TEXT_ID_1, TYPE_1); 41 ProvisionInfo p12 = new ProvisionInfo(DRAWABLE_ID_1, TEXT_ID_2, TYPE_1); 42 ProvisionInfo p13 = new ProvisionInfo(DRAWABLE_ID_1, TEXT_ID_1, TYPE_2); 43 44 assertThat(p1).isNotEqualTo(p10); 45 assertThat(p1.hashCode()).isNotEqualTo(p10.hashCode()); 46 assertThat(p1).isNotEqualTo(p12); 47 assertThat(p1.hashCode()).isNotEqualTo(p12.hashCode()); 48 assertThat(p1).isNotEqualTo(p13); 49 assertThat(p1.hashCode()).isNotEqualTo(p13.hashCode()); 50 } 51 52 @Test equals_withSameFieldValues_returnsTrue()53 public void equals_withSameFieldValues_returnsTrue() { 54 ProvisionInfo p1 = new ProvisionInfo(DRAWABLE_ID_1, TEXT_ID_1, TYPE_1); 55 ProvisionInfo p2 = new ProvisionInfo(DRAWABLE_ID_1, TEXT_ID_1, TYPE_1); 56 57 assertThat(p1).isEqualTo(p2); 58 assertThat(p1.hashCode()).isEqualTo(p2.hashCode()); 59 } 60 } 61