Skip to content
Snippets Groups Projects
Commit e801f358 authored by Rhys Evans's avatar Rhys Evans
Browse files

further work on basic JUnit tests

parent c885b573
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ public class Trail {
private Long trailsId;
private String trailName;
private String trailNumber;
private String imgPath;
......
......@@ -49,6 +49,9 @@ public class LocationsCoordinates {
return locationCoordsLat;
}
public void setLocationID(int locationID) {
this.locationID = locationID;
}
public void setLocationCoordsLong(Double locationCoordsLong) {
this.locationCoordsLong = locationCoordsLong;
}
......
......@@ -224,7 +224,7 @@ public class PlacesController {
// When adding to the locationsCoordinates table, the order is not based on LocationID order, therefore it is needed to rearrange this list to
// follow ascending locationID so that any new coordinates match up with their intended locations.
public List<LocationsCoordinates> reorderCoordsWRTLocations(List<LocationsCoordinates> locCoords){
public static List<LocationsCoordinates> reorderCoordsWRTLocations(List<LocationsCoordinates> locCoords){
Collections.sort(locCoords,
Comparator.comparingInt(LocationsCoordinates::getLocationID));
return locCoords;
......
package Team5.SmartTowns;
import Team5.SmartTowns.data.Location;
import Team5.SmartTowns.landmarks.Landmarks;
import Team5.SmartTowns.placeswithcoordinates.LocationsCoordinates;
import Team5.SmartTowns.placeswithcoordinates.PlacesController;
import Team5.SmartTowns.placeswithcoordinates.TownWithTrails;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class JUnitSimpleTests {
@Autowired
private Environment environment;
@Test
public void landmarksTest(){ // generic for all landmarks, trails+dragons tale
Landmarks landmark = new Landmarks("99",1,"MockLandmark","Mock@Mock2.com",
"MockLandmarkDesc","MockRisca","MockImage");
assertEquals(landmark.getTrailID(),"99");
assertEquals(landmark.getLandmarkID(),1);
assertEquals(landmark.getLandmarkName(),"MockLandmark");
assertEquals(landmark.getLandmarkEmail(),"Mock@Mock2.com");
assertEquals(landmark.getLandmarkDescription(),"MockLandmarkDesc");
assertEquals(landmark.getLandmarkLocation(),"MockRisca");
assertEquals(landmark.getLandmarkPicture(),"MockImage");
landmark.setTrailID("66");
assertEquals(landmark.getTrailID(),"66");
landmark.setLandmarkID(2);
assertEquals(landmark.getLandmarkID(),2);
landmark.setLandmarkName("MockChange");
assertEquals(landmark.getLandmarkName(),"MockChange");
landmark.setLandmarkEmail("Mock@Change2.co.uk");
assertEquals(landmark.getLandmarkEmail(),"Mock@Change2.co.uk");
landmark.setLandmarkDescription("MockDescChange");
assertEquals(landmark.getLandmarkDescription(),"MockDescChange");
landmark.setLandmarkLocation("MockLondon");
assertEquals(landmark.getLandmarkLocation(),"MockLondon");
landmark.setLandmarkPicture("MockPainting");
assertEquals(landmark.getLandmarkPicture(),"MockPainting");
}
@Test
public void locationsTest(){ //specific for trail locations
Location location = new Location(1,"MockLocation", "Mock@Test.co.uk",
"MockDescription","MockCaerphilly","99",false);
assertEquals(location.getLocationID(),1);
assertEquals(location.getLocationName(),"MockLocation");
assertEquals(location.getLocationEmail(),"Mock@Test.co.uk");
assertEquals(location.getLocationDescription(),"MockDescription");
assertEquals(location.getLocationPlace(),"MockCaerphilly");
assertEquals(location.getLocationTrailID(),"99");
assertEquals(location.isLocationApproved(),false);
location.setLocationID(2);
assertEquals(location.getLocationID(),2);
location.setLocationName("MockChange");
assertEquals(location.getLocationName(),"MockChange");
location.setLocationEmail("Mock@Change.com");
assertEquals(location.getLocationEmail(),"Mock@Change.com");
location.setLocationDescription("MockTree");
assertEquals(location.getLocationDescription(),"MockTree");
location.setLocationPlace("MockCardiff");
assertEquals(location.getLocationPlace(),"MockCardiff");
location.setLocationTrailID("66");
assertEquals(location.getLocationTrailID(),"66");
location.setLocationApproved(true);
assertEquals(location.isLocationApproved(),true);
}
@Test
public void locationsCoordinatesTest(){
LocationsCoordinates locCoord = new LocationsCoordinates(1,51.57756,-3.22002);
assertEquals(locCoord.getLocationID(),1);
assertEquals(locCoord.getLocationCoordsLat(),51.57756);
assertEquals(locCoord.getLocationCoordsLong(),-3.22002);
locCoord.setLocationID(2);
assertEquals(2,locCoord.getLocationID());
locCoord.setLocationCoordsLat(66.00);
assertEquals(66,locCoord.getLocationCoordsLat());
locCoord.setLocationCoordsLong(-5.00);
assertEquals(-5,locCoord.getLocationCoordsLong());
}
@Test
void aaa() {
assertEquals(1, 1);
public void townWithTrailsTest(){
TownWithTrails townTrail = new TownWithTrails("MockCaerphilly","51.57903","-3.22075",
"51.60418", "51.55093", "-3.25222", "-3.17696");
assertEquals(townTrail.getTownName(),"MockCaerphilly");
assertEquals(townTrail.getTownCentreCoordsLat(),"51.57903");
assertEquals(townTrail.getTownCentreCoordsLong(),"-3.22075");
assertEquals(townTrail.getTownUppermostCoordsLat(),"51.60418");
assertEquals(townTrail.getTownLowermostCoordsLat(),"51.55093");
assertEquals(townTrail.getTownLeftmostCoordsLong(),"-3.25222");
assertEquals(townTrail.getTownRightmostCoordsLong(),"-3.17696");
//no setters in file add?
}
@Test
void contextLoads() {
assertThat(environment.getActiveProfiles()).contains("test");
public void reorderingLocationCoordsListToMatchIDWithLocationListTest(){
List<Location> locList = new ArrayList<>();
locList.add(new Location(1,"MockLocation", "Mock@Test.co.uk",
"MockDescription","MockCaerphilly","99",false));
locList.add(new Location(2,"MockLocation2", "Mock2@Test.co.uk",
"MockDescription2","MockCaerphilly","99",false));
locList.add(new Location(3,"MockLocation3", "Mock3@Test.co.uk",
"MockDescription","MockCaerphilly","99",false));
List<LocationsCoordinates> locCoordsList = new ArrayList<>();
locCoordsList.add(new LocationsCoordinates(3,51.57756,-3.22002));
locCoordsList.add(new LocationsCoordinates(1,51.57756,-3.22002));
locCoordsList.add(new LocationsCoordinates(2,51.57756,-3.22002));
List<LocationsCoordinates> locCoordsReorder= PlacesController.reorderCoordsWRTLocations(locCoordsList);
assertEquals(locList.get(0).getLocationID(),locCoordsReorder.get(0).getLocationID());
assertEquals(locList.get(2).getLocationID(),locCoordsReorder.get(2).getLocationID());
assertNotEquals(locList.get(1).getLocationID(),locCoordsReorder.get(2).getLocationID());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment