Skip to content

Instantly share code, notes, and snippets.

View nhoxbypass's full-sized avatar
🐧
I come from Earth

Tam H. Doan nhoxbypass

🐧
I come from Earth
View GitHub Profile
class MyPresenterTest {
@Test
fun onOpenCameraButtonClick_postM() {
// Arrange
Mockito.`when`(mockBuildProvider.isMarshmallowAndAbove()).thenReturn(true)
// Action
presenter.onCameraButtonClick()
// Assert
class MyPresenterTest {
@Mock
private lateinit var mockBuildProvider: BuildVersionProvider
@Mock
private lateinit var mockView: MyView
private lateinit var presenter: MyPresenter
@Before
class MyPresenter(val view: MyView, val buildProvider: BuildVersionProvider) : BasePresenter() {
override fun onCameraButtonClick() {
if (buildProvider.isMarshmallowAndAbove()) {
view.requestCameraPermission()
} else {
navigator.openCamera()
}
}
}
@RunWith(PowerMockRunner::class)
@PrepareForTest(Build.VERSION::class)
class MyPresenterTest {
@Test
fun onOpenCameraButtonClick_postM() {
Whitebox.setInternalState(Build.VERSION::class.java, "SDK_INT", 23)
// Verify flow request Runtime Permissions
// ...
}
class MyPresenterTest {
@Test
fun onOpenCameraButtonClick_postM() {
setFinalStatic(Build.VERSION::class.java.getField("SDK_INT"), 23)
// Verify flow request Runtime Permissions
// ...
}
@After
@Throws(Exception::class)
fun setFinalStatic(field: Field, newValue: Any) {
field.setAccessible(true)
val modifiersField = Field::class.java.getDeclaredField("modifiers")
modifiersField.setAccessible(true)
modifiersField.setInt(field, field.getModifiers() and Modifier.FINAL.inv())
field.set(null, newValue)
}
@nhoxbypass
nhoxbypass / app.kt
Last active January 17, 2020 11:13
Kotlin utils package level JVM name
@file:JvmName("SaberUtils")
package org.example
fun makeLightSaber() { /*...*/ }
// Generated class
public final class SaberFactory {
public static final SaberFactory INSTANCE = new SaberFactory();
private SaberFactory() { }
public final void makeLightSaber() { /*...*/ }
}
@nhoxbypass
nhoxbypass / AppKt.java
Last active January 16, 2020 11:55
Kotlin utils: package-level method (generated)
package org.example
// Generated class
class AppKt {
public static void makeLightSaber() { /*..*/ }
}
@nhoxbypass
nhoxbypass / app.kt
Last active January 16, 2020 11:54
Kotlin utils: package-level method
package org.example
fun makeLightSaber() { /*...*/ }