Skip to content

Instantly share code, notes, and snippets.

class AuthenticationManagerTest : KoinTest{
@Before
fun initTest(){
loadKoinModules(listOf(module {
scope(TEST_SCOPE, override = true) { MockWebServer() }
factory (override = true){ AuthenticationManager(get<MockWebServer>().url("").toString()) }
}))
getKoin().createScope(TEST_SCOPE)
}
class AuthenticationManagerTest : KoinTest{
lateinit var server : MockWebServer
@Before
fun initTest(){
server = MockWebServer()
}
@After
class TestMockResponseFileReader{
@Test
fun `read simple file`(){
val reader = MockResponseFileReader("test.json")
assertEquals(reader.content, "success")
}
}
class MockResponseFileReader(path: String) {
val content: String
init {
val reader = InputStreamReader(this.javaClass.classLoader.getResourceAsStream(path))
content = reader.readText()
reader.close()
}
}
{
"token": "RpIjoiEJgOdrXjo9vM1espZWyaHDfCUfVXDII7-BWdaGtBctfwsCFXQ",
"idUser": 31098
}
class AuthenticationManager(endpoint: String) {
var login : LoginResponse? = null
private val okHttpClient = OkHttpClient.Builder().build()
private val retrofit = Retrofit.Builder()
.baseUrl(endpoint)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
private var shadow: Bitmap? = null
private val shadowPaint = Paint(ANTI_ALIAS_FLAG)
private var shadowRadius = context.resources.getDimension(R.dimen.shadow_default_radius)
private var shadowXOffset = context.resources.getDimension(R.dimen.shadow_default_x_translation)
private var shadowYOffset = context.resources.getDimension(R.dimen.shadow_default_y_translation)
private var shadowColor = ContextCompat.getColor(context, R.color.shadow_default_color)
private lateinit var shadowView: ImageView
fun getPath(width: Int, height: Int): Path {
return Path().apply {
val cutoutRadius = 50f
val cutoutWidth = if (cutoutRadius != 0f) cutoutRadius else width / 8f
val cutoutHeight = 3 * cutoutWidth / 4
val padding = 0f
val pathLeft = padding
val pathRight = width - padding
val pathTop = padding
override fun draw(canvas: Canvas) {
if (shapePath != null) {
canvas.clipPath(shapePath)
}
super.draw(canvas)
}
findViewById<TextView>(R.id.tv_round_outline).apply {
val provider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(0, 0, view.width, view.height, view.height / 2f)
}
}
outlineProvider = provider
clipToOutline = true
}