Skip to content

Commit

Permalink
Merge pull request robolectric#166 from zoodles/master
Browse files Browse the repository at this point in the history
Enhancements to ShadowConfiguration, ShadowVideoView, and ShadowCountDownTimer
  • Loading branch information
mportuesisf committed Dec 9, 2011
2 parents 61229a6 + 2b51f8d commit d743325
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.xtremelabs.robolectric.shadows;

import java.util.Locale;

import android.content.res.Configuration;

import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;
Expand All @@ -14,10 +17,14 @@ public class ShadowConfiguration {
public int screenLayout;
public int touchscreen;
public int orientation;

@Implementation
public void setToDefaults() {
realConfiguration.screenLayout = Configuration.SCREENLAYOUT_LONG_NO |
Configuration.SCREENLAYOUT_SIZE_NORMAL;
}

public void setLocale( Locale l ) {
realConfiguration.locale = l;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ public void invokeFinish() {
public boolean hasStarted() {
return started;
}

public long getCountDownInterval() {
return countDownInterval;
}

public long getMillisInFuture() {
return millisInFuture;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ShadowVideoView extends ShadowSurfaceView {
private MediaPlayer.OnPreparedListener preparedListener;

private Uri uri;
private String path;

public static final int STOP = 0;
public static final int START = 1;
Expand All @@ -42,6 +43,11 @@ public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
completionListner = l;
}

@Implementation
public void setVideoPath(String path) {
this.path = path;
}

@Implementation
public void setVideoURI(Uri uri) {
this.uri = uri;
Expand Down Expand Up @@ -112,12 +118,20 @@ public MediaPlayer.OnCompletionListener getOnCompletionListener() {
return completionListner;
}

/**
* Non-Android accessor.
* @return
*/
public String getVideoPath() {
return path;
}

/**
* Non-Android accessor.
* @return
*/
public String getVideoURIString() {
return uri.toString();
return uri == null ? null : uri.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.xtremelabs.robolectric.shadows;


import java.util.Locale;

import android.content.res.Configuration;

import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -14,16 +18,27 @@
public class ConfigurationTest {

private Configuration configuration;
private ShadowConfiguration shConfiguration;

@Before
public void setUp() throws Exception {
configuration = new Configuration();
shConfiguration = Robolectric.shadowOf( configuration );
}

@Test
public void testSetToDefaults() throws Exception {
configuration.setToDefaults();
assertThat(configuration.screenLayout, equalTo(Configuration.SCREENLAYOUT_LONG_NO | Configuration.SCREENLAYOUT_SIZE_NORMAL));
}

@Test
public void testSetLocale() {
shConfiguration.setLocale( Locale.US );
assertThat( configuration.locale, equalTo( Locale.US ) );

shConfiguration.setLocale( Locale.FRANCE);
assertThat( configuration.locale, equalTo( Locale.FRANCE ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@ public void testCancel() {
shadowCountDownTimer.cancel();
assertThat(shadowCountDownTimer.hasStarted(), equalTo(false));
}

@Test
public void testAccessors() {
assertThat(shadowCountDownTimer.getCountDownInterval(), equalTo(countDownInterval));
assertThat(shadowCountDownTimer.getMillisInFuture(), equalTo(millisInFuture));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Before;
Expand Down Expand Up @@ -48,11 +49,22 @@ public void shouldSetOnCompletionListener() throws Exception {
assertThat((TestCompletionListener)(shadowVideoView.getOnCompletionListener()), sameInstance(l));
}

@Test
public void shouldSetVideoPath() throws Exception {
view.setVideoPath("video.mp4");
ShadowVideoView shadowVideoView = Robolectric.shadowOf(view);
assertThat(shadowVideoView.getVideoPath(), equalTo("video.mp4"));
view.setVideoPath(null);
assertThat(shadowVideoView.getVideoPath(), nullValue());
}

@Test
public void shouldSetVideoURI() throws Exception {
view.setVideoURI(Uri.parse("video.mp4"));
ShadowVideoView shadowVideoView = Robolectric.shadowOf(view);
assertThat(shadowVideoView.getVideoURIString(), equalTo("video.mp4"));
view.setVideoURI(null);
assertThat(shadowVideoView.getVideoURIString(), nullValue());
}

@Test
Expand Down

0 comments on commit d743325

Please sign in to comment.