Skip to content

Instantly share code, notes, and snippets.

View desseim's full-sized avatar

Guillaume Legrand desseim

View GitHub Profile
@desseim
desseim / gist:0ea3438ea99c8a6e8a77
Last active August 29, 2015 14:05
Gradle dependency configuration for injected tests using mockito, dagger, guava and auto with Android

This is the configuration I used to get the tests for my Android project to run. This works with Android Studio 0.8 (Gradle 1.12).

The project uses notably guava, mockito, dagger, assertj, awaitility, auto, retrofit / okhttp and mockwebserver and also needs to inject some tests with test-specific modules. Given the necessity to inject tests and the current lack of support for transitive dependencies for the androidTestXxx scopes, the dependency settings are somewhat tricky to get to work properly.

compile 'com.android.support:appcompat-v7:20'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.google.guava:guava:18.0'
@desseim
desseim / gist:914e0663bee3f20d6ca0
Created January 7, 2015 20:58
Create a new git repo out of only a sub-directory of an existing repo
# clone the original repo
git clone git@github.com:user/repo.git
cd ./repo
# filter all git history (including all branches) and only keep the commits affecting a given subdirectory
git filter-branch --subdirectory-filter the/sub/dir -- --all
# clean up git backups (only necessary to help making sure all that we don't want is gone afterwards):
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
@desseim
desseim / ExampleInjectedActivity.kt
Last active October 7, 2015 15:10
Injection in >= M14 Kotlin code with Dagger2
class ExampleInjectedActivity : Activity() {
@Inject lateinit var controller: ExampleController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.example_layout)
//controller.doThing() // would compile but throw at runtime
component().inject(this)