145f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelpackage com.xtremelabs.robolectric.shadows; 245f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 345f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelimport android.accounts.Account; 445f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelimport android.os.Parcel; 545f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelimport com.xtremelabs.robolectric.WithTestDefaultsRunner; 645f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelimport org.junit.Test; 745f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelimport org.junit.runner.RunWith; 845f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 945f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelimport static org.hamcrest.CoreMatchers.equalTo; 108239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkelimport static org.hamcrest.CoreMatchers.not; 1145f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelimport static org.junit.Assert.assertThat; 1245f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 1345f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel@RunWith(WithTestDefaultsRunner.class) 1445f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkelpublic class AccountTest { 1545f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 1645f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel @Test 1745f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel public void shouldHaveStringsConstructor() throws Exception { 1845f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel Account account = new Account("name", "type"); 1945f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 2045f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel assertThat(account.name, equalTo("name")); 2145f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel assertThat(account.type, equalTo("type")); 2245f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel } 2345f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 2445f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel @Test 2545f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel public void shouldHaveParcelConstructor() throws Exception { 2645f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel Parcel p = Parcel.obtain(); 2745f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel p.writeString("name"); 2845f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel p.writeString("type"); 2945f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 30064f86b8dad1300e99457c9672a9ebbb6694ae4eJon Boekenoogen p.setDataPosition(0); 31064f86b8dad1300e99457c9672a9ebbb6694ae4eJon Boekenoogen 3245f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel Account account = new Account(p); 3345f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel assertThat(account.name, equalTo("name")); 3445f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel assertThat(account.type, equalTo("type")); 3545f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel } 3645f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 37fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen @Test 38fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen public void shouldHaveCreator() throws Exception { 39fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen Account expected = new Account("name", "type"); 40fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen Parcel p = Parcel.obtain(); 41fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen expected.writeToParcel(p, 0); 42fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen 43fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen p.setDataPosition(0); 44fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen 45fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen Account actual = Account.CREATOR.createFromParcel(p); 46fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen assertThat(expected, equalTo(actual)); 47fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen } 48fb82eae187c0cdff8efd2d93209e775cd0ed6a39Jon Boekenoogen 4945f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel @Test(expected = IllegalArgumentException.class) 5045f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel public void shouldThrowIfNameIsEmpty() throws Exception { 5145f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel new Account("", "type"); 5245f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel } 5345f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 5445f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel @Test(expected = IllegalArgumentException.class) 5545f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel public void shouldThrowIfTypeIsEmpty() throws Exception { 5645f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel new Account("name", ""); 5745f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel } 5845f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel 5945f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel @Test 6045f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel public void shouldHaveToString() throws Exception { 6145f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel Account account = new Account("name", "type"); 6245f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel assertThat(account.toString(), equalTo("Account {name=name, type=type}")); 6345f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel } 648239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel 658239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel @Test 668239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel public void shouldProvideEqualAndHashCode() throws Exception { 678239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel assertThat(new Account("a", "b"), equalTo(new Account("a", "b"))); 688239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel assertThat(new Account("a", "b"), not(equalTo(new Account("c", "b")))); 698239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel assertThat(new Account("a", "b").hashCode(), equalTo(new Account("a", "b").hashCode())); 708239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel assertThat(new Account("a", "b").hashCode(), not(equalTo(new Account("c", "b").hashCode()))); 718239cec3cb888ed2c71d4bb9cebf63432a3d06deJan Berkel } 7245f283443d645cb7f321b1a0f3eaf28407b699ccJan Berkel} 73