@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
 public void shouldGetCmServer() throws CMException {
   Policy policy = mock(Policy.class);
   doReturn(policy).when(target).getPolicy();
   when(policy.getCMServer()).thenReturn(policyCMServer);
   assertEquals(policyCMServer, target.getCmServer());
 }
 @Test
 public void shouldNotRendarOnViewMode() throws OrchidException, IOException {
   when(contentSession.getMode()).thenReturn(1);
   target.localRender(oc);
   verify(javaScript, times(1)).render(oc);
   verify(syncButton, times(2)).render(oc);
 }
 @Test
 public void shouldGetCurrentRootSiteId() throws CMException {
   doReturn(policyCMServer).when(target).getCmServer();
   doReturn(configUtil).when(target).getConfiguration(policyCMServer);
   Policy topPolicy = mock(Policy.class);
   VersionedContentId id = mock(VersionedContentId.class);
   when(contentSession.getTopPolicy()).thenReturn(topPolicy);
   when(topPolicy.getContentId()).thenReturn(id);
   when(configUtil.getCurrentRootSiteId(id)).thenReturn(siteId);
   assertEquals(siteId, target.getCurrentRootSiteId());
 }
 @Test(expected = OrchidException.class)
 public void shouldThrowErrorWhenFaildTogetbrightcoveService()
     throws CMException, OrchidException {
   doThrow(new CMException("Unit test generated Exception")).when(target).getBrightcoveService();
   target.initSelf(oc);
 }