package com.atlassian.jira.plugins.dvcs.pageobjects.component;

import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.pageobjects.elements.query.Poller;
import org.openqa.selenium.By;

public class RepositoryDiv
{
    private final PageElement rootElement;
    private final PageElement syncRadio;

    public RepositoryDiv(PageElement rootElement)
    {
        this.rootElement = rootElement;
        this.syncRadio = rootElement.find(By.className("radio"));
    }

    public String getMessage()
    {
        return rootElement.find(By.xpath("td[3]/div")).getText();
    }

    public String getRepositoryName()
    {
        return rootElement.find(By.xpath("td[2]/a")).getText();
    }

    public PageElement getSyncIcon()
    {
        return rootElement.find(By.xpath("td[4]//span"));
    }

    public String getElementId()
    {
        return rootElement.getAttribute("id");
    }

    public String getRepositoryId()
    {
        return parseRepositoryId(getElementId());
    }

    public String parseRepositoryId(String elementId)
    {
        return elementId.substring(elementId.lastIndexOf("-") + 1);
    }

    public void enableSync()
    {
        Poller.waitUntilTrue("Sync radio should always be enabled", syncRadio.timed().isEnabled());
        syncRadio.click();
    }

}

@@ -434,16 +434,37 @@
 cRadio =
+ rootElement != null?
  rootEle
@@ -495,17 +495,25 @@
 radio%22))
-;
+ : null;%0A
 %0A    %7D%0A%0A
@@ -1199,32 +1199,77 @@
 bleSync()%0A    %7B%0A
+        if (syncRadio != null)%0A        %7B%0A    
         Poller.w
@@ -1360,16 +1360,20 @@
         
+    
 syncRadi
@@ -1379,21 +1379,31 @@
 io.click();%0A
+        %7D%0A
     %7D%0A%0A%7D%0A

fix null pointer exception