Skip to content

Commit

Permalink
Detekt + ktlint format
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrakal committed Jul 26, 2024
1 parent e32ebd6 commit 924aab5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DependencyGraph private constructor() {
val nodeInCurrentPath = path.contains(dependant)
if (nodeInCurrentPath) {
val pathText = path.joinToString(separator = ", ") { it.key }
throw IllegalStateException("Dependency cycle detected! Cycle in nodes: '${pathText}'.")
error("Dependency cycle detected! Cycle in nodes: '$pathText'.")
}
addConnections(dependant, into, path, visited)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,67 +154,73 @@ class DependencyGraphTest {
assert(statistics.modulesCount == 16)
assert(statistics.edgesCount == 45)
assert(
statistics.longestPath.nodeNames == listOf(
":feature:settings",
":app",
":feature:settings_entrance",
":lib:dynamic-features",
":core-android",
":core"
)
statistics.longestPath.nodeNames ==
listOf(
":feature:settings",
":app",
":feature:settings_entrance",
":lib:dynamic-features",
":core-android",
":core",
),
)
}

@Test(expected = IllegalStateException::class)
fun cyclesDoNotOverflow() {
val dependencyTree = DependencyGraph.create(
"feature" to "lib",
"lib" to "core",
"lib" to "feature",
"feature" to "core",
"app" to "feature"
)
val dependencyTree =
DependencyGraph.create(
"feature" to "lib",
"lib" to "core",
"lib" to "feature",
"feature" to "core",
"app" to "feature",
)

dependencyTree.subTree("app")
}

@Test
fun doesNotDetectCycleOnMultiEntry() {
val dependencyTree = DependencyGraph.create(
"feature" to "lib",
"app" to "lib",
"app" to "feature"
)
val dependencyTree =
DependencyGraph.create(
"feature" to "lib",
"app" to "lib",
"app" to "feature",
)

assert(dependencyTree.subTree("app").findRoot().key == "app")
}

@Test(expected = IllegalStateException::class)
fun detectsTwoNodesCycle() {
val dependencyTree = DependencyGraph.create(
"feature" to "app",
"app" to "feature"
)
val dependencyTree =
DependencyGraph.create(
"feature" to "app",
"app" to "feature",
)

dependencyTree.subTree("app")
}

@Test(expected = IllegalStateException::class)
fun detectsThreeNodesCycle() {
val dependencyTree = DependencyGraph.create(
"feature" to "app",
"app" to "lib",
"lib" to "feature"
)
val dependencyTree =
DependencyGraph.create(
"feature" to "app",
"app" to "lib",
"lib" to "feature",
)

dependencyTree.subTree("app")
}

@Test(expected = IllegalStateException::class)
fun detectsSingleNodeCycle() {
val dependencyTree = DependencyGraph.create(
"app" to "app",
)
val dependencyTree =
DependencyGraph.create(
"app" to "app",
)

dependencyTree.subTree("app")
}
Expand Down

0 comments on commit 924aab5

Please sign in to comment.