Skip to content

Instantly share code, notes, and snippets.

1. Testing the most recent or latest emitted item :

  • In our tests, in most of the cases, we are only interested in the last emitted value.For instance, for any UI state we are mostly interested on what will be the final UI state. And to test the last emitted value, we can do the following
            @Test
            fun verifyErrorOnUpcomingShiftsFetchUIState() = runDeputyTest {
                // given fetched result is failure
                coEvery { getGroupedUpcomingShifts(request) } returns Failure()
 // when
@laaptu
laaptu / pull.sh
Created March 3, 2016 05:41
Simple shell script to pull files from Android private storage
#!/bin/sh
# first argument pass the package name of the app
#echo $1
# the phone must be rooted for this to work
# this will dump the files directly in the location where this script is run
# ./pull.sh com.yourpackagename
adb shell "su -c 'chmod -R +rwx /data/data/$1;cp -r /data/data/$1/files /sdcard/;exit;'"
adb pull /sdcard/files
@laaptu
laaptu / SingleTon.java
Created March 3, 2016 05:21
Creating a singleton
public class DbManager {
static volatile DbManager singleton = null;
private DbManager() {
}
public static DbManager getInstance() {
if (singleton == null) {
synchronized (DbManager.class) {
if (singleton == null)
singleton = new DbManager();
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package tw.com.android.singularsdk.lib2;
import android.media.AudioTrack;
import android.os.SystemClock;
import android.util.Log;
@laaptu
laaptu / ParcelableSparseArray.java
Created July 15, 2015 06:59
Parcelable Sparse Array Implementation
package com.zala.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.SparseArray;
/**
* https://gist.github.com/kaushikgopal/9eea148a2188dc58fe37
*/
public class ParcelableSparseArray<T>
@laaptu
laaptu / DetailDeserializer.java
Last active August 29, 2015 14:22
Gson Deserializer test
package com.zala.utils.json;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.zala.model.base.Location;
import com.zala.model.base.Venue;
@laaptu
laaptu / ButtonProgress.java
Last active June 14, 2018 07:56
Using Styles values as custom attributes
package com.zala.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.zala.R;
@laaptu
laaptu / ApiManager.java
Last active December 13, 2016 10:11
Singleton class for RetroFit RestAdapter (Retrofit 1.9.0)
import retrofit.RestAdapter;
/**
* Singleton class for Retrofit RestAdapter and API (Retrofit 1.9.0)
*/
public class ApiManager {
// interface containing HTTP methods as given by Retrofit
private static RegionApi regionApi;
// static adapter to be used in entire app
@laaptu
laaptu / Events.java
Last active August 29, 2015 14:19
Making a single class to hold all the Events that would be posted and listened by EventBus
public class Events {
public abstract static class Event {
public String getTag() {
return this.getClass().getSimpleName();
}
}
public static class SearchResultEvent extends Event {
public int resultCount;
@laaptu
laaptu / SelectCurrentFragmentInViewPager.java
Created October 13, 2014 09:20
FragmentStateAdapter select current fragment. Viewpager select current fragment
int id = viewPager.getCurrentItem();
System.out.println(id);
FragmentStatePagerAdapter adapter = (FragmentStatePagerAdapter) viewPager.getAdapter();
Fragment fragment = (Fragment) adapter.instantiateItem(viewPager, viewPager.getCurrentItem());