diff --git a/pom.xml b/pom.xml
index 7472fed..ec4defa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,24 @@
4.12
test
+
+ org.hamcrest
+ hamcrest-junit
+ 2.0.0.0
+ test
+
+
+ org.powermock
+ powermock-module-junit4
+ 1.6.6
+ test
+
+
+ org.powermock
+ powermock-api-mockito
+ 1.6.6
+ test
+
diff --git a/src/main/java/de/stklcode/pubtrans/ura/model/Stop.java b/src/main/java/de/stklcode/pubtrans/ura/model/Stop.java
index 71060b6..d814fe1 100644
--- a/src/main/java/de/stklcode/pubtrans/ura/model/Stop.java
+++ b/src/main/java/de/stklcode/pubtrans/ura/model/Stop.java
@@ -41,7 +41,7 @@ public class Stop {
indicator = (String)raw.get(3);
else
throw new IOException("Field 3 not of expected type String, found " + raw.get(3).getClass().getSimpleName());
- if (raw.get(4) instanceof String)
+ if (raw.get(4) instanceof Integer)
state = (Integer)raw.get(4);
else
throw new IOException("Field 4 not of expected type Integer, found " + raw.get(4).getClass().getSimpleName());
@@ -49,7 +49,7 @@ public class Stop {
latitude = (Double)raw.get(5);
else
throw new IOException("Field 5 not of expected type Double, found " + raw.get(5).getClass().getSimpleName());
- if (raw.get(4) instanceof Double)
+ if (raw.get(6) instanceof Double)
longitude = (Double)raw.get(6);
else
throw new IOException("Field 6 not of expected type Double, found " + raw.get(6).getClass().getSimpleName());
diff --git a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java
index afec97c..3541077 100644
--- a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java
+++ b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java
@@ -1,15 +1,38 @@
package de.stklcode.pubtrans.ura;
+import de.stklcode.pubtrans.ura.model.Stop;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
-/**
- * Created by stefan on 24.12.16.
- */
+import java.net.URL;
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.core.Is.is;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ UraClient.class, URL.class })
public class UraClientTest {
private static final String BASE_ASEAG = "http://ivu.aseag.de";
@Test
- public void listStopsTest() {
- new UraClient(BASE_ASEAG).listStops();
+ public void listStopsTest() throws Exception {
+ /* Mock the HTTP call */
+ URL mockURL = PowerMockito.mock(URL.class);
+ PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(mockURL);
+ PowerMockito.when(mockURL.openStream()).thenReturn(getClass().getResourceAsStream("instant_stops.txt"));
+
+ /* List stops and verify some values */
+ List stops = new UraClient("mocked").listStops();
+ assertThat(stops, hasSize(10));
+ assertThat(stops.get(0).getId(), is("100210"));
+ assertThat(stops.get(1).getName(), is("Brockenberg"));
+ assertThat(stops.get(2).getState(), is(0));;
+ assertThat(stops.get(3).getLatitude(), is(50.7578775));
+ assertThat(stops.get(4).getLongitude(), is(6.0708663));
}
}
diff --git a/src/test/resources/de/stklcode/pubtrans/ura/instant_stops.txt b/src/test/resources/de/stklcode/pubtrans/ura/instant_stops.txt
new file mode 100644
index 0000000..40efb7a
--- /dev/null
+++ b/src/test/resources/de/stklcode/pubtrans/ura/instant_stops.txt
@@ -0,0 +1,11 @@
+[4,"2.0",1482845546273]
+[0,"Stollenweg","100210","",0,50.7822619,6.1557408]
+[0,"Brockenberg","215972","",0,50.7539369,6.22667]
+[0,"Barbarossaplatz","100551","",0,50.7643005,6.0751172]
+[0,"Erberichshofstraße","100381","",0,50.7578775,6.1724391]
+[0,"Mühlenbachstraße","210711","",0,50.8395522,6.0708663]
+[0,"Steinebrück","100901","",0,50.7434749,6.1735477]
+[0,"Kohlscheid Markt","210735","",0,50.8346844,6.0902494]
+[0,"Röhe Aachener Straße","213401","",0,50.8227575,6.2449847]
+[0,"Kreisaltenheim","213313","",0,50.8161047,6.2537613]
+[0,"Aachen Bushof","100000","H.1",0,50.7775936,6.0908191]