Merge pull request #68 from Philipp91/testfix

Fix broken unit test with manual dependency injection
This commit is contained in:
Abdelilah El Aissaoui 2022-12-30 16:54:28 +01:00 committed by GitHub
commit 723ff898a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,13 @@
package com.jetpackduba.gitnuro.app.git
import com.jetpackduba.gitnuro.credentials.GProcess
import com.jetpackduba.gitnuro.credentials.GRemoteSession
import com.jetpackduba.gitnuro.credentials.GSessionManager
import com.jetpackduba.gitnuro.credentials.*
import com.jetpackduba.gitnuro.di.factories.HttpCredentialsFactory
import com.jetpackduba.gitnuro.git.remote_operations.CloneRepositoryUseCase
import com.jetpackduba.gitnuro.git.remote_operations.HandleTransportUseCase
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.runBlocking
import org.eclipse.jgit.api.Git
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtensionContext
@ -32,12 +32,21 @@ class BeforeRepoAllTestsExtension : BeforeAllCallback, AfterAllCallback {
// The following line registers a callback hook when the root test context is shut down
context.root.getStore(GLOBAL).put("gitnuro_tests", this)
val credentialsStateManager = CredentialsStateManager()
val cloneRepositoryUseCase =
CloneRepositoryUseCase(HandleTransportUseCase(GSessionManager { GRemoteSession { GProcess() } }))
CloneRepositoryUseCase(
HandleTransportUseCase(
sessionManager = GSessionManager { GRemoteSession({ GProcess() }, credentialsStateManager) },
httpCredentialsProvider = object : HttpCredentialsFactory {
override fun create(git: Git?): HttpCredentialsProvider =
HttpCredentialsProvider(credentialsStateManager, git)
},
)
)
cloneRepositoryUseCase(repoDir, REPO_URL)
.flowOn(Dispatchers.IO)
.collect { newCloneStatus ->
println("Clonning test repository: $newCloneStatus")
println("Cloning test repository: $newCloneStatus")
}
}
}