Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Vaughan vaughandroid

View GitHub Profile
@vaughandroid
vaughandroid / Animal.kt
Last active Apr 26, 2019
Kotlin dog riddle solution
View Animal.kt
// We are modelling different types of animals.
sealed class Animal {
// Cats are simple. A cat is a cat.
object Cat : Animal()
sealed class Dog: Animal() {
companion object : Dog()
@vaughandroid
vaughandroid / RxArchitecture.java
Last active Sep 22, 2017
Experimenting with Rx architecture
View RxArchitecture.java
class Wiring {
private final Observable<ViewModel> viewModelObservable;
Wiring(View view, ActionDispatcher actionDispatcher, Service service, ViewModelScanner viewModelScanner) {
viewModelObservable = view.uiEventObservable()
.compose(actionDispatcher.uiEventToAction())
.compose(service.actionToResult())
.compose(viewModelScanner.resultToViewModel());
@vaughandroid
vaughandroid / MyActivityTest.java
Last active Apr 26, 2018
Demonstration of Dagger 2 per-test Activity injection (if https://github.com/google/dagger/issues/648 is resolved)
View MyActivityTest.java
@RunWith(AndroidJUnit4.class)
public class MyActivityTest {
@Rule public ActivityTestRule<MyActivity> activityTestRule = new ActivityTestRule<>(MyActivity.class, false, false);
private MyApp myApp;
@Before public void setup() {
myApp = (MyApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
}
@vaughandroid
vaughandroid / MyActivityTest.java
Created Mar 24, 2017
Demonstration of Dagger 2 per-test Activity injection
View MyActivityTest.java
@RunWith(AndroidJUnit4.class)
public class MyActivityTest {
@Rule public ActivityTestRule<MyActivity> activityTestRule = new ActivityTestRule<>(MyActivity.class, false, false);
private MyApp myApp;
@Before public void setup() {
myApp = (MyApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
}
View JodaAndroidFixRule.java
package me.vaughandroid.testutils.rules;
import org.joda.time.DateTimeZone;
import org.joda.time.tz.Provider;
import org.joda.time.tz.UTCProvider;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
@vaughandroid
vaughandroid / kill-emulator.exp
Created May 25, 2016
Script to kill an Android emulator which requires authentication
View kill-emulator.exp
#!/usr/bin/expect
##############################################################
#
# KILL-EMULATOR
#
# Kills an Android emulator which requires authentication.
# It works by opening a telnet session and authenticates, before issuing the
# kill command.
#
@vaughandroid
vaughandroid / ModuleOverride.java
Last active Mar 11, 2020
Overriding Dagger 2 Modules in the simplest way I know how
View ModuleOverride.java
@Component(modules=MyModule.class)
@ApplicationScope
public interface MyComponent {
void inject(MyApplication application);
}
@Module
public class MyModule {
@Provides @ApplicationScope
public String provideString() {
@vaughandroid
vaughandroid / ModuleOverride.java
Last active Mar 11, 2020
Not quite the easiest way to override Dagger 2 modules for unit tests...
View ModuleOverride.java
@Component(modules=MyModule.class)
@ApplicationScope
public interface MyComponent {
void inject(MyApplication application);
}
@Module
public class MyModule {
@Provides @ApplicationScope
@vaughandroid
vaughandroid / ViewVisibilityIdlingResource.java
Created Aug 21, 2015
An IdlingResource for Espresso which blocks until a View has a particular visibility state.
View ViewVisibilityIdlingResource.java
package com.vaughandroid.test.espresso.idlingresources;
import android.app.Activity;
import android.os.Handler;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.test.espresso.*;
import android.view.View;
import java.lang.ref.WeakReference;
You can’t perform that action at this time.