Skip to content

Instantly share code, notes, and snippets.

@marcelpinto
Created July 21, 2018 19:01
Show Gist options
  • Save marcelpinto/20f1f882d4040c81314a1d697f10a75e to your computer and use it in GitHub Desktop.
Save marcelpinto/20f1f882d4040c81314a1d697f10a75e to your computer and use it in GitHub Desktop.
class NetworkFactoryTest {
private val baseUrl = "/"
private val testData = TestData("hello!")
private val testDataJson = "{\"name\":\"${testData.name}\"}"
private val mockWebServer = MockWebServer()
private val httpUrl = mockWebServer.url(baseUrl)
private val moshi = createMoshi()
private val authenticator = MyAuthenticator()
private val tokenStorage = mock<TokenStorage>()
private lateinit var tested: NetworkFactory
private lateinit var testApi: TestApi
@Before
fun setUp() {
val authInterceptor = AuthenticationInterceptor(tokenStorage)
tested = NetworkFactory(moshi, authInterceptor, authenticator)
testApi = tested.createApi(TestApi::class.java, httpUrl.toString())
}
}
private interface TestApi {
@GET("/test")
fun test(): Call<TestData>
}
private data class TestData(val name: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment