Merge remote-tracking branch 'origin/Tests' into Tests

This commit is contained in:
Robin Koedood
2021-01-04 15:27:58 +01:00
2 changed files with 113 additions and 9 deletions

View File

@@ -0,0 +1,97 @@
package com.a1.nextlocation;
import com.a1.nextlocation.data.Location;
import org.junit.Before;
import org.junit.Test;
import org.osmdroid.util.GeoPoint;
import static org.junit.Assert.*;
public class LocationTest {
private Location testLocation;
@Before
public void init(){
testLocation = new Location("testName", "15.4,27.5", "testDesc", null);
}
@Test
public void nameTest(){
String testName = "nameTestName";
String expectedBefore = "testName";
String expectedAfter = "nameTestName";
assertEquals(expectedBefore, testLocation.getName());
testLocation.setName(testName);
assertEquals(expectedAfter, testLocation.getName());
}
@Test
public void coordinatesTest(){
String testCoordinaates = "32.4,15.7";
String expectedBefore = "15.4,27.5";
String expectedAfter = "32.4,15.7";
assertEquals(expectedBefore, testLocation.getCoordinates());
testLocation.setCoordinates(testCoordinaates);
assertEquals(expectedAfter, testLocation.getCoordinates());
}
@Test
public void descriptionTest(){
String testDescription = "This description is a test!";
String expectedBefore = "testDesc";
String expectedAfter = "This description is a test!";
assertEquals(expectedBefore, testLocation.getDescription());
testLocation.setDescription(testDescription);
assertEquals(expectedAfter, testLocation.getDescription());
}
@Test
public void ImageURLTest(){
String testURL = "https://i.imgur.com/FvohwaS.png";
String expectedBefore = null;
String expectedAfter = "https://i.imgur.com/FvohwaS.png";
assertEquals(expectedBefore ,testLocation.getImageUrl());
testLocation.setImageUrl(testURL);
assertEquals(expectedAfter, testLocation.getImageUrl());
}
@Test
public void coordinateDoublesTest(){
double[] testDoubles = new double[2];
testDoubles[0] = 15.4;
testDoubles[1] = 27.5;
double [] expectedCoordAsDouble = testDoubles;
String expectedStringFromDouble = "15.4,27.5";
assertArrayEquals(expectedCoordAsDouble, testLocation.getCoordinatesAsDoubles(), 0.1);
assertEquals(expectedStringFromDouble, testLocation.getStringFromCoordinates(testDoubles[0], testDoubles[1]));
}
@Test
public void geoPointTest(){
String testGeoPointCoords = "30.3,55.5";
GeoPoint expectedBefore = new GeoPoint(15.4, 27.5);
GeoPoint expectedAfter = new GeoPoint(30.3, 55.5);
assertEquals(expectedBefore, testLocation.convertToGeoPoint());
testLocation.setCoordinates(testGeoPointCoords);
assertEquals(expectedAfter, testLocation.convertToGeoPoint());
}
@Test
public void AlternateConstructorTest(){
Location alternateTestLocation = new Location("testName", 15.4, 27.5, "testDesc", null);
assertNotNull(alternateTestLocation);
}
}

View File

@@ -3,6 +3,7 @@ package com.a1.nextlocation;
import com.a1.nextlocation.data.Location;
import com.a1.nextlocation.data.Route;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
@@ -11,17 +12,27 @@ import java.util.List;
import static org.junit.Assert.*;
public class RouteTest {
private Route route;
@Before
public void init(){
route = new Route("testName");
}
@Test
public void GetNameTest(){
Route route = new Route("testName");
String expected = "testName";
assertEquals(expected, route.getName());
public void nameTest(){
String testName = "secondTestName";
String expectedBefore = "testName";
String expectedAfter = "secondTestName";
assertEquals(expectedBefore, route.getName());
route.setName(testName);
assertEquals(expectedAfter, route.getName());
}
@Test
public void getLocationsTest(){
Route route = new Route("testName");
List<Location> expected = new ArrayList<>();
assertEquals(expected, route.getLocations());
@@ -29,7 +40,6 @@ public class RouteTest {
@Test
public void SetLocationsTest(){
Route route = new Route("testName");
List<Location> testList = new ArrayList<>();
testList.add(new Location("name1", "coord1", "desc1", null));
testList.add(new Location("name2", "coord2", "desc2", null));
@@ -45,7 +55,6 @@ public class RouteTest {
@Test
public void AddLocationTest(){
Route route = new Route("testName");
Location testLocation = new Location("testLocationName", "testCoordinates", "testDescription", null);
List<Location> expectedBefore = new ArrayList<>();
@@ -59,7 +68,6 @@ public class RouteTest {
@Test
public void totalDistanceTest(){
Route route = new Route("testName");
float testDistance = 523;
float expectedBefore = 0;
@@ -72,7 +80,6 @@ public class RouteTest {
@Test
public void totalTimeTest(){
Route route = new Route("testName");
int testTime = 36;
int expectedBefore = 0;