-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
4ee48b8
commit 4001044
Showing
21 changed files
with
109 additions
and
167 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
49 changes: 21 additions & 28 deletions
49
sample/app/src/test/kotlin/io/github/usefulness/licensee/PluginIntegrationTest.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 |
---|---|---|
@@ -1,39 +1,32 @@ | ||
package io.github.usefulness.licensee | ||
|
||
import io.githhub.usefulness.licensee.android.app.BuildConfig | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import se.premex.gross.ui.AssetLicenseeParser | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class PluginIntegrationTest { | ||
|
||
@Test | ||
fun checkGeneratedCode() { | ||
assertThat(Licensee.artifacts).isNotEmpty() | ||
val viewPagers = Licensee.artifacts.filter { it.groupId == "androidx.viewpager2" && it.artifactId == "viewpager2" } | ||
checkLoadedArtifacts( | ||
artifacts = Licensee.artifacts, | ||
isViewPager2Dependency = { groupId == "androidx.viewpager2" && artifactId == "viewpager2" }, | ||
) | ||
} | ||
|
||
@Suppress("KotlinConstantConditions") | ||
when (BuildConfig.BUILD_TYPE) { | ||
"release" -> assertThat(viewPagers).isEmpty() | ||
"debug" -> assertThat(viewPagers.single()).isEqualTo( | ||
Artifact( | ||
groupId = "androidx.viewpager2", | ||
artifactId = "viewpager2", | ||
version = "1.0.0", | ||
name = "AndroidX Widget ViewPager2", | ||
spdxLicenses = listOf( | ||
SpdxLicenses( | ||
identifier = "Apache-2.0", | ||
name = "Apache License 2.0", | ||
url = "https://www.apache.org/licenses/LICENSE-2.0", | ||
), | ||
), | ||
scm = Scm(url = "http://source.android.com"), | ||
unknownLicenses = emptyList(), | ||
), | ||
) | ||
@Test | ||
fun checkAssets() { | ||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
val source = runBlocking { AssetLicenseeParser(context.assets).readFromAssets() } | ||
|
||
else -> error("Not supported") | ||
} | ||
assertThat(Licensee.artifacts).isNotEmpty() | ||
checkLoadedArtifacts( | ||
artifacts = source, | ||
isViewPager2Dependency = { groupId == "androidx.viewpager2" && artifactId == "viewpager2" }, | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
sample/app/src/test/kotlin/io/github/usefulness/licensee/TestUtils.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,33 @@ | ||
package io.github.usefulness.licensee | ||
|
||
import io.githhub.usefulness.licensee.android.app.BuildConfig | ||
import org.assertj.core.api.Assertions.assertThat | ||
|
||
internal fun <T> checkLoadedArtifacts(artifacts: List<T>, isViewPager2Dependency: T.() -> Boolean) { | ||
assertThat(artifacts).isNotEmpty() | ||
val viewPagers = artifacts.filter { it.isViewPager2Dependency() } | ||
|
||
@Suppress("KotlinConstantConditions") | ||
when (BuildConfig.BUILD_TYPE) { | ||
"release" -> assertThat(viewPagers).isEmpty() | ||
"debug" -> assertThat(viewPagers.single().toString()).isEqualTo( | ||
Artifact( | ||
groupId = "androidx.viewpager2", | ||
artifactId = "viewpager2", | ||
version = "1.0.0", | ||
name = "AndroidX Widget ViewPager2", | ||
spdxLicenses = listOf( | ||
SpdxLicenses( | ||
identifier = "Apache-2.0", | ||
name = "Apache License 2.0", | ||
url = "https://www.apache.org/licenses/LICENSE-2.0", | ||
), | ||
), | ||
scm = Scm(url = "http://source.android.com"), | ||
unknownLicenses = emptyList(), | ||
).toString(), | ||
) | ||
|
||
else -> error("Not supported") | ||
} | ||
} |
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
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
7 changes: 4 additions & 3 deletions
7
...lin/se/premex/gross/core/LicenseParser.kt → ...sefulness/licensee/core/LicenseeParser.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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package se.premex.gross.core | ||
package io.github.usefulness.licensee.core | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.okio.decodeFromBufferedSource | ||
import okio.BufferedSource | ||
|
||
interface LicenseParser { | ||
@ExperimentalSerializationApi | ||
object LicenseeParser { | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
fun decode(source: BufferedSource) = Json.decodeFromBufferedSource<List<Artifact>>(source) | ||
} |
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
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
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
14 changes: 6 additions & 8 deletions
14
.../se/premex/gross/ui/AssetLicenseParser.kt → ...se/premex/gross/ui/AssetLicenseeParser.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
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
Oops, something went wrong.