Skip to content

Commit

Permalink
Refactored URL.toPath method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Oct 15, 2024
1 parent 1f65320 commit fb3d9b2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ dependencies {

testImplementation 'javax.annotation:javax.annotation-api:1.3.2'
testImplementation "org.junit.jupiter:junit-jupiter:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testImplementation "org.mockito.kotlin:mockito-kotlin:5.3.1"
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
testImplementation "org.testcontainers:testcontainers:1.19.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,10 @@ internal class ExactproMetaInf(
}
}

private fun URL.toPath(): Path = toURI().run {
// the code below are added to provide windows compatibility
when (scheme) {
"file" -> Path.of(this)
"jar" -> Path.of(schemeSpecificPart
.substringBefore("!")
.removePrefix("file:"))
else -> error("The '$scheme' schema of '$this' URI can't be handled")
}
internal fun URL.toPath(): Path = when (protocol) {
"jar" -> URL(file).toPath() // the code below are added to provide windows compatibility
"file" -> Path.of(path)
else -> error("The '$protocol' protocol of '$this' URL can't be handled")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.exactpro.th2.common.schema.factory

import com.exactpro.th2.common.schema.factory.ExactproMetaInf.Companion.toPath
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
import java.net.URL
import java.nio.file.Path
import kotlin.test.assertEquals

class ExactproMetaInfTest {

@ParameterizedTest
@CsvSource(
"""jar:file:/C:/Users/test!user/common-0.0.0.jar!/META-INF/MANIFEST.MF,/C:/Users/test!user/common-0.0.0.jar!/META-INF/MANIFEST.MF""",
"""jar:file:/home/user/common-0.0.0-dev.jar!/META-INF/MANIFEST.MF,/home/user/common-0.0.0-dev.jar!/META-INF/MANIFEST.MF"""
)
fun `convert url to path test`(url: String, path: String) {
assertEquals(Path.of(path), URL(url).toPath())
}
}

0 comments on commit fb3d9b2

Please sign in to comment.