OpenLREncoder implements openlr.OpenLREncoder { @Override public LocationReferenceHolder encodeLocation( final OpenLREncoderParameter parameter, final Location loc) throws OpenLRProcessingException { return encodeLocation(parameter, new OpenLREncoderProperties(parameter.getConfiguration(), parameter.getPhysicalEncoders()), loc); }  static List<PhysicalEncoder> getPhysicalEncoderServices(); @Override List<LocationReferenceHolder> encodeLocations(
            final OpenLREncoderParameter parameter, final List<Location> loc); @Override LocationReferenceHolder encodeLocation(
            final OpenLREncoderParameter parameter, final Location loc); @Override String getMajorVersion(); @Override String getMinorVersion(); @Override String getPatchVersion(); @Override String getVersion();  }
@Test public final void testPOIWithAccesNoOffsets() { LocationReferenceHolder encLocRef = null; try { PoiAccessLocation inputLocation = td.getPOIWithAccessNoOffset(); encLocRef = encodeLocation(inputLocation); assertTrue(encLocRef.isValid()); RawLocationReference rawData = encLocRef .getRawLocationReferenceData(); GeoCoordinates inputPoi = inputLocation.getPointLocation(); GeoCoordinates coords = rawData.getGeoCoordinates(); assertEquals(coords.getLatitudeDeg(), inputPoi.getLatitudeDeg()); assertEquals(coords.getLongitudeDeg(), inputPoi.getLongitudeDeg()); Offsets offsets = rawData.getOffsets(); assertTrue(offsets.getPositiveOffset(0) <= 0); assertTrue(offsets.getNegativeOffset(0) <= 0); } catch (InvalidMapDataException e) { Assert.fail("Unexpected exception", e); } }
@Test public final void testReducedLineLocation() { LocationReferenceHolder encLocRef = null; LineLocation inputLocation = td.getLineLocationReducibleOffsets(); int lengtIn = 0; for (Line l : inputLocation.getLocationLines()) { lengtIn += l.getLineLength(); } int pOffIn = inputLocation.getPositiveOffset(); int nOffIn = inputLocation.getNegativeOffset(); encLocRef = encodeLocation(inputLocation); assertTrue(encLocRef.isValid()); int lengthOut = 0; for (LocationReferencePoint lrp : encLocRef.getLRPs()) { lengthOut += lrp.getDistanceToNext(); } Offsets offOut = encLocRef.getRawLocationReferenceData().getOffsets(); assertTrue(lengtIn > lengthOut); assertTrue(pOffIn != offOut.getPositiveOffset(0)); assertTrue(nOffIn != offOut.getNegativeOffset(0)); int locationLengthIn = lengtIn - pOffIn - nOffIn; int locationLengthOut = lengthOut - offOut.getPositiveOffset(0) - offOut.getNegativeOffset(0); assertTrue(locationLengthIn == locationLengthOut); }
@Test public final void testInvalidLocationType() { final Location mockedLocRef = mockery.mock(Location.class, "invalidType"); final String id = "locID"; mockery.checking(new Expectations() { { allowing(mockedLocRef).getLocationType(); will(returnValue(LocationType.UNKNOWN)); } }); mockery.checking(new Expectations() { { allowing(mockedLocRef).getID(); will(returnValue(id)); } }); LocationReferenceHolder result = encodeLocation(mockedLocRef); assertFalse(result.isValid()); assertSame(result.getReturnCode().toString(), EncoderReturnCode.INVALID_LOCATION_TYPE.toString()); assertEquals(result.getID(), id); assertNotNull(result.toString()); }
@Test public final void testEmptyLocation() { try { LocationReferenceHolder encLocRef = encodeLocation(td .getEmptyLocation()); assertFalse(encLocRef.isValid()); assertEquals(encLocRef.getReturnCode(), EncoderReturnCode.LOCATION_IS_EMPTY); } catch (Exception e) { fail("Wrong error detected: " + e.getMessage()); } }