This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private CatalogProductEntity mockProduct(String sku, String name, String brandName, Double price, Double specialPrice, List<String> imageUrls){ | |
BrandEntity brand = mock(BrandEntity.class); | |
when(brand.getName()).thenReturn(brandName); | |
ArrayList<ImageEntity> images = new ArrayList<>(); | |
for(String imageUrl : imageUrls){ | |
ImageEntity imageEntity = mock(ImageEntity.class); | |
when(imageEntity.getUrl()).thenReturn(imageUrl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CatalogProductEntity mockProduct(String sku, String name, String brand, Double price, Double specialPrice, List<String> imageUrls){ | |
return Mock(CatalogProductEntity) { | |
it.getSku() >> sku | |
it.getName() >> name | |
it.getBrand() >> Mock(BrandEntity){ | |
it.getName() >> brand | |
} | |
it.getPrice() >> price | |
it.getSpecialPrice() >> specialPrice | |
it.getImages() >> imageUrls.collect{ url-> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def product = mockProduct("sky", "name", "BranName", 120d, 90d, ["http://theiconic.com.au/someImage.jpg","http://theiconic.com.au/someOtherImage.jpg"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReactiveData<T> { | |
@Getter | |
private final T value; | |
@Getter | |
private final Throwable error; | |
public ReactiveData(T value) { | |
this.value = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "A request for products", | |
"request": { | |
"method": "GET", | |
"path": "/catalog/products", | |
"headers": { | |
"Accept": "application/json" | |
}, | |
"query": "gender=male" | |
}, |