Skip to content

Instantly share code, notes, and snippets.

View jobinlawrance's full-sized avatar

Jobin Lawrance jobinlawrance

View GitHub Profile
Film Genre Lead Studio Audience score Profitability Rotten Tomatoes Worldwide Gross Year
Zack and Miri Make a Porno Romance The Weinstein Company 70 1.747541667 64 $41.94 2008
Youth in Revolt Comedy The Weinstein Company 52 1.09 68 $19.62 2010
You Will Meet a Tall Dark Stranger Comedy Independent 35 1.211818182 43 $26.66 2010
When in Rome Comedy Disney 44 0 15 $43.04 2010
What Happens in Vegas Comedy Fox 72 6.267647029 28 $219.37 2008
Water For Elephants Drama 20th Century Fox 72 3.081421053 60 $117.09 2011
WALL-E Animation Disney 89 2.896019067 96 $521.28 2008
Waitress Romance Independent 67 11.0897415 89 $22.18 2007
Waiting For Forever Romance Independent 53 0.005 6 $0.03 2011
object TimeStampSurrogateSerializer : KSerializer<Timestamp> {
override val descriptor: SerialDescriptor = TimestampSurrogate.serializer().descriptor
override fun serialize(encoder: Encoder, value: Timestamp) {
val surrogate = TimestampSurrogate(value.date.getAsTime())
encoder.encodeSerializableValue(TimestampSurrogate.serializer(), surrogate)
}
override fun deserialize(decoder: Decoder): Timestamp {
val surrogate = decoder.decodeSerializableValue(TimestampSurrogate.serializer())
return Timestamp(Date(surrogate.timeInMillis))
// Third party data class that can't be changed
data class Timestamp(val date: Date)
@Serializable
@SerialName("Timestamp")
private class TimestampSurrogate(val timeInMillis: Long)
@Serializable
data class MyClass(
val name: String,
@Serializable(with = TimestampAsLongSerializable::class)
val timestamp: Timestamp
)
object TimeStampAsLongSerializer : KSerializer<Timestamp> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Date", PrimitiveKind.LONG)
override fun serialize(encoder: Encoder, value: Timestamp) {
encoder.encodeLong(value.timeInMillis)
}
override fun deserialize(decoder: Decoder): Timestamp {
return Timestamp(decoder.decodeLong())
}
}
// Third party data class that we cannot change
data class Timestamp(val timeInMillis: Long)
open class MockTestRunner : AndroidJUnitRunner() {
override fun onCreate(arguments: Bundle?) {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build())
super.onCreate(arguments)
}
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
return super.newApplication(cl, TestHomeApplication::class.java.name, context)
}
class TestHomeApplication: HomeApplication { // make HomeApplication open at this point
override fun onCreate() {
super.onCreate()
koinApplication.modules(testModule)
}
}
val testModule = module {
...
@Before
override fun setup() {
val realInteractor = get<HomeInteractor>()
mockedInteractor = Mockito.spy(realInteractor)
mockedModule = module {
single(override = true) { mockedInteractor }
}
loadKoinModules(mockModule)
@jobinlawrance
jobinlawrance / HomeActivityTest.kt
Created December 13, 2020 20:13
Testing using KoinTest
import ...
@RunWith(AndroidJUnit4ClassRunner::class)
class HomeActivityTest: KoinTest {
@get:Rule
var intentRule = IntentsTestRule(HomeActivity::class.java, true, false)
lateinit var mockModule: Module
lateinit var mockedInteractor: HomeInteractor