RegionEvent extends Event implements JsonSerializable { @NonNull public static Builder newBuilder() { return new Builder(); } private  RegionEvent(@NonNull RegionEvent.Builder builder); @NonNull static Builder newBuilder(); @NonNull @Override final String getType(); @Boundary int getBoundaryEvent(); @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) final JsonMap getEventData(); @NonNull @Override JsonValue toJsonValue(); @Override boolean isValid(); @Override @Priority int getPriority(); @NonNull
    static final String TYPE; @NonNull
    static final String REGION_ID; static final int BOUNDARY_EVENT_ENTER; static final int BOUNDARY_EVENT_EXIT; static final int MAX_CHARACTER_LENGTH; static final double MAX_LATITUDE; static final double MIN_LATITUDE; static final double MAX_LONGITUDE; static final double MIN_LONGITUDE; }
@Test(expected = IllegalArgumentException.class) public void testEmptyRegionID() { String regionId = ""; String source = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .build(); }
@Test(expected = IllegalArgumentException.class) public void testNullRegionID() { String source = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; RegionEvent event = RegionEvent.newBuilder() .setRegionId(null) .setSource(source) .setBoundaryEvent(boundaryEvent) .build(); }
@Test(expected = IllegalArgumentException.class) public void testMaxRegionID() { String regionId = createFixedSizeString('a', 256); String source = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .build(); }
@Test(expected = IllegalArgumentException.class) public void testEmptySource() { String regionId = createFixedSizeString('a', 255); String source = ""; int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .build(); }
@Test(expected = IllegalArgumentException.class) public void testNullSource() { String regionId = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setBoundaryEvent(boundaryEvent) .build(); }
@Test(expected = IllegalArgumentException.class) public void testMaxSource() { String regionId = createFixedSizeString('a', 255); String source = createFixedSizeString('b', 256); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .build(); }
@Test(expected = IllegalArgumentException.class) public void testInvalidBoundaryEvent() { String regionId = createFixedSizeString('a', 255); String source = createFixedSizeString('b', 255); int boundaryEvent = 11; RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .build(); }
@Test public void testRegionEventWithProximityRegion() throws JSONException { String regionId = createFixedSizeString('a', 255); String source = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; ProximityRegion proximityRegion = new ProximityRegion("test_proximity_region", 1, 2); proximityRegion.setCoordinates(0.0, 0.0); proximityRegion.setRssi(-59); RegionEvent event = RegionEvent.newBuilder().setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .setProximityRegion(proximityRegion).build(); EventTestUtils.validateEventValue(event, "region_id", regionId); EventTestUtils.validateEventValue(event, "source", source); EventTestUtils.validateEventValue(event, "action", "enter"); EventTestUtils.validateNestedEventValue(event, "proximity", "proximity_id", proximityRegion.getProximityId()); EventTestUtils.validateNestedEventValue(event, "proximity", "major", proximityRegion.getMajor()); EventTestUtils.validateNestedEventValue(event, "proximity", "minor", proximityRegion.getMinor()); EventTestUtils.validateNestedEventValue(event, "proximity", "latitude", proximityRegion.getLatitude()); EventTestUtils.validateNestedEventValue(event, "proximity", "longitude", proximityRegion.getLongitude()); EventTestUtils.validateNestedEventValue(event, "proximity", "rssi", proximityRegion.getRssi()); }
@Test public void testRegionEventWithProximityRegionWithNullCoordinates() throws JSONException { String regionId = createFixedSizeString('a', 255); String source = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; ProximityRegion proximityRegion = new ProximityRegion("test_proximity_region", 1, 2); proximityRegion.setRssi(-59); RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .setProximityRegion(proximityRegion) .build(); EventTestUtils.validateEventValue(event, "region_id", regionId); EventTestUtils.validateEventValue(event, "source", source); EventTestUtils.validateEventValue(event, "action", "enter"); EventTestUtils.validateNestedEventValue(event, "proximity", "proximity_id", proximityRegion.getProximityId()); EventTestUtils.validateNestedEventValue(event, "proximity", "major", proximityRegion.getMajor()); EventTestUtils.validateNestedEventValue(event, "proximity", "minor", proximityRegion.getMinor()); EventTestUtils.validateNestedEventValue(event, "proximity", "rssi", proximityRegion.getRssi()); }
@Test public void testRegionEventWithProximityRegionWithNullRssi() throws JSONException { String regionId = createFixedSizeString('a', 255); String source = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; ProximityRegion proximityRegion = new ProximityRegion("test_proximity_region", 1, 2); proximityRegion.setCoordinates(0.0, 0.0); RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .setProximityRegion(proximityRegion) .build(); EventTestUtils.validateEventValue(event, "region_id", regionId); EventTestUtils.validateEventValue(event, "source", source); EventTestUtils.validateEventValue(event, "action", "enter"); EventTestUtils.validateNestedEventValue(event, "proximity", "proximity_id", proximityRegion.getProximityId()); EventTestUtils.validateNestedEventValue(event, "proximity", "major", proximityRegion.getMajor()); EventTestUtils.validateNestedEventValue(event, "proximity", "minor", proximityRegion.getMinor()); EventTestUtils.validateNestedEventValue(event, "proximity", "latitude", proximityRegion.getLatitude()); EventTestUtils.validateNestedEventValue(event, "proximity", "longitude", proximityRegion.getLongitude()); }
@Test public void testRegionEventWithCircularRegion() throws JSONException { String regionId = createFixedSizeString('a', 255); String source = createFixedSizeString('b', 255); int boundaryEvent = RegionEvent.BOUNDARY_EVENT_ENTER; CircularRegion circularRegion = new CircularRegion(10, 90.0, 180.0); RegionEvent event = RegionEvent.newBuilder() .setRegionId(regionId) .setSource(source) .setBoundaryEvent(boundaryEvent) .setCircularRegion(circularRegion) .build(); EventTestUtils.validateEventValue(event, "region_id", regionId); EventTestUtils.validateEventValue(event, "source", source); EventTestUtils.validateEventValue(event, "action", "enter"); EventTestUtils.validateNestedEventValue(event, "circular_region", "radius", 10); EventTestUtils.validateNestedEventValue(event, "circular_region", "latitude", 90.0000000); EventTestUtils.validateNestedEventValue(event, "circular_region", "longitude", 180.0000000); }