Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.content.Context;
      4 import android.text.ClipboardManager;
      5 import com.xtremelabs.robolectric.Robolectric;
      6 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
      7 import org.junit.Before;
      8 import org.junit.Test;
      9 import org.junit.runner.RunWith;
     10 
     11 import static org.hamcrest.core.IsEqual.equalTo;
     12 import static org.junit.Assert.assertFalse;
     13 import static org.junit.Assert.assertThat;
     14 import static org.junit.Assert.assertTrue;
     15 
     16 @RunWith(WithTestDefaultsRunner.class)
     17 public class ClipboardManagerTest {
     18 
     19     private ClipboardManager clipboardManager;
     20 
     21     @Before public void setUp() throws Exception {
     22         clipboardManager = (ClipboardManager) Robolectric.application.getSystemService(Context.CLIPBOARD_SERVICE);
     23     }
     24 
     25     @Test
     26     public void shouldStoreText() throws Exception {
     27         clipboardManager.setText("BLARG!!!");
     28         assertThat(clipboardManager.getText().toString(), equalTo("BLARG!!!"));
     29     }
     30 
     31     @Test
     32     public void shouldNotHaveTextIfTextIsNull() throws Exception {
     33         clipboardManager.setText(null);
     34         assertFalse(clipboardManager.hasText());
     35     }
     36 
     37     @Test
     38     public void shouldNotHaveTextIfTextIsEmpty() throws Exception {
     39         clipboardManager.setText("");
     40         assertFalse(clipboardManager.hasText());
     41     }
     42 
     43     @Test
     44     public void shouldHaveTextIfEmptyString() throws Exception {
     45         clipboardManager.setText(" ");
     46         assertTrue(clipboardManager.hasText());
     47     }
     48 
     49     @Test
     50     public void shouldHaveTextIfString() throws Exception {
     51         clipboardManager.setText("BLARG");
     52         assertTrue(clipboardManager.hasText());
     53     }
     54 }
     55