@@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow.relocation
33import assertk.assertThat
44import assertk.assertions.isEqualTo
55import com.github.jengelman.gradle.plugins.shadow.internal.mapName
6+ import org.junit.jupiter.api.Test
67import org.junit.jupiter.params.ParameterizedTest
78import org.junit.jupiter.params.provider.Arguments
89import org.junit.jupiter.params.provider.MethodSource
@@ -17,6 +18,30 @@ class RelocatorsTest {
1718 assertThat(actual).isEqualTo(expected)
1819 }
1920
21+ /* *
22+ * Verifies that a relocator with [Relocator.skipStringConstants] = true is skipped individually
23+ * when mapping literals, rather than short-circuiting the entire set of relocators.
24+ */
25+ @Test
26+ fun skipStringConstantsIsPerRelocator () {
27+ val skippingRelocator =
28+ SimpleRelocator (" org.package" , " shadow.org.package" , skipStringConstants = true )
29+ val normalRelocator = SimpleRelocator (" com.example" , " shadow.com.example" )
30+ val relocators = linkedSetOf(skippingRelocator, normalRelocator)
31+
32+ // The skipping relocator cannot match "com.example.Foo", but the normal one can.
33+ // Ensure the normal relocator is still applied even though the first one has
34+ // skipStringConstants.
35+ assertThat(relocators.mapName(" com.example.Foo" , mapLiterals = true ))
36+ .isEqualTo(" shadow.com.example.Foo" )
37+ // When mapLiterals=true, the skipping relocator should not apply to its own pattern.
38+ assertThat(relocators.mapName(" org.package.Bar" , mapLiterals = true ))
39+ .isEqualTo(" org.package.Bar" )
40+ // When mapLiterals=false, the skipping relocator applies normally.
41+ assertThat(relocators.mapName(" org.package.Bar" , mapLiterals = false ))
42+ .isEqualTo(" shadow.org.package.Bar" )
43+ }
44+
2045 private companion object {
2146 val primitiveTypes = setOf (' B' , ' C' , ' D' , ' F' , ' I' , ' J' , ' S' , ' Z' )
2247
0 commit comments