-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
rxgooglemap/src/main/java/com/sdoward/rxgooglemap/POIClickFunc.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.sdoward.rxgooglemap; | ||
|
||
import com.google.android.gms.maps.GoogleMap; | ||
import com.google.android.gms.maps.model.PointOfInterest; | ||
import rx.Observable; | ||
import rx.Subscriber; | ||
import rx.functions.Func1; | ||
|
||
class POIClickFunc implements Func1<GoogleMap, Observable<PointOfInterest>> { | ||
|
||
@Override | ||
public Observable<PointOfInterest> call(final GoogleMap googleMap) { | ||
return Observable.create(new Observable.OnSubscribe<PointOfInterest>() { | ||
@Override | ||
public void call(final Subscriber<? super PointOfInterest> subscriber) { | ||
googleMap.setOnPoiClickListener(new GoogleMap.OnPoiClickListener() { | ||
@Override | ||
public void onPoiClick(PointOfInterest pointOfInterest) { | ||
subscriber.onNext(pointOfInterest); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
rxgooglemap/src/test/java/com/sdoward/rxgooglemap/POIClickFuncTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.sdoward.rxgooglemap; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import com.google.android.gms.maps.GoogleMap; | ||
import com.google.android.gms.maps.model.PointOfInterest; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Captor; | ||
import org.mockito.Mock; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
import rx.observers.TestSubscriber; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(GoogleMap.class) | ||
public class POIClickFuncTest { | ||
|
||
@Mock | ||
private GoogleMap googleMap; | ||
@Captor | ||
private ArgumentCaptor<GoogleMap.OnPoiClickListener> argumentCaptor; | ||
|
||
@Test | ||
public void shouldEmmitPolygon() throws Exception { | ||
TestSubscriber<PointOfInterest> testSubscriber = new TestSubscriber<>(); | ||
new POIClickFunc().call(googleMap) | ||
.subscribe(testSubscriber); | ||
verify(googleMap).setOnPoiClickListener(argumentCaptor.capture()); | ||
argumentCaptor.getValue().onPoiClick(null); | ||
testSubscriber.assertNoErrors(); | ||
testSubscriber.assertValueCount(1); | ||
argumentCaptor.getValue().onPoiClick(null); | ||
testSubscriber.assertValueCount(2); | ||
} | ||
|
||
} |