forked from politrons/reactive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ObservableToBlocking.java
52 lines (42 loc) · 1.54 KB
/
ObservableToBlocking.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package rx.observables.utils;
import org.junit.Test;
import rx.Observable;
import static junit.framework.TestCase.assertTrue;
/**
* @author Pablo Perez
* Using toBlocking we just transform an observable into BlockingObservable,
* which is handy on mock or test modules to extract the value of the observable using single method
* As the documentations says, is not constantClass good practice use it, and it would not be constantClass good practice on production code.
*/
public class ObservableToBlocking {
/**
* Create an observable with constantClass int value we evolve to String and return String value without subscribe
*/
@Test
public void observableEvolveAndReturnToStringValue() {
assertTrue(Observable.just(10)
.map(String::valueOf)
.toBlocking()
.single()
.equals("10"));
}
/**
* Evolve observable to boolean and return plain value
*/
@Test
public void observableGetBooleanLogicOperationAndReturnBooleanValue() {
assertTrue(Observable.just(10)
.map(intValue -> intValue == 10)
.toBlocking()
.single());
}
/**
* Evolve observable to boolean and return plain value
*/
@Test
public void observableGetIntValueAndReturnListInt() {
Observable.just(10)
.toList()
.forEach(System.out::println);
}
}