Skip to content

Commit

Permalink
Add test and crash
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadsen committed Nov 28, 2022
1 parent 65e6d80 commit 7a6c048
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.NoSuchElementException;

/**
* Decodes an encoded path string as an iterator of {@link Point}.
Expand Down Expand Up @@ -60,9 +61,15 @@ public boolean hasNext() {

/**
* Returns the next point in the geometry.
*
* @throws NoSuchElementException if the geometry has no more points
*/
@Override
public Point next() {
public Point next() throws NoSuchElementException {
if (!hasNext()) {
throw new NoSuchElementException("Next element is not available when hasNext is false.");
}

int result = 1;
int shift = 0;
int temp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.NoSuchElementException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

public class PolylineDecoderTest extends TestUtils {
Expand Down Expand Up @@ -62,4 +64,14 @@ public void testCurrentValue() {
assertEquals(polylineDecoder.next(), polylineDecoder.getCurrent());
assertEquals(polylineDecoder.next(), polylineDecoder.getCurrent());
}

@Test
public void testThrowsExceptionWhenNoMoreElements() {
String geometry = "";

InputStream inputStream = new ByteArrayInputStream(geometry.getBytes());
PolylineDecoder polylineDecoder = new PolylineDecoder(inputStream, 5);

assertThrows(NoSuchElementException.class, polylineDecoder::next);
}
}

0 comments on commit 7a6c048

Please sign in to comment.