Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.Test
import org.mockito.Mockito
import javax.inject.Inject
import javax.servlet.http.HttpServletRequest
interface Database {
fun findUser(): User
class User(val name: String)
inline fun <reified T : Any> mock() = Mockito.mock(
class MyComponent @Inject constructor(val request: HttpServletRequest, val database: Database) {
val user: User by lazy {
fun getUsername(): String {
class MyComponentTest {
val request = mock<HttpServletRequest>()
val database = mock<Database>()
val sut = MyComponent(request, database)
fun `username`() {
val username = sut.getUsername()
MatcherAssert.assertThat(username, Matchers.equalTo("test"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.