1 /* 2 * Copyright (C) 2015 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 android.nfc; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertNotEquals; 21 22 import android.os.Parcel; 23 24 import org.junit.Before; 25 import org.junit.Test; 26 27 public class AvailableNfcAntennaTest { 28 private final int mLocationX = 10; 29 private final int mLocationY = 20; 30 private AvailableNfcAntenna mAntenna; 31 32 @Before setUp()33 public void setUp() { 34 mAntenna = new AvailableNfcAntenna(mLocationX, mLocationY); 35 } 36 37 @Test testConstructorAndGetters()38 public void testConstructorAndGetters() { 39 assertEquals(mLocationX, mAntenna.getLocationX()); 40 assertEquals(mLocationY, mAntenna.getLocationY()); 41 } 42 43 @Test testParcelWriteAndRead()44 public void testParcelWriteAndRead() { 45 int locationX = 15; 46 int locationY = 25; 47 AvailableNfcAntenna originalAntenna = new AvailableNfcAntenna(locationX, locationY); 48 Parcel parcel = Parcel.obtain(); 49 originalAntenna.writeToParcel(parcel, 0); 50 parcel.setDataPosition(0); 51 AvailableNfcAntenna createdFromParcel = AvailableNfcAntenna.CREATOR.createFromParcel( 52 parcel); 53 54 assertEquals(originalAntenna.getLocationX(), createdFromParcel.getLocationX()); 55 assertEquals(originalAntenna.getLocationY(), createdFromParcel.getLocationY()); 56 parcel.recycle(); 57 } 58 59 @Test testEqualsAndHashCode()60 public void testEqualsAndHashCode() { 61 AvailableNfcAntenna antenna = new AvailableNfcAntenna(mLocationX, mLocationY); 62 AvailableNfcAntenna nfcAntenna = new AvailableNfcAntenna(15, 25); 63 64 assertEquals(mAntenna, antenna); 65 assertNotEquals(mAntenna, nfcAntenna); 66 assertEquals(mAntenna.hashCode(), antenna.hashCode()); 67 assertNotEquals(mAntenna.hashCode(), nfcAntenna.hashCode()); 68 } 69 70 @Test testToString()71 public void testToString() { 72 String result = mAntenna.toString(); 73 assertEquals("AvailableNfcAntenna x: 10 y: 20", result); 74 } 75 76 @Test testDescribeContents()77 public void testDescribeContents() { 78 assertEquals(0, mAntenna.describeContents()); 79 } 80 } 81