// Path: src/main/java/com/github/quiram/buildhotspots/clients/CiClient.java
// public interface CiClient {
//     Optional<LocalDateTime> getDateOfOldestBuildFor(String jobName);
// 
//     List<String> getAllBuildConfigurations();
// 
//     List<String> getDependenciesFor(String jobName);
// 
//     List<String> getDependentsFor(String jobName);
// }
// 
// Path: src/main/java/com/github/quiram/buildhotspots/drawingdata/DependencyType.java
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "DependencyType", propOrder = { "buildConfigurationName" })
// public class DependencyType {
// 
//     @XmlElement(name = "BuildConfigurationName", required = true)
//     protected String buildConfigurationName;
// 
//     /**
//      * Gets the value of the buildConfigurationName property.
//      *
//      * @return
//      *     possible object is
//      *     {@link String }
//      *
//      */
//     public String getBuildConfigurationName() {
//         return buildConfigurationName;
//     }
// 
//     /**
//      * Sets the value of the buildConfigurationName property.
//      *
//      * @param value
//      *     allowed object is
//      *     {@link String }
//      *
//      */
//     public void setBuildConfigurationName(String value) {
//         this.buildConfigurationName = value;
//     }
// 
// }


import com.github.quiram.buildhotspots.clients.CiClient;
import com.github.quiram.buildhotspots.drawingdata.BuildConfigurationType;
import com.github.quiram.buildhotspots.drawingdata.BuildConfigurationType.BuildStats;
import com.github.quiram.buildhotspots.drawingdata.DependencyType;
import com.github.quiram.buildhotspots.drawingdata.Root;
import com.github.quiram.buildhotspots.drawingdata.Root.BuildConfigurations;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.InOrder;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import static java.time.LocalDateTime.now;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
        final String unrelatedDependent = "unrelated-dependent";

        when(ciClient.getDependentsFor(dependencyBuildName)).thenReturn(asList(buildName, unrelatedDependent));
        when(ciClient.getDependenciesFor(buildName)).thenReturn(singletonList(dependencyBuildName));

        Root documentRoot = drawingBuilder.buildFor(singletonList(buildName));
        assertRootHasTwoDependentBuilds(documentRoot, dependencyBuildName, buildName);
    }

    private void assertEmptyDocument(Root documentRoot) {
        assertNotNull(documentRoot);
        final BuildConfigurations buildConfigurations = documentRoot.getBuildConfigurations();
        assertNotNull(buildConfigurations);
        final List<BuildConfigurationType> buildConfiguration = buildConfigurations.getBuildConfiguration();
        assertTrue(buildConfiguration.isEmpty());
    }

    private void assertRootHasOneBuild(Root documentRoot, String buildName) {
        final List<BuildConfigurationType> buildConfigurationList = documentRoot.getBuildConfigurations().getBuildConfiguration();
        assertEquals(1, buildConfigurationList.size());
        final BuildConfigurationType buildConfigurationType = buildConfigurationList.get(0);
        assertEquals(buildName, buildConfigurationType.getName());
        assertNull(buildConfigurationType.getDependencies());
    }

    private void assertRootHasTwoDependentBuilds(Root documentRoot, String mainBuildName, String dependentBuildName) {
        final List<BuildConfigurationType> buildConfigurationList = documentRoot.getBuildConfigurations().getBuildConfiguration();
        assertEquals(2, buildConfigurationList.size());

        final BuildConfigurationType buildConfiguration = buildConfigurationList.stream().filter(b -> b.getName().equals(dependentBuildName)).findFirst().get();
// Path: src/main/java/com/github/quiram/buildhotspots/clients/CiClient.java
// public interface CiClient {
//     Optional<LocalDateTime> getDateOfOldestBuildFor(String jobName);
// 
//     List<String> getAllBuildConfigurations();
// 
//     List<String> getDependenciesFor(String jobName);
// 
//     List<String> getDependentsFor(String jobName);
// }
// 
// Path: src/main/java/com/github/quiram/buildhotspots/drawingdata/DependencyType.java
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlType(name = "DependencyType", propOrder = { "buildConfigurationName" })
// public class DependencyType {
// 
//     @XmlElement(name = "BuildConfigurationName", required = true)
//     protected String buildConfigurationName;
// 
//     /**
//      * Gets the value of the buildConfigurationName property.
//      *
//      * @return
//      *     possible object is
//      *     {@link String }
//      *
//      */
//     public String getBuildConfigurationName() {
//         return buildConfigurationName;
//     }
// 
//     /**
//      * Sets the value of the buildConfigurationName property.
//      *
//      * @param value
//      *     allowed object is
//      *     {@link String }
//      *
//      */
//     public void setBuildConfigurationName(String value) {
//         this.buildConfigurationName = value;
//     }
// 
// }


// Path: src/test/java/com/github/quiram/buildhotspots/DrawingBuilderTest.java
import com.github.quiram.buildhotspots.clients.CiClient;
import com.github.quiram.buildhotspots.drawingdata.BuildConfigurationType;
import com.github.quiram.buildhotspots.drawingdata.BuildConfigurationType.BuildStats;
import com.github.quiram.buildhotspots.drawingdata.DependencyType;
import com.github.quiram.buildhotspots.drawingdata.Root;
import com.github.quiram.buildhotspots.drawingdata.Root.BuildConfigurations;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.InOrder;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import static java.time.LocalDateTime.now;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;

        final String unrelatedDependent = "unrelated-dependent";

        when(ciClient.getDependentsFor(dependencyBuildName)).thenReturn(asList(buildName, unrelatedDependent));
        when(ciClient.getDependenciesFor(buildName)).thenReturn(singletonList(dependencyBuildName));

        Root documentRoot = drawingBuilder.buildFor(singletonList(buildName));
        assertRootHasTwoDependentBuilds(documentRoot, dependencyBuildName, buildName);
    }

    private void assertEmptyDocument(Root documentRoot) {
        assertNotNull(documentRoot);
        final BuildConfigurations buildConfigurations = documentRoot.getBuildConfigurations();
        assertNotNull(buildConfigurations);
        final List<BuildConfigurationType> buildConfiguration = buildConfigurations.getBuildConfiguration();
        assertTrue(buildConfiguration.isEmpty());
    }

    private void assertRootHasOneBuild(Root documentRoot, String buildName) {
        final List<BuildConfigurationType> buildConfigurationList = documentRoot.getBuildConfigurations().getBuildConfiguration();
        assertEquals(1, buildConfigurationList.size());
        final BuildConfigurationType buildConfigurationType = buildConfigurationList.get(0);
        assertEquals(buildName, buildConfigurationType.getName());
        assertNull(buildConfigurationType.getDependencies());
    }

    private void assertRootHasTwoDependentBuilds(Root documentRoot, String mainBuildName, String dependentBuildName) {
        final List<BuildConfigurationType> buildConfigurationList = documentRoot.getBuildConfigurations().getBuildConfiguration();
        assertEquals(2, buildConfigurationList.size());

        final BuildConfigurationType buildConfiguration = buildConfigurationList.stream().filter(b -> b.getName().equals(dependentBuildName)).findFirst().get();
        final List<DependencyType> dependencyList = buildConfiguration.getDependencies().getDependency();