GeoCoordinatesEncoder implements LocationReferenceEncoder { @Override public LocationReference encode(RawLocationReference rawLocationReference) throws OpenLRProtoException { if (rawLocationReference.getLocationType() != LocationType.GEO_COORDINATES) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } GeoCoordinates geoCoordinates = rawLocationReference.getGeoCoordinates(); Coordinates coordinates = Coordinates.newBuilder() .setLongitude(geoCoordinates.getLongitudeDeg()) .setLatitude(geoCoordinates.getLatitudeDeg()) .build(); GeoCoordinatesLocationReference geoCoordinatesLocationReference = GeoCoordinatesLocationReference.newBuilder() .setCoordinates(coordinates) .build(); LocationReferenceData locationReferenceData = LocationReferenceData.newBuilder() .setGeoCoordinatesLocationReference(geoCoordinatesLocationReference) .build(); return new LocationReferenceProtoImpl(rawLocationReference.getID(), LocationType.GEO_COORDINATES, locationReferenceData); }  @Override LocationReference encode(RawLocationReference rawLocationReference);  }
@Test public void testEncodeGeoCoordinates() throws OpenLRProtoException { GeoCoordinatesProtoImpl geoCoordinates = new GeoCoordinatesProtoImpl(7.3, 52.5); RawGeoCoordLocRef rawLocationReference = new RawGeoCoordLocRef("1", geoCoordinates); LocationReference locationReference = geoCoordinatesEncoder.encode(rawLocationReference); assertNotNull(locationReference); assertEquals(locationReference.getID(), "1"); assertEquals(locationReference.getLocationType(), LocationType.GEO_COORDINATES); assertEquals(locationReference.getDataIdentifier(), "proto"); assertEquals(locationReference.getDataClass(), LocationReferenceData.class); assertNotNull(locationReference); assertEquals(locationReference.getID(), "1"); assertEquals(locationReference.getLocationType(), LocationType.GEO_COORDINATES); assertTrue(locationReference.isValid()); assertEquals(locationReference.getDataClass(), LocationReferenceData.class); Object locationReferenceData = locationReference.getLocationReferenceData(); assertTrue(locationReferenceData instanceof LocationReferenceData); LocationReferenceData data = (LocationReferenceData) locationReferenceData; assertTrue(data.hasGeoCoordinatesLocationReference()); GeoCoordinatesLocationReference geoCoordinatesLocationReference = data.getGeoCoordinatesLocationReference(); assertTrue(geoCoordinatesLocationReference.hasCoordinates()); Coordinates coordinates = geoCoordinatesLocationReference.getCoordinates(); assertEquals(coordinates.getLongitude(), 7.3); assertEquals(coordinates.getLatitude(), 52.5); }