Skip to content

Instantly share code, notes, and snippets.

@Kisty
Last active April 29, 2016 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kisty/d529505ca17b89971380546730387021 to your computer and use it in GitHub Desktop.
Save Kisty/d529505ca17b89971380546730387021 to your computer and use it in GitHub Desktop.
Robolectric shadow for EMVideoView
@Implements(com.devbrackets.android.exomedia.EMVideoView.class)
public class ShadowEMVideoView extends ShadowRelativeLayout {
public static final int STOP = 0;
public static final int START = 1;
public static final int SUSPEND = 2;
public static final int PAUSE = 3;
private int currentState = -1;
private int prevState;
private int currentPosition;
@Implementation
public void start() {
savePrevState();
currentState = ShadowEMVideoView.START;
}
@Implementation
public void stopPlayback() {
savePrevState();
currentState = ShadowEMVideoView.STOP;
}
@Implementation
public void suspend() {
savePrevState();
currentState = ShadowEMVideoView.SUSPEND;
}
@Implementation
public void pause() {
savePrevState();
currentState = ShadowEMVideoView.PAUSE;
}
@Implementation
public boolean isPlaying() {
return (currentState == ShadowEMVideoView.START);
}
@Implementation
public void seekTo(int msec) {
currentPosition = msec;
}
@Implementation
public long getCurrentPosition() {
return currentPosition;
}
/**
* Non-Android accessor.
*/
private void savePrevState() {
prevState = currentState;
}
}
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, shadows = {ShadowEMVideoView.class})
public class SingleVideoReviewFragmentTest {
private HPTVideo video;
private SingleVideoReviewFragment f;
private int score;
private int possibleScore;
@Before
public void setUp() throws Exception {
score = 4;
possibleScore = 5;
video = VideoSelector.getHptVideoSet(RuntimeEnvironment.application).getDataSet().videoList.get(0);
f = SingleVideoReviewFragment.newInstance(score, possibleScore, video);
startFragment();
}
private void startFragment() {
FragmentActivity activity = Robolectric.setupActivity(VideoActivity.class);
activity.getSupportFragmentManager()
.beginTransaction().add(R.id.container, f, SingleVideoReviewFragment.TAG).commit();
}
@Test
public void hasJumpToHazardButton() throws Exception {
View btn_jumpToHazard = f.getView().findViewById(R.id.button_jump_to_hazard);
assertNotNull(btn_jumpToHazard);
assertTrue(btn_jumpToHazard.getVisibility() == View.VISIBLE);
}
@Test
public void jumpToHazardButton_goesToHazard() throws Exception {
EMVideoView videoView = (EMVideoView) f.getView().findViewById(R.id.video);
ShadowEMVideoView shadowVideoView = (ShadowEMVideoView) ShadowExtractor.extract(videoView);
videoView.start();
assertTrue(shadowVideoView.isPlaying());
View btn_jumpToHazard = f.getView().findViewById(R.id.button_jump_to_hazard);
btn_jumpToHazard.performClick();
assertEquals("Button doesn't jump to hazard", video.hazardWindowList.get(0).openingTime / HPTVideo.UNIT_100_NANO_TO_MILLISECOND, shadowVideoView.getCurrentPosition());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment