-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
64 deletions.
There are no files selected for viewing
63 changes: 0 additions & 63 deletions
63
...com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerSpec.groovy
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...lin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.github.jengelman.gradle.plugins.shadow.transformers | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.Arguments | ||
import org.junit.jupiter.params.provider.MethodSource | ||
|
||
class ServiceFileTransformerTest : TransformerTestSupport<ServiceFileTransformer>() { | ||
@BeforeEach | ||
fun setup() { | ||
transformer = ServiceFileTransformer() | ||
} | ||
|
||
@ParameterizedTest(name = "{index} => path={0}, exclude={1}, expected={2}") | ||
@MethodSource("canTransformResourceData") | ||
fun `test canTransformResource`(path: String, exclude: Boolean, expected: Boolean) { | ||
if (exclude) { | ||
transformer.exclude(path) | ||
} | ||
assertThat(transformer.canTransformResource(getFileElement(path))).isEqualTo(expected) | ||
} | ||
|
||
@ParameterizedTest(name = "{index} => path={0}") | ||
@MethodSource("transformsServiceFileData") | ||
fun `test transforms service file`(path: String, input1: String, input2: String, output: String) { | ||
val element = getFileElement(path) | ||
val transformer = ServiceFileTransformer() | ||
|
||
if (transformer.canTransformResource(element)) { | ||
transformer.transform(context(path, input1)) | ||
transformer.transform(context(path, input2)) | ||
} | ||
|
||
assertThat(transformer.hasTransformedResource()).isEqualTo(true) | ||
val transformedText = transformer.serviceEntries.getValue(path).toInputStream().bufferedReader().readText() | ||
assertThat(transformedText).isEqualTo(output) | ||
} | ||
|
||
@Test | ||
fun `test excludes Groovy extension module descriptor files by default`() { | ||
val transformer = ServiceFileTransformer() | ||
val element = getFileElement("META-INF/services/org.codehaus.groovy.runtime.ExtensionModule") | ||
|
||
assertThat(transformer.canTransformResource(element)).isEqualTo(false) | ||
} | ||
|
||
private companion object { | ||
@JvmStatic | ||
fun canTransformResourceData() = listOf( | ||
// path, exclude, expected | ||
Arguments.of("META-INF/services/java.sql.Driver", false, true), | ||
Arguments.of("META-INF/services/io.dropwizard.logging.AppenderFactory", false, true), | ||
Arguments.of("META-INF/services/org.apache.maven.Shade", true, false), | ||
Arguments.of("META-INF/services/foo/bar/moo.goo.Zoo", false, true), | ||
Arguments.of("foo/bar.properties", false, false), | ||
Arguments.of("foo.props", false, false), | ||
) | ||
|
||
@JvmStatic | ||
fun transformsServiceFileData() = listOf( | ||
// path, input1, input2, output | ||
Arguments.of("META-INF/services/com.acme.Foo", "foo", "bar", "foo\nbar"), | ||
Arguments.of("META-INF/services/com.acme.Bar", "foo\nbar", "zoo", "foo\nbar\nzoo"), | ||
) | ||
} | ||
} |