createMicroservices() {
+ return LongStream.rangeClosed(1, 12)
+ .mapToObj(i -> new MicroserviceBuilder().withId(i).build())
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Graph will contain two connected components, one of them has cycle
+ *
+ * First component with cycle 1->2->3->1
+ * Second component without cycle 5->6, 5->7
+ *
+ * @return dependencies
+ */
+ private List createDependenciesWithCycleInSameComponent() {
+ final List dependencies = new ArrayList<>();
+
+ // First component with cycle 1->2->3->1
+ dependencies.add(new DependencyBuilder()
+ .withId(1L).withSource(1L).withTarget(2L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(2L).withSource(2L).withTarget(3L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(3L).withSource(3L).withTarget(1L)
+ .build());
+
+ // Second component without cycle 5->6, 5->7
+ dependencies.add(new DependencyBuilder()
+ .withId(4L).withSource(5L).withTarget(6L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(5L).withSource(5L).withTarget(7L)
+ .build());
+
+
+ return dependencies;
+ }
+
+ /**
+ * Graph will contain two connected components, one of them has cycle
+ * First component without cycle 1->2, 2->3, 2->4
+ * Second component with cycle 6->7->8->6
+ *
+ * @return dependencies
+ */
+ private List createDependenciesWithCycleInOtherComponent() {
+ final List dependencies = new ArrayList<>();
+
+ // First component without cycle 1->2, 2->3, 2->4
+ dependencies.add(new DependencyBuilder()
+ .withId(1L).withSource(1L).withTarget(2L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(2L).withSource(2L).withTarget(3L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(3L).withSource(2L).withTarget(4L)
+ .build());
+
+ // Second component with cycle 6->7->8->6
+ dependencies.add(new DependencyBuilder()
+ .withId(4L).withSource(5L).withTarget(6L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(5L).withSource(6L).withTarget(7L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(6L).withSource(7L).withTarget(8L)
+ .build());
+ dependencies.add(new DependencyBuilder()
+ .withId(7L).withSource(8L).withTarget(6L)
+ .build());
+
+
+ return dependencies;
+ }
+
+ private List createDependencies() {
+ final List dependencies = new ArrayList<>();
+
+ dependencies.add(new DependencyBuilder()
+ .withId(1L).withSource(1L).withTarget(2L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(2L).withSource(2L).withTarget(4L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(3L).withSource(6L).withTarget(4L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(4L).withSource(4L).withTarget(5L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(5L).withSource(4L).withTarget(7L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(6L).withSource(4L).withTarget(8L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(7L).withSource(3L).withTarget(9L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(8L).withSource(3L).withTarget(11L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(9L).withSource(12L).withTarget(1L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(10L).withSource(7L).withTarget(5L)
+ .build());
+
+ dependencies.add(new DependencyBuilder()
+ .withId(11L).withSource(10L).withTarget(1L)
+ .build());
+
+ return dependencies;
+ }
+}
diff --git a/src/test/java/com/github/microcatalog/utils/DependencyBuilderTest.java b/src/test/java/com/github/microcatalog/utils/DependencyBuilderTest.java
new file mode 100644
index 0000000..56e6472
--- /dev/null
+++ b/src/test/java/com/github/microcatalog/utils/DependencyBuilderTest.java
@@ -0,0 +1,19 @@
+package com.github.microcatalog.utils;
+
+import com.github.microcatalog.domain.Dependency;
+import com.github.microcatalog.domain.Microservice;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class DependencyBuilderTest {
+
+ @Test
+ void build() {
+ DependencyBuilder builder = new DependencyBuilder();
+ Dependency dependency = builder.withId(1L).withSource(2L).withTarget(3L).build();
+ assertThat(dependency).isNotNull().extracting(Dependency::getId).isEqualTo(1L);
+ assertThat(dependency.getSource()).isNotNull().extracting(Microservice::getId).isEqualTo(2L);
+ assertThat(dependency.getTarget()).isNotNull().extracting(Microservice::getId).isEqualTo(3L);
+ }
+}
diff --git a/src/test/java/com/github/microcatalog/utils/MicroserviceBuilderTest.java b/src/test/java/com/github/microcatalog/utils/MicroserviceBuilderTest.java
new file mode 100644
index 0000000..0ad8ec6
--- /dev/null
+++ b/src/test/java/com/github/microcatalog/utils/MicroserviceBuilderTest.java
@@ -0,0 +1,16 @@
+package com.github.microcatalog.utils;
+
+import com.github.microcatalog.domain.Microservice;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class MicroserviceBuilderTest {
+
+ @Test
+ void build() {
+ MicroserviceBuilder builder = new MicroserviceBuilder();
+ Microservice microservice = builder.withId(1L).build();
+ assertThat(microservice).isNotNull().extracting(Microservice::getId).isEqualTo(1L);
+ }
+}