Minor model corrections and getStops() unit test
This commit is contained in:
parent
6ec93ba0f7
commit
429e90c61b
18
pom.xml
18
pom.xml
@ -25,6 +25,24 @@
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-junit</artifactId>
|
||||
<version>2.0.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.6.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -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());
|
||||
|
@ -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<Stop> 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));
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
Loading…
x
Reference in New Issue
Block a user