1 package com.xtremelabs.robolectric.shadows; 2 3 import static org.hamcrest.CoreMatchers.equalTo; 4 import static org.hamcrest.CoreMatchers.not; 5 import static org.junit.Assert.assertArrayEquals; 6 import static org.junit.Assert.assertEquals; 7 import static org.junit.Assert.assertThat; 8 9 import com.xtremelabs.robolectric.WithTestDefaultsRunner; 10 11 import org.junit.Test; 12 import org.junit.runner.RunWith; 13 14 import android.content.pm.Signature; 15 import android.os.Parcel; 16 17 @RunWith(WithTestDefaultsRunner.class) 18 public class SignatureTest { 19 20 @Test 21 public void shouldHaveByteArrayConstructorAndToByteArray() { 22 byte[] bytes = { (byte) 0xAC, (byte) 0xDE }; 23 Signature signature = new Signature(bytes); 24 25 assertArrayEquals(bytes, signature.toByteArray()); 26 } 27 28 @Test 29 public void shouldHaveCreator() throws Exception { 30 byte[] bytes = { (byte) 0xAC, (byte) 0xDE }; 31 Signature expected = new Signature(bytes); 32 Parcel p = Parcel.obtain(); 33 expected.writeToParcel(p, 0); 34 35 p.setDataPosition(0); 36 37 Signature actual = Signature.CREATOR.createFromParcel(p); 38 assertEquals(expected, actual); 39 } 40 41 @Test 42 public void shouldProvideEqualsAndHashCode() throws Exception { 43 assertThat(new Signature(new byte[] { (byte) 0xAC }), 44 equalTo(new Signature(new byte[] { (byte) 0xAC }))); 45 assertThat(new Signature(new byte[] { (byte) 0xAC }), 46 not(equalTo(new Signature(new byte[] { (byte) 0xDE })))); 47 assertThat(new Signature(new byte[] { (byte) 0xAC }).hashCode(), 48 equalTo(new Signature(new byte[] { (byte) 0xAC }).hashCode())); 49 assertThat(new Signature(new byte[] { (byte) 0xAC }).hashCode(), 50 not(equalTo(new Signature(new byte[] { (byte) 0xDE }).hashCode()))); 51 } 52 } 53