Created
November 16, 2020 12:45
-
-
Save thecodeside/cc818c3103926abc5cac97912511f69f to your computer and use it in GitHub Desktop.
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
import android.util.Base64 | |
import io.mockk.every | |
import io.mockk.mockkStatic | |
import io.mockk.unmockkStatic | |
import org.junit.jupiter.api.extension.AfterEachCallback | |
import org.junit.jupiter.api.extension.BeforeEachCallback | |
import org.junit.jupiter.api.extension.ExtensionContext | |
class Base64TestExtension : BeforeEachCallback, AfterEachCallback { | |
override fun beforeEach(context: ExtensionContext?) { | |
mockkStatic(Base64::class) | |
every { Base64.encodeToString(any(), any()) } answers { | |
java.util.Base64.getEncoder().encodeToString(this.firstArg()) | |
} | |
every { Base64.decode(any<String>(), any()) } answers { | |
java.util.Base64.getDecoder().decode(this.firstArg<String>()) | |
} | |
every { Base64.decode(any<ByteArray>(), any()) } answers { | |
java.util.Base64.getDecoder().decode(this.firstArg<ByteArray>()) | |
} | |
} | |
override fun afterEach(context: ExtensionContext?) { | |
unmockkStatic(Base64::class) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment