Home | History | Annotate | Download | only in shadows
      1 package org.robolectric.shadows;
      2 
      3 import static org.assertj.core.api.Assertions.assertThat;
      4 
      5 import android.accounts.Account;
      6 import android.os.Parcel;
      7 import org.junit.Test;
      8 import org.junit.runner.RunWith;
      9 import org.robolectric.RobolectricTestRunner;
     10 
     11 @RunWith(RobolectricTestRunner.class)
     12 public class ShadowAccountTest {
     13 
     14   @Test
     15   public void shouldHaveStringsConstructor() throws Exception {
     16     Account account = new Account("name", "type");
     17 
     18     assertThat(account.name).isEqualTo("name");
     19     assertThat(account.type).isEqualTo("type");
     20   }
     21 
     22   @Test
     23   public void shouldHaveParcelConstructor() throws Exception {
     24     Account expected = new Account("name", "type");
     25     Parcel p = Parcel.obtain();
     26     expected.writeToParcel(p, 0);
     27     p.setDataPosition(0);
     28 
     29     Account actual = new Account(p);
     30     assertThat(actual).isEqualTo(expected);
     31   }
     32 
     33   @Test
     34   public void shouldBeParcelable() throws Exception {
     35     Account expected = new Account("name", "type");
     36     Parcel p = Parcel.obtain();
     37     expected.writeToParcel(p, 0);
     38     p.setDataPosition(0);
     39     Account actual = Account.CREATOR.createFromParcel(p);
     40     assertThat(actual).isEqualTo(expected);
     41   }
     42 
     43   @Test(expected = IllegalArgumentException.class)
     44   public void shouldThrowIfNameIsEmpty() throws Exception {
     45     new Account("", "type");
     46   }
     47 
     48   @Test(expected = IllegalArgumentException.class)
     49   public void shouldThrowIfTypeIsEmpty() throws Exception {
     50     new Account("name", "");
     51   }
     52 
     53   @Test
     54   public void shouldHaveToString() throws Exception {
     55     Account account = new Account("name", "type");
     56     assertThat(account.toString()).isEqualTo("Account {name=name, type=type}");
     57   }
     58 
     59   @Test
     60   public void shouldProvideEqualAndHashCode() throws Exception {
     61     assertThat(new Account("a", "b")).isEqualTo(new Account("a", "b"));
     62     assertThat(new Account("a", "b")).isNotEqualTo(new Account("c", "b"));
     63     assertThat(new Account("a", "b").hashCode()).isEqualTo(new Account("a", "b").hashCode());
     64     assertThat(new Account("a", "b").hashCode()).isNotEqualTo(new Account("c", "b").hashCode());
     65   }
     66 }
     67