Made Parcel.writeString() handle null string
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowIntent.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowIntent.java
index 1128960..9f24e74 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowIntent.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowIntent.java
@@ -608,16 +608,16 @@
@Implementation
public void writeToParcel(Parcel out, int flags) {
- writeStringToParcel(action, out);
+ out.writeString(action);
if (data != null) {
out.writeInt(1);
Uri.writeToParcel(out, data);
} else {
out.writeInt(0);
}
- writeStringToParcel(type, out);
+ out.writeString(type);
out.writeInt(flags);
- writeStringToParcel(packageName, out);
+ out.writeString(packageName);
ComponentName.writeToParcel(componentName, out);
out.writeInt(categories.size());
for (String category : categories) {
@@ -628,13 +628,13 @@
@Implementation
public void readFromParcel(Parcel in) {
- setAction(readStringFromParcel(in));
+ setAction(in.readString());
if (in.readInt() != 0) {
data = Uri.CREATOR.createFromParcel(in);
}
- type = readStringFromParcel(in);
+ type = in.readString();
flags = in.readInt();
- packageName = readStringFromParcel(in);
+ packageName = in.readString();
componentName = ComponentName.readFromParcel(in);
int N = in.readInt();
for (int i = 0; i < N; i++) {
@@ -643,22 +643,6 @@
extras.putAll(in.readBundle());
}
- private void writeStringToParcel(String s, Parcel out) {
- if (s != null) {
- out.writeInt(1);
- out.writeString(s);
- } else {
- out.writeInt(0);
- }
- }
-
- private String readStringFromParcel(Parcel in) {
- if (in.readInt() != 0) {
- return in.readString();
- }
- return null;
- }
-
private Serializable serializeCycle(Serializable serializable) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowParcel.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowParcel.java
index d41a681..75c864a 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowParcel.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowParcel.java
@@ -27,9 +27,6 @@
@Implementation
public void writeString(String str) {
- if (str == null) {
- return;
- }
parcelData.add(str);
}
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/ParcelTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/ParcelTest.java
index d2e5a1a..8072eb7 100644
--- a/src/test/java/com/xtremelabs/robolectric/shadows/ParcelTest.java
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/ParcelTest.java
@@ -65,13 +65,13 @@
assertThat(parcel.readString(), equalTo(val));
}
- @Test
- public void testWriteNullString() {
- parcel.writeString(null);
- assertThat(parcel.readString(), nullValue());
- assertThat(shadowParcel.getIndex(), equalTo(0));
- assertThat(shadowParcel.getParcelData().size(), equalTo(0));
- }
+ @Test
+ public void testWriteNullString() {
+ parcel.writeString( null );
+ assertThat( parcel.readString(), nullValue() );
+ assertThat( shadowParcel.getIndex(), equalTo( 1 ) );
+ assertThat( shadowParcel.getParcelData().size(), equalTo( 1 ) );
+ }
@Test
public void testReadWriteMultipleStrings() {