BundleableUtil { @NonNull public static <T extends Bundleable> T materializeBundle(Bundle b) throws BadBundleableException { return materializeBundle(b.getString(Bundleable.CLZ), b); }  @NonNull static T materializeBundle(Bundle b); @NonNull @SuppressWarnings("unchecked") static T materializeBundle(Class<T> cls, Bundle b); @NonNull @SuppressWarnings("unchecked") static T materializeBundle(String name, Bundle b);  }
@Test public void testMaterializeBundleWorks() throws Exception { TestBundleable t = new TestBundleable("fred", 26); Bundle b = t.toBundle(); Parcel p = Parcel.obtain(); b.writeToParcel(p, 0); p.setDataPosition(0); Bundle b1 = p.readBundle(); Bundleable b2 = BundleableUtil.materializeBundle(b1); assertThat((b2 instanceof TestBundleable)).isTrue(); assertThat((TestBundleable) b2).isEqualTo(t); }
@Test public void testMaterializeBundleWorks2() throws Exception { TestBundleable t = new TestBundleable("sally", 23); Bundle b = t.toBundle(); Parcel p = Parcel.obtain(); b.writeToParcel(p, 0); p.setDataPosition(0); Bundle b1 = p.readBundle(); TestBundleable f2 = BundleableUtil.materializeBundle(TestBundleable.class, b1); assertThat(t).isEqualTo(f2); }
@Test(expected = BadBundleableException.class) public void testWrongClassThrows() throws Exception { TestBundleable t = new TestBundleable("alice", 32); Bundle b = t.toBundle(); BundleableUtil.materializeBundle("org.opensilk.Foo", b); }