LatLngBounds implements Parcelable { public boolean contains(LatLng point) { return this.includesLat(point.getLatitude()) && this.includesLng(point.getLongitude()); } LatLngBounds(@NonNull LatLng southwest, @NonNull LatLng northeast); private  LatLngBounds(Parcel in); @NonNull LatLng getSouthwest(); @NonNull LatLng getNortheast(); boolean contains(LatLng point); @NonNull LatLngBounds including(@NonNull LatLng point); @NonNull LatLng getCenter(); @Override int describeContents(); @Override void writeToParcel(Parcel parcel, int i); static final Parcelable.Creator<LatLngBounds> CREATOR; }
@Test public void contains_shouldReturnTrue() { LatLng pointA = new LatLng(40, 50); LatLng pointB = new LatLng(-40, -50); LatLngBounds bounds = new LatLngBounds.Builder() .include(pointA) .include(pointB) .build(); LatLng point = new LatLng(20, 20); assertThat(bounds.contains(point)).isTrue(); }
@Test public void contains_shouldReturnFalse() { LatLng pointA = new LatLng(40, 50); LatLng pointB = new LatLng(-40, -50); LatLngBounds bounds = new LatLngBounds.Builder() .include(pointA) .include(pointB) .build(); LatLng point = new LatLng(20, 120); assertThat(bounds.contains(point)).isFalse(); }