// Write to parcel.
Parcel p = Parcel.obtain();
Bundle writer = new Bundle();
writer.putParcelable("test_info", original);
writer.writeToParcel(p, 0);
// Extract from parcel.
p.setDataPosition(0);
Bundle reader = p.readBundle();
reader.setClassLoader(NsdServiceInfo.class.getClassLoader());
NsdServiceInfo result = reader.getParcelable("test_info");
// Assert equality of base fields.
assertEquality(original.getServiceName(), result.getServiceName());
assertEquality(original.getServiceType(), result.getServiceType());
assertEquality(original.getHost(), result.getHost());
assertTrue(original.getPort() == result.getPort());
// Assert equality of attribute map.
Map<String, byte[]> originalMap = original.getAttributes();
Map<String, byte[]> resultMap = result.getAttributes();
assertEquality(originalMap.keySet(), resultMap.keySet());
for (String key : originalMap.keySet()) {
assertTrue(Arrays.equals(originalMap.get(key), resultMap.get(key)));
}