Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.widget.ProgressBar;
      4 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
      5 import org.junit.Before;
      6 import org.junit.Test;
      7 import org.junit.runner.RunWith;
      8 
      9 import static org.hamcrest.CoreMatchers.equalTo;
     10 import static org.junit.Assert.assertEquals;
     11 import static org.junit.Assert.assertFalse;
     12 import static org.junit.Assert.assertThat;
     13 import static org.junit.Assert.assertTrue;
     14 
     15 @RunWith(WithTestDefaultsRunner.class)
     16 public class ProgressBarTest {
     17 
     18     private int[] testValues = {0, 1, 2, 100};
     19     private ProgressBar progressBar;
     20 
     21     @Before
     22     public void setUp() {
     23         progressBar = new ProgressBar(null);
     24     }
     25 
     26     @Test
     27     public void shouldInitMaxTo100() {
     28         assertThat(progressBar.getMax(), equalTo(100));
     29     }
     30 
     31     @Test
     32     public void testMax() {
     33         for (int max : testValues) {
     34             progressBar.setMax(max);
     35             assertThat(progressBar.getMax(), equalTo(max));
     36         }
     37     }
     38 
     39     @Test
     40     public void testProgress() {
     41         for (int progress : testValues) {
     42             progressBar.setProgress(progress);
     43             assertThat(progressBar.getProgress(), equalTo(progress));
     44         }
     45     }
     46 
     47     @Test
     48     public void testSecondaryProgress() {
     49         for (int progress : testValues) {
     50             progressBar.setSecondaryProgress(progress);
     51             assertThat(progressBar.getSecondaryProgress(), equalTo(progress));
     52         }
     53     }
     54 
     55     @Test
     56     public void testIsDeterminate() throws Exception {
     57         assertFalse(progressBar.isIndeterminate());
     58         progressBar.setIndeterminate(true);
     59         assertTrue(progressBar.isIndeterminate());
     60     }
     61 
     62     @Test
     63     public void shouldReturnZeroAsProgressWhenIndeterminate() throws Exception {
     64         progressBar.setProgress(10);
     65         progressBar.setSecondaryProgress(20);
     66         progressBar.setIndeterminate(true);
     67         assertEquals(0, progressBar.getProgress());
     68         assertEquals(0, progressBar.getSecondaryProgress());
     69         progressBar.setIndeterminate(false);
     70 
     71         assertEquals(10, progressBar.getProgress());
     72         assertEquals(20, progressBar.getSecondaryProgress());
     73     }
     74 
     75     @Test
     76     public void shouldNotSetProgressWhenIndeterminate() throws Exception {
     77         progressBar.setIndeterminate(true);
     78         progressBar.setProgress(10);
     79         progressBar.setSecondaryProgress(20);
     80         progressBar.setIndeterminate(false);
     81 
     82         assertEquals(0, progressBar.getProgress());
     83         assertEquals(0, progressBar.getSecondaryProgress());
     84     }
     85 
     86     @Test
     87     public void testIncrementProgressBy() throws Exception {
     88         assertEquals(0, progressBar.getProgress());
     89         progressBar.incrementProgressBy(1);
     90         assertEquals(1, progressBar.getProgress());
     91         progressBar.incrementProgressBy(1);
     92         assertEquals(2, progressBar.getProgress());
     93 
     94         assertEquals(0, progressBar.getSecondaryProgress());
     95         progressBar.incrementSecondaryProgressBy(1);
     96         assertEquals(1, progressBar.getSecondaryProgress());
     97         progressBar.incrementSecondaryProgressBy(1);
     98         assertEquals(2, progressBar.getSecondaryProgress());
     99     }
    100 
    101     @Test
    102     public void shouldRespectMax() throws Exception {
    103         progressBar.setMax(20);
    104         progressBar.setProgress(50);
    105         assertEquals(20, progressBar.getProgress());
    106     }
    107 }
    108