Skip to content

Commit

Permalink
chore: Add temporary debug log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
warnyul committed Jul 31, 2024
1 parent 1393d1e commit 295c368
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tech.apter.junit.jupiter.robolectric.internal

import org.robolectric.annotation.Config
import org.robolectric.internal.ManifestIdentifier
import org.robolectric.internal.MavenManifestFactory
import org.robolectric.res.Fs
import tech.apter.junit.jupiter.robolectric.internal.extensions.createLogger
import java.nio.file.Path
import java.nio.file.Paths

internal class FakeMavenManifestFactory : MavenManifestFactory() {

private inline val logger get() = createLogger()

override fun identify(config: Config): ManifestIdentifier {
val manifestPath = config.manifest
if (manifestPath == Config.NONE) {
return ManifestIdentifier(null as String?, null, null, null, null)
}

// Try to locate the manifest file as a classpath resource; fallback to using the base dir.
val manifestFile: Path
val resourceName = if (manifestPath.startsWith("/")) manifestPath else ("/$manifestPath")
val resourceUrl = javaClass.getResource(resourceName)
if (resourceUrl != null && "file" == resourceUrl.protocol) {
// Construct a path to the manifest file relative to the current working directory.
val workingDirectory = Paths.get(System.getProperty("user.dir"))
val absolutePath = Fs.fromUrl(resourceUrl)
logger.warn { "user.dir=$workingDirectory" }
logger.warn { "resourceUrl=$resourceUrl" }
logger.warn { "absolutePath=$absolutePath" }

manifestFile = workingDirectory.relativize(absolutePath)
}
return super.identify(config)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tech.apter.junit.jupiter.robolectric.internal
import org.junit.runners.model.FrameworkMethod
import org.robolectric.RobolectricTestRunner
import org.robolectric.internal.AndroidSandbox
import org.robolectric.internal.ManifestFactory
import org.robolectric.internal.SandboxManager
import org.robolectric.internal.SandboxManager.SandboxBuilder
import org.robolectric.internal.SandboxTestRunner
Expand Down Expand Up @@ -119,5 +120,6 @@ internal class JUnit5RobolectricTestRunner(
defaultInjector().bind(SandboxBuilder::class.java, JUnit5RobolectricSandboxBuilder::class.java)
.bind(DependencyResolver::class.java, JUnit5MavenDependencyResolver::class.java)
.bind(SandboxManager::class.java, JUnit5RobolectricSandboxManager::class.java)
.bind(ManifestFactory::class.java, FakeMavenManifestFactory::class.java)
}
}

0 comments on commit 295c368

Please sign in to comment.