RectGeofence implements Geofence { @Override public boolean contains(LatLng latLng) { double longitude = latLng.longitude; double latitude = latLng.latitude; double leftBorder = northWest.longitude; double rightBorder = southEast.longitude; double bottomBorder = southEast.latitude; double topBorder = northWest.latitude; return latitude >= bottomBorder && latitude <= topBorder && longitude >= leftBorder && longitude <= rightBorder; } RectGeofence(LatLng northWest, LatLng southEast); @Override boolean contains(LatLng latLng);  }
@Test public void testInside() throws Exception { assertTrue(createFence().contains(new LatLng(0, 0))); assertTrue(createFence().contains(new LatLng(0.999, 0.999))); assertTrue(createFence().contains(new LatLng(-0.999, 0.999))); assertTrue(createFence().contains(new LatLng(-0.999, -0.999))); assertTrue(createFence().contains(new LatLng(0.999, -0.999))); }
@Test public void testOutside() throws Exception { assertFalse(createFence().contains(new LatLng(1.001, 0))); assertFalse(createFence().contains(new LatLng(-1.001, 0))); assertFalse(createFence().contains(new LatLng(0, 1.001))); assertFalse(createFence().contains(new LatLng(0, -1.001))); }