@Before
  public void before()
      throws OrchidException, IOException, CMException, BrightcoveException, ImageFormatException,
          ImageTooBigException, URISyntaxException {
    MockitoAnnotations.initMocks(this);

    when(contentSession.getMode()).thenReturn(2);
    when(contentSession.getTopWidget()).thenReturn(policyWidget);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.NAME)).thenReturn(name);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.SHORT_DESCRIPTION))
        .thenReturn(shortDescription);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.LONG_DESCIPTION))
        .thenReturn(longDescription);
    when(contentSession.findPolicyWidget(OBrightcoveSyncWidget.IMAGE_TYPE))
        .thenReturn(selectableSubFieldPolicyWidget);
    when(contentSession.getTopWidget()).thenReturn(policyWidget);
    when(name.getChildWidget()).thenReturn(nameWidget);
    when(shortDescription.getChildWidget()).thenReturn(shortDescriptionWidget);
    when(longDescription.getChildWidget()).thenReturn(longDescriptionWidget);
    when(nameWidget.getCompoundId()).thenReturn("name_id");
    when(shortDescriptionWidget.getCompoundId()).thenReturn("short_id");
    when(longDescriptionWidget.getCompoundId()).thenReturn("long_id");
    when(video.getName()).thenReturn("video name");
    when(video.getShortDescription()).thenReturn("video short description");
    when(video.getLongDescription()).thenReturn("video long description");
    when(video.getThumbnailUrl())
        .thenReturn(
            getClass().getClassLoader().getResource("small.jpg").toURI().toURL().toString());
    when(brightcoveService.findByVideoID(1)).thenReturn(video);
    when(policy.getId()).thenReturn("1");
    when(policy.getChildPolicy("categorization")).thenReturn(categorizationProvider);
    when(policy.getSubFieldPolicy()).thenReturn(selectableSubFieldPolicy);
    when(selectableSubFieldPolicy.getChildPolicy(BrightcoveVideoPolicy.IMAGE))
        .thenReturn(imageManagerPolicy);
    when(policyCMServer.getPolicy(BrightcoveConfigPolicy.CONTENT_ID)).thenReturn(configPolicy);

    doNothing().when(javaScript).render(oc);
    doNothing().when(syncButton).render(oc);

    target = spy(new OBrightcoveSyncWidget());
    doReturn(brightcoveService).when(target).getBrightcoveService();
    doReturn(policy).when(target).getPolicy();
    doReturn(javaScript).when(target).getOJavaScript();
    doReturn(syncButton).when(target).getOButton();
    doReturn(contentSession).when(target).getContentSession();
    target.initSelf(oc);
    target.localRender(oc);
  }
 @Test(expected = OrchidException.class)
 public void shouldThrowErrorWhenFaildTogetbrightcoveService()
     throws CMException, OrchidException {
   doThrow(new CMException("Unit test generated Exception")).when(target).getBrightcoveService();
   target.initSelf(oc);
 }