1 package com.xtremelabs.robolectric.shadows; 2 3 import static com.xtremelabs.robolectric.Robolectric.shadowOf; 4 5 import com.xtremelabs.robolectric.Robolectric; 6 import com.xtremelabs.robolectric.internal.Implementation; 7 import com.xtremelabs.robolectric.internal.Implements; 8 9 import android.content.pm.Signature; 10 import android.os.Parcel; 11 import android.os.Parcelable.Creator; 12 13 import java.util.Arrays; 14 15 @Implements(Signature.class) 16 public class ShadowSignature { 17 18 private byte[] mSignature; 19 __constructor__(byte[] signature)20 public void __constructor__(byte[] signature) { 21 mSignature = signature.clone(); 22 } 23 24 @Implementation toByteArray()25 public byte[] toByteArray() { 26 byte[] bytes = new byte[mSignature.length]; 27 System.arraycopy(mSignature, 0, bytes, 0, mSignature.length); 28 return bytes; 29 } 30 31 @Override 32 @Implementation equals(Object obj)33 public boolean equals(Object obj) { 34 if (this == obj) { 35 return true; 36 } 37 if (!(obj instanceof Signature)) { 38 return false; 39 } 40 ShadowSignature otherShadow = shadowOf((Signature) obj); 41 return Arrays.equals(mSignature, otherShadow.mSignature); 42 } 43 44 @Override 45 @Implementation hashCode()46 public int hashCode() { 47 return Arrays.hashCode(mSignature); 48 } 49 50 @Implementation writeToParcel(Parcel dest, int flags)51 public void writeToParcel(Parcel dest, int flags) { 52 dest.writeByteArray(mSignature); 53 } 54 55 public static final Creator<Signature> CREATOR = 56 new Creator<Signature>() { 57 @Override 58 public Signature createFromParcel(Parcel source) { 59 byte[] signature = source.createByteArray(); 60 return new Signature(signature); 61 } 62 63 @Override 64 public Signature[] newArray(int size) { 65 return new Signature[size]; 66 } 67 }; 68 reset()69 public static void reset() { 70 Robolectric.Reflection.setFinalStaticField(Signature.class, "CREATOR", CREATOR); 71 } 72 } 73