Skip to content

Commit

Permalink
refactor(model): Stop implementing Comparable with DependencyReference
Browse files Browse the repository at this point in the history
The first two test cases of `AnalyzerResultBuilder` [1] compare
instances of `DependencyReference`s in their assertion. Without
the `Comparable` interface implemented, these assertions fail because
the equality is changed to compare whether the instances (memory
locations) are the same. So, turn the `DependencyReference` into
a data class to fix that.

[1]: https://github.com/oss-review-toolkit/ort/blob/41b450b11c5930179016ba1a54d77e03f0c70b4c/analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt#L128-L154

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed May 27, 2024
1 parent 9ece42c commit 5d8f9d9
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions model/src/main/kotlin/DependencyGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ data class RootDependencyIndex(
* Note: This is by intention no data class. Equality is tested via references and not via the values contained.
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
class DependencyReference(
data class DependencyReference(
/**
* Stores the numeric index of the package dependency referenced by this object. The package behind this index can
* be resolved by evaluating the list of identifiers stored in [DependencyGraph] at this index.
Expand Down Expand Up @@ -326,17 +326,7 @@ class DependencyReference(
* A list of [Issue]s that occurred handling this dependency.
*/
val issues: List<Issue> = emptyList()
) : Comparable<DependencyReference> {
/**
* Define an order on [DependencyReference] instances. Instances are ordered by their indices and fragment indices.
*/
override fun compareTo(other: DependencyReference): Int =
if (pkg != other.pkg) {
pkg - other.pkg
} else {
fragment - other.fragment
}
}
)

/**
* A data class representing a node in the dependency graph.
Expand Down

0 comments on commit 5d8f9d9

Please sign in to comment.