Skip to content

Commit

Permalink
Add POIClick functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sdoward committed Sep 28, 2016
1 parent 38b07af commit c86d273
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public Observable<Polygon> getPolygonClickObservable() {
return mapSubject.flatMap(new PolygonClickFunc());
}

public Observable<PointOfInterest> getPOIClickObservable() {
return mapSubject.flatMap(new POIClickFunc());
}

public Observable<GroundOverlay> getGroundOverlayObservable() {
return mapSubject.flatMap(new GroundOverlayClickFunc());
}
Expand Down
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);
}
});
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public void shouldProvideCameraIdleObservable() throws Exception {
Assert.assertNotNull(observable);
}


@Test
public void shouldProvideCameraMoveObservable() throws Exception {
Observable observable = new MapObservableProvider(mapFragment).getCameraMoveObservable();
Expand Down Expand Up @@ -162,6 +161,12 @@ public void shouldProvidePolygonClickObservable() throws Exception {
Assert.assertNotNull(observable);
}

@Test
public void shouldProvidePOIClickObservable() throws Exception {
Observable observable = new MapObservableProvider(mapFragment).getPOIClickObservable();
Assert.assertNotNull(observable);
}

@Test
public void shouldProvideGroundOverlayObservable() throws Exception {
Observable observable = new MapObservableProvider(mapFragment).getGroundOverlayObservable();
Expand Down
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);
}

}

0 comments on commit c86d273

Please sign in to comment.