DistroRulesVersionTest.java revision bede17c216815a849be0c43d5ce7daaf750a9fac
1/* 2 * Copyright (C) 2017 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 17package android.app.timezone; 18 19import static org.junit.Assert.assertEquals; 20import static org.junit.Assert.assertFalse; 21import static org.junit.Assert.assertTrue; 22 23import android.os.Parcel; 24 25import org.junit.Test; 26 27/** 28 * Tests for {@link DistroRulesVersion}. 29 */ 30// TODO(nfuller) Move to CTS once this class is part of the SystemApi. http://b/31008728 31public class DistroRulesVersionTest { 32 33 @Test 34 public void equalsAndHashCode() { 35 DistroRulesVersion one = new DistroRulesVersion("2016a", 2); 36 assertEqualsContract(one, one); 37 38 DistroRulesVersion two = new DistroRulesVersion("2016a", 2); 39 assertEqualsContract(one, two); 40 41 DistroRulesVersion three = new DistroRulesVersion("2016b", 1); 42 assertFalse(one.equals(three)); 43 } 44 45 @Test 46 public void parcelable() { 47 DistroRulesVersion version = new DistroRulesVersion("2016a", 2); 48 49 Parcel parcel = Parcel.obtain(); 50 version.writeToParcel(parcel, 0 /* flags */); 51 parcel.setDataPosition(0); 52 53 DistroRulesVersion newVersion = DistroRulesVersion.CREATOR.createFromParcel(parcel); 54 55 assertEquals(version, newVersion); 56 } 57 58 @Test 59 public void isOlderThan() { 60 DistroRulesVersion deviceVersion = new DistroRulesVersion("2016b", 2); 61 assertFalse(deviceVersion.isOlderThan(deviceVersion)); 62 63 DistroRulesVersion sameVersion = new DistroRulesVersion("2016b", 2); 64 assertFalse(deviceVersion.isOlderThan(sameVersion)); 65 66 DistroRulesVersion sameRulesNewerRevision = new DistroRulesVersion("2016b", 3); 67 assertTrue(deviceVersion.isOlderThan(sameRulesNewerRevision)); 68 69 DistroRulesVersion sameRulesOlderRevision = new DistroRulesVersion("2016b", 1); 70 assertFalse(deviceVersion.isOlderThan(sameRulesOlderRevision)); 71 72 DistroRulesVersion newerRules = new DistroRulesVersion("2016c", 2); 73 assertTrue(deviceVersion.isOlderThan(newerRules)); 74 75 DistroRulesVersion olderRules = new DistroRulesVersion("2016a", 2); 76 assertFalse(deviceVersion.isOlderThan(olderRules)); 77 } 78 79 private static void assertEqualsContract(DistroRulesVersion one, DistroRulesVersion two) { 80 assertEquals(one, two); 81 assertEquals(one.hashCode(), two.hashCode()); 82 } 83} 84