Skip to content

Instantly share code, notes, and snippets.

View PhilippeBoisney's full-sized avatar
🏠
Working from home

Boisney Philippe PhilippeBoisney

🏠
Working from home
View GitHub Profile
cd ~/Library/Android/sdk/platform-tools/
# Get the hash of the mitmproxy-ca certificate.
openssl x509 -inform PEM -subject_hash_old -in ~/.mitmproxy/mitmproxy-ca.pem | head -1
# We will use this hash value, append '.0' (dot zero) and use this as the filename for the resulting Android certificate
cat ~/.mitmproxy/mitmproxy-ca.pem > c8750f0d.0
openssl x509 -inform PEM -text -in ~/.mitmproxy/mitmproxy-ca.pem -out /dev/null >> c8750f0d.0
# In an other terminal, we will start the emulator with writable /system volume
class MainActivity: AppCompatActivity(), Navigable
fun EditText.afterTextChanged(afterTextChanged: (String) -> Unit) {
this.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(editable: Editable) {
afterTextChanged.invoke(editable.toString())
fun AppCompatActivity.configureSlideFromBottomEnterTransition() {
val decor = window.decorView
val actionBarId = R.id.action_bar_container
val transitionSet = TransitionSet()
val fadeActionBarAnimation = Fade().apply { duration = 100 }
fadeActionBarAnimation.addTarget(decor.findViewById(actionBarId) as? View)
transitionSet.addTransition(fadeActionBarAnimation)
class UserUnitTest : BaseTest() {
...
// TESTS
@Test
fun getUser_whenSuccess() {
// Prepare data
this.mockHttpResponse("getUser_whenSuccess.json", HttpURLConnection.HTTP_OK)
// Pre-test
@RunWith(AndroidJUnit4::class)
@LargeTest
class SearchUserFragmentTest: BaseIT() {
@Rule
@JvmField
val activityRule = ActivityTestRule(MainActivity::class.java, true, false)
@get:Rule
var executorRule = CountingTaskExecutorRule()
class UserRepositoryTest: BaseUT() {
// FOR DATA ---
private val userRepository by inject<UserRepository>()
// OVERRIDE ---
override fun isMockServerEnabled() = true
override fun setUp() {
super.setUp()
val viewModelModule = module {
viewModel { SearchUserViewModel(get(), get()) }
}
val networkModule = module {
factory<Interceptor> {
HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { Log.d("API", it) })
.setLevel(HttpLoggingInterceptor.Level.HEADERS)
}
factory { OkHttpClient.Builder().addInterceptor(get()).build() }
single {
class UserDataSourceFactory(private val repository: UserRepository,
private var query: String = "",
private var sort: String = "",
private val scope: CoroutineScope): DataSource.Factory<Int, User>() {
val source = MutableLiveData<UserDataSource>()
override fun create(): DataSource<Int, User> {
val source = UserDataSource(repository, query, sort, scope)
this.source.postValue(source)