Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import static org.hamcrest.CoreMatchers.nullValue;
      4 import static org.hamcrest.CoreMatchers.sameInstance;
      5 import static org.junit.Assert.assertThat;
      6 
      7 import org.junit.Before;
      8 import org.junit.Test;
      9 import org.junit.runner.RunWith;
     10 
     11 import android.app.Activity;
     12 import android.widget.SeekBar;
     13 
     14 import com.xtremelabs.robolectric.Robolectric;
     15 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
     16 import com.xtremelabs.robolectric.util.Transcript;
     17 
     18 @RunWith(WithTestDefaultsRunner.class)
     19 public class SeekBarTest {
     20 
     21 	private SeekBar seekBar;
     22 	private ShadowSeekBar shadow;
     23 	private SeekBar.OnSeekBarChangeListener listener;
     24 	private Transcript transcript;
     25 
     26 	@Before
     27 	public void setup() {
     28 	    seekBar = new SeekBar(new Activity());
     29         shadow = Robolectric.shadowOf(seekBar);
     30         listener = new TestSeekBarChangedListener();
     31         transcript = new Transcript();
     32         seekBar.setOnSeekBarChangeListener(listener);
     33 	}
     34 
     35     @Test
     36     public void testOnSeekBarChangedListener() {
     37         assertThat(shadow.getOnSeekBarChangeListener(), sameInstance(listener));
     38         seekBar.setOnSeekBarChangeListener(null);
     39         assertThat(shadow.getOnSeekBarChangeListener(), nullValue());
     40     }
     41 
     42     @Test
     43     public void testOnChangeNotification() {
     44     	seekBar.setProgress(5);
     45     	transcript.assertEventsSoFar("onProgressChanged() - 5");
     46     }
     47 
     48     private class TestSeekBarChangedListener implements SeekBar.OnSeekBarChangeListener {
     49 
     50         @Override
     51         public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
     52         	transcript.add("onProgressChanged() - " + progress);
     53         }
     54 
     55         @Override
     56         public void onStartTrackingTouch(SeekBar seekBar) {
     57         }
     58 
     59         @Override
     60         public void onStopTrackingTouch(SeekBar seekBar) {
     61         }
     62     }
     63 }
     64