Created
June 13, 2017 16:15
-
-
Save guelo/74ee2b06f4b314100fc69950592a19c3 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import io.reactivex.Observable; | |
import io.reactivex.annotations.NonNull; | |
import io.reactivex.functions.Consumer; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertNotEquals; | |
public class Test { | |
private Observable<Double> retrofit() { | |
return Observable.just(Math.random()).delay(1, TimeUnit.SECONDS); | |
} | |
@org.junit.Test | |
public void test() throws InterruptedException { | |
final List<Double> results = new ArrayList<>(); | |
Consumer<Double> onNext = new Consumer<Double>() { | |
@Override | |
public void accept(@NonNull Double aDouble) throws Exception { | |
results.add(aDouble); | |
} | |
}; | |
getStuff().subscribe(onNext); | |
Thread.sleep(500); | |
getStuff().subscribe(onNext); | |
Thread.sleep(510); | |
getStuff().subscribe(onNext); | |
Thread.sleep(1100); | |
assertEquals(results.get(0),results.get(1) ); | |
assertNotEquals(results.get(1),results.get(2) ); | |
} | |
private Observable<Double> stuff = retrofit().share(); | |
public Observable<Double> getStuff() { | |
return stuff; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment