@Test
  public void testCreatesWidget() throws IOException {
    lifeCycleAdapter.renderInitialization(video);

    assertTrue(MessageUtil.hasCreateOperation("tabris.widgets.Video"));
    JsonObject properties =
        MessageUtil.getOperationProperties(WidgetUtil.getId(video), CREATE, null);
    assertEquals(video.getURL().toString(), properties.get(Constants.PROPERTY_URL).asString());
  }
  @Test
  public void testRendersHeadPointer() throws IOException {
    lifeCycleAdapter.preserveValues(video);

    video.stepToTime(23);
    lifeCycleAdapter.renderChanges(video);

    JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null);
    assertEquals(23, properties.get(keyForEnum(PlaybackOptions.HEAD_POSITION)).asInt());
  }
  @Test
  public void testRendersRepeat() throws IOException {
    lifeCycleAdapter.preserveValues(video);

    video.setRepeat(true);
    lifeCycleAdapter.renderChanges(video);

    JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null);
    assertTrue(properties.get(keyForEnum(PlaybackOptions.REPEAT)).asBoolean());
  }
  @Test
  public void testRendersControlsVisible() throws IOException {
    lifeCycleAdapter.preserveValues(video);

    video.setPlayerControlsVisible(false);
    lifeCycleAdapter.renderChanges(video);

    JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null);
    assertFalse(properties.get(keyForEnum(PlaybackOptions.CONTROLS_VISIBLE)).asBoolean());
  }
  @Test
  public void testRendersSpeedBackward() throws IOException {
    lifeCycleAdapter.preserveValues(video);

    video.fastBackward(-2);
    lifeCycleAdapter.renderChanges(video);

    JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null);
    assertEquals(-2, properties.get(keyForEnum(PlaybackOptions.SPEED)).asDouble(), 0);
  }
 @Before
 public void setUp() {
   Display display = new Display();
   parent = new Shell(display);
   video = new Video("http://test.com", parent);
   playbackListener = mock(PlaybackListener.class);
   presentationListener = mock(PresentationListener.class);
   new Button(parent, SWT.PUSH);
   lifeCycleAdapter = (AbstractWidgetLCA) video.getAdapter(WidgetLifeCycleAdapter.class);
   environment.newRequest();
 }
  @Test
  public void testRendersPresentationListener() throws IOException {
    lifeCycleAdapter.preserveValues(video);

    video.addPresentationListener(presentationListener);
    lifeCycleAdapter.renderChanges(video);

    JsonObject properties =
        MessageUtil.getOperationProperties(WidgetUtil.getId(video), LISTEN, null);
    assertNotNull(properties.get(Constants.EVENT_PRESENTATION));
  }
  @Test
  public void testRendersPlaybackMode() throws IOException {
    lifeCycleAdapter.preserveValues(video);

    video.play();
    lifeCycleAdapter.renderChanges(video);

    JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null);
    assertEquals(
        keyForEnum(Playback.PLAY), properties.get(keyForEnum(PlaybackOptions.PLAYBACK)).asString());
  }
  @Test
  public void testFiresPresentationChangeToFullScreen() {
    environment.getRemoteObject().setHandler(new VideoOperationHandler(video));
    video.addPresentationListener(presentationListener);
    JsonObject parameters = new JsonObject();
    parameters.add(PROPERTY_PRESENTATION, Presentation.FULL_SCREEN.name());

    environment.dispatchNotify(Constants.EVENT_PRESENTATION, parameters);

    verify(presentationListener).presentationChanged(Presentation.FULL_SCREEN);
  }
  @Test
  public void testFiresPlaybackChange() {
    environment.getRemoteObject().setHandler(new VideoOperationHandler(video));
    video.addPlaybackListener(playbackListener);
    JsonObject parameters = new JsonObject();
    parameters.add(PROPERTY_PLAYBACK, Playback.ERROR.name());

    environment.dispatchNotify(Constants.EVENT_PLAYBACK, parameters);

    verify(playbackListener).playbackChanged(Playback.ERROR);
  }
  @Test
  public void testRendersPresentationMode() throws IOException {
    lifeCycleAdapter.preserveValues(video);

    video.setFullscreen(true);
    lifeCycleAdapter.renderChanges(video);

    JsonObject properties = MessageUtil.getOperationProperties(WidgetUtil.getId(video), SET, null);
    assertEquals(
        keyForEnum(Presentation.FULL_SCREEN),
        properties.get(keyForEnum(PlaybackOptions.PRESENTATION)).asString());
  }
  @Test
  public void testRendersPlaybackPlayOnce() {
    environment.getRemoteObject().setHandler(new VideoOperationHandler(video));
    video.addPlaybackListener(playbackListener);
    environment.newRequest();
    JsonObject parameters = new JsonObject();
    parameters.add(PROPERTY_PLAYBACK, Playback.PLAY.name());

    environment.dispatchNotify(Constants.EVENT_PLAYBACK, parameters);

    verify(playbackListener).playbackChanged(Playback.PLAY);
    assertFalse(hasOperation(WidgetUtil.getId(video), SET, null));
  }
  @Test
  public void testCreatesParent() throws IOException {
    lifeCycleAdapter.renderInitialization(video);

    assertTrue(isParentOfCreate("tabris.widgets.Video", WidgetUtil.getId(video.getParent())));
  }