Code formatted

This commit is contained in:
TINO 2018-12-04 22:31:10 +03:00
parent a32cb1a489
commit 127c3eca04
2 changed files with 57 additions and 53 deletions

View File

@ -1,53 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>rxjava-2</artifactId> <artifactId>rxjava-2</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId> <artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath> <relativePath>../parent-java</relativePath>
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.reactivex.rxjava2</groupId> <groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId> <artifactId>rxjava</artifactId>
<version>${rx.java2.version}</version> <version>${rx.java2.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jayway.awaitility</groupId> <groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId> <artifactId>awaitility</artifactId>
<version>${awaitility.version}</version> <version>${awaitility.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
<version>${assertj.version}</version> <version>${assertj.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.jakewharton.rxrelay2</groupId> <groupId>com.jakewharton.rxrelay2</groupId>
<artifactId>rxrelay</artifactId> <artifactId>rxrelay</artifactId>
<version>${rxrelay.version}</version> <version>${rxrelay.version}</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.github.akarnokd/rxjava2-extensions --> <!-- https://mvnrepository.com/artifact/com.github.akarnokd/rxjava2-extensions -->
<dependency> <dependency>
<groupId>com.github.akarnokd</groupId> <groupId>com.github.akarnokd</groupId>
<artifactId>rxjava2-extensions</artifactId> <artifactId>rxjava2-extensions</artifactId>
<version>${rxjava2.ext.version}</version> <version>${rxjava2.ext.version}</version>
</dependency> </dependency>
</dependencies>
</dependencies> <properties>
<assertj.version>3.8.0</assertj.version>
<properties> <rx.java2.version>2.2.2</rx.java2.version>
<assertj.version>3.8.0</assertj.version> <awaitility.version>1.7.0</awaitility.version>
<rx.java2.version>2.2.2</rx.java2.version> <rxrelay.version>2.0.0</rxrelay.version>
<awaitility.version>1.7.0</awaitility.version> <rxjava2.ext.version>0.20.4</rxjava2.ext.version>
<rxrelay.version>2.0.0</rxrelay.version> </properties>
<rxjava2.ext.version>0.20.4</rxjava2.ext.version>
</properties>
</project> </project>

View File

@ -21,8 +21,9 @@ public class AsyncAndSyncToObservableIntegrationTest {
AtomicInteger counter = new AtomicInteger(); AtomicInteger counter = new AtomicInteger();
Callable<Integer> callable = () -> counter.incrementAndGet(); Callable<Integer> callable = () -> counter.incrementAndGet();
/* Method will execute every time it gets subscribed*/
@Test @Test
public void givenSyncMethod_whenConvertedWithFromCallable_thenReturnObservable() {// method will execute every time it gets subscribed public void givenSyncMethod_whenConvertedWithFromCallable_thenReturnObservable() {
Observable<Integer> source = Observable.fromCallable(callable); Observable<Integer> source = Observable.fromCallable(callable);
@ -35,8 +36,9 @@ public class AsyncAndSyncToObservableIntegrationTest {
} }
} }
/* Method will execute only once and cache its result.*/
@Test @Test
public void givenSyncMethod_whenConvertedWithStart_thenReturnObservable() {// method will execute only once and cache its result. public void givenSyncMethod_whenConvertedWithStart_thenReturnObservable() {
Observable<Integer> source = AsyncObservable.start(callable); Observable<Integer> source = AsyncObservable.start(callable);
@ -49,8 +51,9 @@ public class AsyncAndSyncToObservableIntegrationTest {
} }
} }
/* Method will execute only once and cache its result.*/
@Test @Test
public void givenAsyncMethod_whenConvertedWithFromFuture_thenRetrunObservble() { // method will execute only once and cache its result. public void givenAsyncMethod_whenConvertedWithFromFuture_thenRetrunObservble() {
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> future = executor.submit(callable); Future<Integer> future = executor.submit(callable);
@ -67,8 +70,9 @@ public class AsyncAndSyncToObservableIntegrationTest {
executor.shutdown(); executor.shutdown();
} }
/* Method will execute every time it gets subscribed*/
@Test @Test
public void givenAsyncMethod_whenConvertedWithStartFuture_thenRetrunObservble() {// method will execute every time it gets subscribed public void givenAsyncMethod_whenConvertedWithStartFuture_thenRetrunObservble() {
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
Observable<Integer> source = AsyncObservable.startFuture(() -> executor.submit(callable)); Observable<Integer> source = AsyncObservable.startFuture(() -> executor.submit(callable));
@ -84,9 +88,9 @@ public class AsyncAndSyncToObservableIntegrationTest {
executor.shutdown(); executor.shutdown();
} }
/*Method will execute only once and cache its result.*/
@Test @Test
public void givenAsyncMethod_whenConvertedWithDeferFuture_thenRetrunObservble() { // method will execute only once and cache its result. public void givenAsyncMethod_whenConvertedWithDeferFuture_thenRetrunObservble() {
List<Integer> list = Arrays.asList(new Integer[] { counter.incrementAndGet(), counter.incrementAndGet(), counter.incrementAndGet() }); List<Integer> list = Arrays.asList(new Integer[] { counter.incrementAndGet(), counter.incrementAndGet(), counter.incrementAndGet() });
ExecutorService exec = Executors.newSingleThreadExecutor(); ExecutorService exec = Executors.newSingleThreadExecutor();
Callable<Observable<Integer>> callable = () -> Observable.fromIterable(list); Callable<Observable<Integer>> callable = () -> Observable.fromIterable(list);