Skip to content

Commit b0729a8

Browse files
jimonthebarnyusufugurozbek
authored andcommitted
Fix test class not being ablew to find constructor
1 parent 7231ad7 commit b0729a8

File tree

1 file changed

+25
-3
lines changed
  • src/main/kotlin/com/github/yusufugurozbek/testcontainers/port/updater

1 file changed

+25
-3
lines changed

src/main/kotlin/com/github/yusufugurozbek/testcontainers/port/updater/DataSourceUrl.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ import com.github.yusufugurozbek.testcontainers.port.updater.settings.MatchMode.
55
import com.intellij.database.dataSource.LocalDataSource
66
import com.intellij.database.util.common.isNotNullOrEmpty
77

8-
data class DataSourceUrl(val beforePort: String, val port: String, val afterPort: String?, val urlExtractor : DataSourceUrlExtractor = DataSourceUrlExtractor()) {
8+
data class DataSourceUrl(val beforePort: String, val port: String, val afterPort: String?, private val urlExtractor : DataSourceUrlExtractor) {
9+
10+
constructor(beforePort: String, port: String, afterPort: String?) : this(beforePort, port, afterPort, DataSourceUrlExtractor())
911

1012
init {
11-
extractor = urlExtractor
13+
setUrlExtractor(urlExtractor)
1214
}
1315

1416
companion object {
15-
lateinit var extractor: DataSourceUrlExtractor
17+
private var extractor: DataSourceUrlExtractor = DataSourceUrlExtractor()
18+
19+
fun setUrlExtractor(extractor: DataSourceUrlExtractor) {
20+
// Initialize extractor when first needed
21+
22+
this.extractor = extractor
23+
24+
}
1625

1726
fun from(dataSource: LocalDataSource): DataSourceUrl? = from(dataSource.url)
1827

@@ -47,5 +56,18 @@ data class DataSourceUrl(val beforePort: String, val port: String, val afterPort
4756
private fun equalsIgnoringPort(other: DataSourceUrl): Boolean =
4857
(this.beforePort == other.beforePort) and (this.afterPort == other.afterPort)
4958

59+
override fun equals(other: Any?): Boolean {
60+
if (this === other) return true
61+
if (other !is DataSourceUrl) return false
62+
63+
return beforePort == other.beforePort &&
64+
port == other.port &&
65+
afterPort == other.afterPort
66+
}
67+
68+
override fun hashCode(): Int {
69+
return 31 * beforePort.hashCode() + port.hashCode() + (afterPort?.hashCode() ?: 0)
70+
}
71+
5072
override fun toString(): String = "$beforePort:$port$afterPort"
5173
}

0 commit comments

Comments
 (0)