Skip to content

Instantly share code, notes, and snippets.

@ian-ellis
ian-ellis / Pact Fail
Created March 23, 2017 01:59
Pact Fail
$.body.page_count -> Expected 1 but received 462
$.body._embedded.product.0.name -> Expected 'Alaska Coat' but received '1460 8 Eye Boots Smooth'
$.body._embedded.product.0.sku -> Expected 'FR760AA31JSE' but received 'DR086SH49AVE'
$.body._embedded.product.0.price -> Expected 169.95 but received 199
$.body._embedded.product.0.short_description -> Expected 'A product description' but received '<b>PLEASE NOTE - THE ICONIC IS UNABLE TO SHIP THIS PRODUCT TO NEW ZEALAND.</b><br><br>For the original grunge look, you can't go past <b>Dr Martens 1460Z DMC 8 Eye Lace Up</b> boots, a direct replica of the first boots to roll off the production
line in 1960. Combine your pair with distressed skinny jeans and a printed tee.<br><br>- Genuine leather upper and lining<br>- Rounded toe<br>- Eight-eye lace-up fastening<br>- Classic looped pull tab<br>- Topstitch detailing around the sole<br>- Oil and acid resistant outsole<br><br>PLEASE NOTE : This style comes in UK sizing and has a unisex fit. We reco
@ian-ellis
ian-ellis / Pact Builder
Created March 23, 2017 01:59
Pact Builder
pactBuilder {
serviceConsumer 'Android_App'
hasPactWith 'Eve_v1'
port PORT
uponReceiving 'A request for products'
withAttributes(
method: 'GET',
path: "/catalog/products",
headers: ['Accept': 'application/json'],
{
"description": "A request for products",
"request": {
"method": "GET",
"path": "/catalog/products",
"headers": {
"Accept": "application/json"
},
"query": {
"gender": [
{
"description": "A request for products",
"request": {
"method": "GET",
"path": "/catalog/products",
"headers": {
"Accept": "application/json"
},
"query": "gender=male"
},
public static <T> Observable.Transformer<T, T> doOnLast(Action1<T> doOnCompleteFunc) {
return new Observable.Transformer<T, T>() {
private T lastValue;
@Override
public Observable<T> call(Observable<T> observable) {
return observable.doOnNext(value -> {
lastValue = value;
}).doOnCompleted(() -> {
doOnCompleteFunc.call(lastValue);
public class ReactiveData<T> {
@Getter
private final T value;
@Getter
private final Throwable error;
public ReactiveData(T value) {
this.value = value;
@ian-ellis
ian-ellis / rx-transformers-swallow-error.java
Created January 17, 2017 22:32
Example of how to swallow an error without ending the parent stream
public static <T, R> Observable.Transformer<T, R> switchMapSwallowError(Func1<T, Observable<R>> onwardCall) {
return new Observable.Transformer<T, R>() {
private R previousValue = null;
@Override
public Observable<R> call(Observable<T> observable) {
return observable.switchMap(
a -> onwardCall.call(a)
.doOnNext(value -> previousValue = value)
public static Observable.Transformer<Integer, Integer> increment() {
return new Observable.Transformer<Integer, Integer>() {
private Integer previous = 0;
@Override
public Observable<Integer> call(Observable<Integer> integerObservable) {
return integerObservable.map(i -> {
Integer val = i + previous;
previous = val;
return val;
1 * useCase.repository.removeItem(_) >> Observable.just(true)
1 * useCase.repository.removeItem(_ as String) >> Observable.just(true)
1 * useCase.repository.removeItem(simpleSku) >> { args->
assert args[0] == simpleSku
return Observable.just(true)
}
ArrayList<String> imageUrls = new ArrayList<>();
imageUrls.add("http://theiconic.com.au/someImage.jpg")
imageUrls.add("http://theiconic.com.au/someOtherImage.jpg")
CatalogProductEntity product = mockProduct("sky", "name", "BrandName", 120d, 90d, imageUrls)