Skip to content

Instantly share code, notes, and snippets.

@ian-ellis
ian-ellis / AppbarSwipeRefreshLayout
Last active October 9, 2022 09:36
Fixing Up SwipeRefreshLayout to handle a collapsing toolbar
package au.com.qantas.qantas.common.presentation;
import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.util.AttributeSet;
import android.view.View;
import android.support.v4.widget.SwipeRefreshLayout;
public class AppbarSwipeRefreshLayout extends SwipeRefreshLayout implements
AppBarLayout.OnOffsetChangedListener {
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.8'
@ian-ellis
ian-ellis / spock-examples-app-build.gradle
Last active January 16, 2017 22:27
Snippet from app module build.gradle
apply plugin: 'groovyx.grooid.groovy-android'
//......
testCompile 'org.codehaus.groovy:groovy:2.4.5:grooid'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'cglib:cglib-nodep:3.1'
@ian-ellis
ian-ellis / spock-examples-addition-spec.groovy
Created January 16, 2017 22:28
Simple Addition Spock Specification to demonstrate syntax
package com.theiconic.spockexamples
import spock.lang.Specification
class SimpleAdditionSpec extends Specification {
def 'addition'() {
given: 'two integers'
def a = 1
def b = 2
@ian-ellis
ian-ellis / spock-examples-validate-email-usecase.java
Last active January 16, 2017 22:33
Validate Email Use Case
package com.theiconic.spockexamples.common.domain.usecases;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
public class ValidateEmailUseCase implements UseCase<String,Boolean> {
private static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
package com.theiconic.spockexamples.common.domain.usecases
import com.theiconic.spockexamples.common.domain.usecases.ValidateEmailUseCase
import spock.lang.Specification
import spock.lang.Unroll
class ValidEmailUseCaseSpec extends Specification {
ValidateEmailUseCase useCase;
package com.theiconic.spockexamples.bag.domain.usecases
import com.theiconic.spockexamples.bag.domain.repositories.BagRepository
import com.theiconic.spockexamples.bag.domain.usecases.RemoveProductFromBagUseCase
import rx.Observable
import rx.observers.TestSubscriber
import spock.lang.Specification
class RemoveProductFromBagUseCaseSpec extends Specification{
protected RemoveProductFromBagUseCase useCase;
package com.theiconic.spockexamples.bag.domain.usecases;
import com.theiconic.spockexamples.common.domain.usecases.ObservableUseCase;
import com.theiconic.spockexamples.bag.domain.repositories.BagRepository;
import javax.inject.Inject;
import rx.Observable;
public class RemoveProductFromBagUseCase implements ObservableUseCase<String, Boolean> {
1 * useCase.repository.removeItem(simpleSku) >> Observable.just(out);
package com.theiconic.spockexamples.bag.domain.usecases;
import com.theiconic.spockexamples.bag.domain.repositories.BagRepository;
import com.theiconic.spockexamples.bag.domain.usecases.RemoveProductFromBagUseCase;
import com.theiconic.spockexamples.common.entities.BrandEntity;
import com.theiconic.spockexamples.common.entities.ImageEntity;
import com.theiconic.spockexamples.shop.entities.CatalogProductEntity;
import com.theiconic.spockexamples.shop.entities.CategoryEntity;
import org.junit.Before;