1package com.xtremelabs.robolectric.shadows;
2
3import static com.xtremelabs.robolectric.Robolectric.shadowOf;
4
5import com.xtremelabs.robolectric.Robolectric;
6import com.xtremelabs.robolectric.internal.Implementation;
7import com.xtremelabs.robolectric.internal.Implements;
8
9import android.content.pm.Signature;
10import android.os.Parcel;
11import android.os.Parcelable.Creator;
12
13import java.util.Arrays;
14
15@Implements(Signature.class)
16public class ShadowSignature {
17
18    private byte[] mSignature;
19
20    public void __constructor__(byte[] signature) {
21        mSignature = signature.clone();
22    }
23
24    @Implementation
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
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
46    public int hashCode() {
47        return Arrays.hashCode(mSignature);
48    }
49
50    @Implementation
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
69    public static void reset() {
70        Robolectric.Reflection.setFinalStaticField(Signature.class, "CREATOR", CREATOR);
71    }
72}
73