Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lapr.project.model;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
- import lapr.project.controller.GraphController;
- import lapr.project.data.JourneyDB;
- import lapr.project.data.ParkDB;
- import lapr.project.data.RouteDB;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertFalse;
- import static org.junit.jupiter.api.Assertions.assertThrows;
- import static org.junit.jupiter.api.Assertions.assertTrue;
- import static org.junit.jupiter.api.Assertions.fail;
- import org.junit.jupiter.api.Test;
- import org.mockito.Mock;
- import org.mockito.Mockito;
- import static org.mockito.Mockito.when;
- import org.mockito.MockitoAnnotations;
- /**
- *
- * @author morei
- */
- public class JourneyTest {
- @Mock
- ParkDB pdb;
- @Mock
- JourneyDB db;
- @Mock
- Park p;
- @Mock
- RouteDB rdb;
- @Mock
- Route route;
- Journey j = new Journey();
- List<Route> routes = new ArrayList<>();
- Journey instance = new Journey();
- Journey instance1 = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0);
- Journey instance2 = new Journey(1, new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0, new Date(10), routes);
- Journey instance3 = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0);
- Journey instance4 = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0, new Date(10));
- @Test
- public void testException() {
- Journey.setDB(null);
- NullPointerException exceptionGet = assertThrows(NullPointerException.class, () -> {
- Journey.getJourney(0);
- });
- assertTrue(exceptionGet.getMessage().equals("The dataBase connection was not yet set, either set or get a new one"));
- exceptionGet = assertThrows(NullPointerException.class, () -> {
- Journey.removeJourney(0);
- });
- assertTrue(exceptionGet.getMessage().equals("The dataBase connection was not yet set, either set or get a new one"));
- exceptionGet = assertThrows(NullPointerException.class, () -> {
- new Journey().save();
- });
- assertTrue(exceptionGet.getMessage().equals("The dataBase connection was not yet set, either set or get a new one"));
- assertTrue(Journey.getCurrentDB() == null);
- Journey.getDB();
- assertTrue(Journey.getCurrentDB() != null);
- }
- @Test
- public void testDB() {
- MockitoAnnotations.initMocks(this);
- Journey.setDB(db);
- when(db.getJourney(0)).thenReturn(j);
- assertTrue(Journey.getJourney(0).equals(j));
- System.out.println("Test remove");
- Mockito.doThrow(new IllegalArgumentException()).when(db).removeJourney(0);
- //ensure method call
- boolean exception = false;
- try {
- Journey.removeJourney(0);
- fail("There should have been an exception");
- } catch (Exception ex) {
- exception = true;
- }
- assertTrue(exception);
- Mockito.doNothing().when(db).removeJourney(0);
- Journey.removeJourney(0);
- assertTrue(true);
- System.out.println("Test save");
- System.out.println("Test save-update");
- Mockito.doThrow(new IndexOutOfBoundsException("test"))
- .when(db).updateJourney(j);
- try {
- exception = false;
- j.save();
- fail("There should have been an exception");
- } catch (IndexOutOfBoundsException ex) {
- exception = true;
- }
- assertTrue(exception);
- System.out.println("Test savve-add");
- Mockito.doThrow(new IllegalArgumentException()).when(db).updateJourney(j);
- //ensure method add is called
- Mockito.doThrow(new IndexOutOfBoundsException("test")).when(db).addJourney(j);
- try {
- exception = false;
- j.save();
- fail("There should have been an exception");
- } catch (IndexOutOfBoundsException ex) {
- exception = true;
- }
- assertTrue(exception);
- Mockito.doNothing().when(db).addJourney(j);
- System.out.println("Test save- routes");
- j.setRoutes(new ArrayList<>());
- j.addRoute(route);
- Mockito.doNothing().when(db).addJourney(j);
- Mockito.doThrow(new IndexOutOfBoundsException("test")).when(route).updateRoute();
- //ensure ps.update is being executed
- try {
- exception = false;
- j.save();
- fail("There should have been an exception");
- } catch (IndexOutOfBoundsException ex) {
- exception = true;
- }
- Mockito.doNothing().when(route).updateRoute();
- j.save();
- assertTrue(true);
- Mockito.doThrow(new IllegalArgumentException("test")).when(route).updateRoute();
- Mockito.doThrow(new IndexOutOfBoundsException("test")).when(route).save();
- //ensure ps.addParkingSlot is being executed
- try {
- exception = false;
- j.save();
- fail("There should have been an exception");
- } catch (IndexOutOfBoundsException ex) {
- exception = true;
- }
- Mockito.doNothing().when(route).save();
- j.save();
- assertTrue(true);
- Mockito.doNothing().when(db).updateJourney(j);
- j.save();
- assertTrue(true);
- System.out.println("Test end");
- Park.setDB(pdb);
- p.setLocation(new Location(0, 0, 0));
- when(pdb.getPark(0, 0)).thenReturn(p);
- j.setUserName(new User("", "349590615116555", 1, 23));
- Bicycle b1 = new Bicycle("", 1, 1, "y", 20, null);
- j.setBicycle(b1);
- route.setLocation(new Location(0, 0, 0));
- j.setRoutes(new ArrayList<>());
- j.addRoute(new Route(new Location(0, 0, 0), 0, new Timestamp(400), 0));
- j.addRoute(new Route(new Location(0, 0, 0), 0, new Timestamp(100000000), 0));
- assertFalse(j.endJourney());
- when(p.addBicycle(b1)).thenReturn(new ParkingSlot(1));
- Mockito.doThrow(new IllegalArgumentException()).when(p).save();
- assertFalse(j.endJourney());
- Mockito.doNothing().when(p).save();
- assertTrue(j.endJourney());
- assertEquals(j.getPrice(), 81);
- assertTrue(j.getMonthYear().equals(new Timestamp(100000000)));
- }
- //ENSURE UPDATE CALL
- @Test
- public void testDbGetDelete() {
- MockitoAnnotations.initMocks(this);
- Journey.setDB(db);
- //TEST OF GET
- when(db.getJourney(0)).thenReturn(j);
- assertEquals(Journey.getJourney(0), j);
- //TEST OF REMOVE
- //ENSURE REMOVE IS CALLED
- Mockito.doThrow(new ArrayIndexOutOfBoundsException()).when(db).removeJourney(0);
- ArrayIndexOutOfBoundsException exceptionGet = assertThrows(ArrayIndexOutOfBoundsException.class, () -> {
- Journey.removeJourney(0);
- });
- assertTrue(exceptionGet.getMessage() == null);
- Mockito.doNothing().when(db).removeJourney(0);
- Journey.removeJourney(0);
- assertTrue(true);
- }
- /**
- * Test of getId method, of class Journey.
- */
- @Test
- public void testGetIdReservation() {
- System.out.println("getIdReservation");
- int expResult = 1;
- int result = instance2.getIdReservation();
- assertEquals(expResult, result);
- }
- /**
- * Test of getReservationDate method, of class Journey.
- */
- @Test
- public void testGetReservationDate() {
- System.out.println("getReservationDate");
- Timestamp expResult = new Timestamp(10);
- Timestamp result = instance2.getReservationDate();
- assertEquals(expResult, result);
- }
- /**
- * Test of getPrice method, of class Journey.
- */
- @Test
- public void testGetPrice() {
- System.out.println("getPrice");
- int expResult = 0;
- int result = instance2.getPrice();
- assertEquals(expResult, result);
- }
- /**
- * Test of getMonthYear method, of class Journey.
- */
- @Test
- public void testGetMonthYear() {
- System.out.println("getMonthYear");
- Date expResult = new Date(10);
- Date result = instance2.getMonthYear();
- assertEquals(expResult, result);
- }
- /**
- * Test of setReservationDate method, of class Journey.
- */
- @Test
- public void testSetReservationDate() {
- System.out.println("setReservationDate");
- Timestamp reservationDate = new Timestamp(15);
- instance2.setReservationDate(reservationDate);
- assertEquals(reservationDate, instance2.getReservationDate());
- }
- /**
- * Test of setUserName method, of class Journey.
- */
- @Test
- public void testSetUsername() {
- System.out.println("testSetUsername");
- User instance = new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0);
- instance2.setUserName(instance);
- assertEquals(instance, instance2.getUser());
- }
- /**
- * Test of setIdBicycle method, of class Journey.
- */
- @Test
- public void testSetIdBicycle() {
- System.out.println("setIdBicycle");
- Bicycle b1 = new Bicycle("", 1, 1, "y", 15.6, "oo");
- instance2.setBicycle(b1);
- assertEquals(b1, instance2.getBicycle());
- }
- /**
- * Test of setPrice method, of class Journey.
- */
- @Test
- public void testSetPrice() {
- System.out.println("setPrice");
- int price = 15;
- instance2.setPrice(price);
- assertEquals(price, instance2.getPrice());
- }
- /**
- * Test of setMonthYear method, of class Journey.
- */
- @Test
- public void testSetMonthYear() {
- System.out.println("setMonthYear");
- Date monthYear = new Date(15);
- instance2.setMonthYear(monthYear);
- assertEquals(monthYear, instance2.getMonthYear());
- }
- /**
- * Test of toString method, of class Journey.
- */
- @Test
- public void testToString() {
- System.out.println("toString");
- // String expResult = "Reservation date 1970-01-01 01:00:00.01 Email 1161263@isep.ipp.pt Id bicycle 1 Price 0 Month Year Thu Jan 01 01:00:00 WET 1970";
- String expResult1 = "Reservation date "
- + instance2.getReservationDate().toString()
- + " Username " + instance2.getUser().getUsername()
- + " Id bicycle " + instance2.getBicycle().getDescription()
- + " Price " + instance2.getPrice()
- + " Month Year " + instance2.getMonthYear().toString();
- String result = instance2.toString();
- assertEquals(expResult1, result);
- }
- /**
- * Test of equals method, of class Journey.
- */
- @Test
- public void testEquals() {
- System.out.println("equals");
- Object obj = null;
- boolean expResult = false;
- boolean result = instance.equals(obj);
- assertEquals(expResult, result);
- }
- /**
- * Test of equals method, of class Journey.
- */
- @Test
- public void testEqualsDiferentClass() {
- System.out.println("equals");
- Object obj = new Park("", new Location(), 0, 0);
- boolean expResult = false;
- boolean result = instance.equals(obj);
- assertEquals(expResult, result);
- }
- /**
- * Test of equals method, of class Journey.
- */
- @Test
- public void testEquals1() {
- System.out.println("equals");
- Object obj = instance2;
- boolean expResult = true;
- boolean result = instance2.equals(obj);
- assertEquals(expResult, result);
- }
- /**
- * Test of equals method, of class Journey.
- */
- @Test
- public void testEquals2() {
- System.out.println("equals");
- Object obj = new Journey(2, new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0, new Date(10), routes);
- boolean expResult = false;
- boolean result = instance2.equals(obj);
- assertEquals(expResult, result);
- }
- /**
- * Test of equals method, of class Journey.
- */
- @Test
- public void testEquals3() {
- System.out.println("equals");
- Object obj = new Journey(1, new User("", "NOTadminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(15), new Bicycle("", 2, 1, "y", 15.6, null), 2, new Date(15), routes);
- boolean expResult = true;
- boolean result = instance2.equals(obj);
- assertEquals(expResult, result);
- }
- /**
- * Test of routes methods, of class Journey.
- */
- @Test
- public void testSetAddGetRoutes() {
- List<Route> routes = new ArrayList<>();
- routes.add(new Route(null, 0));
- Journey journey = new Journey();
- journey.setRoutes(routes);
- journey.addRoute(new Route(null, 1));
- assertEquals(journey.getRoutes().size(), 2);
- assertEquals(journey.getRoutes(), routes);
- }
- @Test
- public void testCalcPrice() {
- List<Route> routes = new ArrayList<>();
- routes.add(new Route(new Timestamp(0), 0));
- routes.add(new Route(new Timestamp(10000000), 0));
- Journey test = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null));
- test.setRoutes(routes);
- test.calculatePrice();
- assertEquals(test.getPrice(), 6);
- test.calculateMonthYear();
- assertEquals(test.getMonthYear(), new Timestamp(10000000));
- routes.get(0).setVisitDate(new Timestamp(10000000));
- test.calculatePrice();
- assertEquals(test.getPrice(), 0);
- }
- /**
- * Test of hashCode method, of class Journey.
- */
- @Test
- public void testHashCode() {
- System.out.println("hashCode");
- int expResult = hashCode(instance2);
- int result = instance2.hashCode();
- assertEquals(expResult, result);
- }
- public int hashCode(Journey j) {
- int hash = 5;
- hash = 37 * hash + j.getIdReservation();
- return hash;
- }
- @Test
- public void testCalculateCredits() {
- MockitoAnnotations.initMocks(this);
- List<Route> rou1 = new ArrayList<>();
- Journey journey = new Journey(1, new User("", "349590615116555", 0, 0), new Timestamp(50),
- new Bicycle("a", 1, 1, "Y", 20.0, "name"), 30, new Timestamp(60), rou1);
- assertTrue(journey.getCredits() == null);
- assertTrue(journey.getUser().getCreditPoints() == 0);
- Journey.setDB(null);
- journey.calculateCredits();
- assertTrue(journey.getCredits() == null);
- assertTrue(journey.getUser().getCreditPoints() == 0);
- //
- Journey.setDB(db);
- assertTrue(Journey.getCurrentDB() != null);
- Route r = new Route(new Location(0, 0, 0), 0, new Timestamp(0), 0);
- Route r1 = new Route(new Location(0, 0, 0), 0, new Timestamp(5000000), 0);
- journey.setRoutes(new ArrayList<>());
- journey.addRoute(r);
- journey.addRoute(r1);
- when(db.getJourneyCredits(29, new Location(29, 29, 29))).thenReturn(5000);
- //
- }
- @Test
- public void testCalculateEnergyBetweenParksEletricBicycle() {
- System.out.println("testCalculateEnergyBetweenParksEletricBicycle");
- GraphController graphController = new GraphController(new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f));
- Set<Point> points = new HashSet<>();
- Point p1 = new TouristicPoint(12, 12, 21, "TESTE");
- Point p2 = new Park("", new Location(13, 13, 13), 0, 0);
- points.add(p1);
- points.add(p2);
- graphController.getGraphHandler().addPoints(points);
- graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
- graphController.getGraphHandler().setWind(p1, p2, 5.0, 0);
- graphController.getGraphHandler().setDistance(p1, p2, 25.1);
- User user = new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f);
- user.setHeight(180.4);
- user.setAverageSpeed(10.5);
- Battery bat = new Battery(2, 120.5, 30.4, new Timestamp(10));
- EBicycle eb = new EBicycle("", 1, 1, "y", 15.6, bat, "abc@gmail.com");
- eb.setAerodynamic(0.65f);
- double airV1 = graphController.getGraphHandler().getWind(p1, p2);
- graphController.getGraphHandler().setCoeficient(p1, p2, 0.5);
- //--------------------------------------------//
- Location li = p1.getLocation();
- Location lf = p2.getLocation();
- double bang = Wind.calculatePathDirection(li, lf);
- double inicialHeight = (double) li.getAltitude();
- double finalHeight = (double) lf.getAltitude();
- double distance = graphController.getGraphHandler().getDistance(p1, p2);
- System.out.println(distance);
- double bodyArea = Math.sqrt(((user.getWeight() + eb.getWeigth()) * user.getHeight()) / 3600);
- System.out.println(bodyArea);
- double heightDifference = finalHeight - inicialHeight;
- System.out.println(heightDifference);
- double angle = (Math.asin(heightDifference / distance));
- System.out.println(angle);
- double resAng = bang - angle;
- double fa = ((eb.getWeigth() + user.getWeight()) * 9.8 * graphController.getGraphHandler().getCoefficient(p1, p2));
- System.out.println(fa);
- double df = (0.5 * 1.2041 * (Math.pow(Bicycle.ELETRICBICYCLEVELOCITY - airV1 * Math.cos(resAng), 2)) * eb.getAerodynamic() * bodyArea);
- System.out.println(df);
- double gf = (user.getWeight() + eb.getWeigth()) * 9.8 * heightDifference * Math.sin(angle);
- System.out.println(gf);
- double arf = bodyArea * 1.2041 * eb.getAerodynamic() * (Math.pow((user.getAverageSpeed() - airV1 * Math.cos(resAng)), 2));
- System.out.println(arf);
- double total = ((fa * distance) + (df * distance) + (gf * distance) + (arf * distance));
- System.out.println(total);
- double expResult = total * 2.77777778E-7;
- double result = Journey.calculateEnergyBetweenTwoLocations(li, lf, user, user.getAverageSpeed(), eb, graphController.getGraphHandler());
- assertEquals(expResult, result, 0.01);
- }
- @Test
- public void testCalculateEnergyBetweenParksRoadBicycle() {
- System.out.println("testCalculateEnergyBetweenParksRoadBicycle");
- GraphController graphController = new GraphController(new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f));
- Set<Point> points = new HashSet<>();
- Point p1 = new TouristicPoint(12, 12, 21, "TESTE");
- Point p2 = new Park("", new Location(13, 13, 13), 0, 0);
- points.add(p1);
- points.add(p2);
- graphController.getGraphHandler().addPoints(points);
- graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
- graphController.getGraphHandler().setWind(p1, p2, 5.0, 5);
- graphController.getGraphHandler().setDistance(p1, p2, 25.1);
- User user = new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f);
- user.setHeight(180.4);
- user.setAverageSpeed(10.5);
- Bicycle eb = new Bicycle("", 1, 1, "y", 15.6, "abc@gmail.com");
- eb.setAerodynamic(0.65f);
- double airV1 = graphController.getGraphHandler().getWind(p1, p2);
- graphController.getGraphHandler().setCoeficient(p1, p2, 0.5);
- //--------------------------------------------//
- Location li = p1.getLocation();
- Location lf = p2.getLocation();
- double bang = Wind.calculatePathDirection(li, lf);
- double inicialHeight = (double) li.getAltitude();
- double finalHeight = (double) lf.getAltitude();
- double distance = graphController.getGraphHandler().getDistance(p1, p2);
- System.out.println(distance);
- double bodyArea = Math.sqrt(((user.getWeight() + eb.getWeigth()) * user.getHeight()) / 3600);
- System.out.println(bodyArea);
- double heightDifference = finalHeight - inicialHeight;
- System.out.println(heightDifference);
- double angle = (Math.asin(heightDifference / distance));
- System.out.println(angle);
- double resAng = bang - angle;
- double fa = ((eb.getWeigth() + user.getWeight()) * 9.8 * graphController.getGraphHandler().getCoefficient(p1, p2));
- System.out.println(fa);
- double df = (0.5 * 1.2041 * (Math.pow(Bicycle.ROADBICYCLEVELOCITY - airV1 * Math.cos(resAng), 2)) * eb.getAerodynamic() * bodyArea);
- System.out.println(df);
- double gf = (user.getWeight() + eb.getWeigth()) * 9.8 * heightDifference * Math.sin(angle);
- System.out.println(gf);
- double arf = bodyArea * 1.2041 * eb.getAerodynamic() * (Math.pow((user.getAverageSpeed() - airV1 * Math.cos(resAng)), 2));
- System.out.println(arf);
- double total = ((fa * distance) + (df * distance) + (gf * distance) + (arf * distance));
- System.out.println(total);
- double expResult = total * 2.77777778E-7;
- double result = Journey.calculateEnergyBetweenTwoLocations(li, lf, user, user.getAverageSpeed(), eb, graphController.getGraphHandler());
- assertEquals(expResult, result, 0.01);
- }
- @Test
- public void testEnergyDuringJourney() {
- System.out.println("testEnergyDuringJourney");
- GraphController graphController = new GraphController(new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0));
- Set<Point> points = new HashSet<>();
- Point p1 = new TouristicPoint(10, 10, 10, "TESTE");
- Point p2 = new Park("", new Location(12, 12, 12), 0, 0);
- points.add(p1);
- points.add(p2);
- graphController.getGraphHandler().addPoints(points);
- graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
- Route r = new Route(new Location(10, 10, 10), 1, new Timestamp(0), 0.0);
- Route r1 = new Route(new Location(12, 12, 12), 1, new Timestamp(3600000 * 4), 0.0);
- List<Route> rl = new ArrayList<>();
- rl.add(r);
- rl.add(r1);
- graphController.getGraphHandler().setWind(p1, p2, 5.0, 0);
- Journey journey = new Journey(1, new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 5, null, rl);
- journey.getUser().setAverageSpeed(10.5);
- double expResult = 2.7056009670732324E-5;
- double result = Journey.calculateEnergyDuringJourney(journey, graphController.getGraphHandler());
- assertEquals(expResult, result, 0.01);
- }
- /**
- * Test of calculateBurnedCalories method, of class Journey.
- */
- @Test
- public void testCalculateBurnedCalories() {
- System.out.println("calculateBurnedCalories");
- GraphController graphController = new GraphController(new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0));
- Set<Point> points = new HashSet<>();
- Point p1 = new TouristicPoint(10, 10, 10, "TESTE");
- Point p2 = new Park("", new Location(12, 12, 12), 0, 0);
- points.add(p1);
- points.add(p2);
- graphController.getGraphHandler().addPoints(points);
- graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
- Route r = new Route(new Location(10, 10, 10), 1, new Timestamp(0), 0.0);
- Route r1 = new Route(new Location(12, 12, 12), 1, new Timestamp(3600000 * 4), 0.0);
- List<Route> rl = new ArrayList<>();
- rl.add(r);
- rl.add(r1);
- graphController.getGraphHandler().setWind(p1, p2, 5.0, 0);
- Journey journey = new Journey(1, new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 5, null, rl);
- double expResult = 5.6102685487062536E7;
- double result = Journey.calculateBurnedCalories(journey, graphController.getGraphHandler());
- assertEquals(expResult, result, 0.01);
- journey.setBicycle(new Bicycle("", 2, 2, "y", 15.6, null));
- expResult = 2.068090551724417E8;
- result = Journey.calculateBurnedCalories(journey, graphController.getGraphHandler());
- assertEquals(expResult, result, 0.01);
- }
- /**
- * Test of getTotalMonth method, of class Invoice.
- */
- @Test
- public void testGetTotalMonth() {
- System.out.println("getTotalMonth");
- Set<Journey> journeys = new HashSet<>();
- Journey j1 = new Journey();
- j1.setPrice(10);
- Journey j2 = new Journey();
- j2.setPrice(12);
- j1.setPrice(12);
- journeys.add(j1);
- journeys.add(j2);
- double expResult = 12.0;
- double result = Journey.getTotalMonth(journeys);
- assertEquals(expResult, result, 0.001);
- }
- @Test
- public void testGetSetCredits() {
- System.out.println("testgetSetCredits");
- Integer exp = 2;
- instance2.setCredits(exp);
- assertEquals(exp, instance2.getCredits());
- }
- @Test
- public void testgetIdBicycle() {
- System.out.println("testgetSetCredits");
- Bicycle b = new Bicycle("a", 1, 1, "Y", 20.0, "name");
- instance2.setIdBicycle(b);
- assertEquals(b, instance2.getBicycle());
- }
- @Test
- public void testsetUser() {
- System.out.println("testgetSetCredits");
- User u = new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0);
- instance2.setUser(u);
- assertEquals(u, instance2.getUser());
- }
- @Test
- public void testSetIdReservation() {
- System.out.println("test id Reservation");
- int exp = 12;
- instance2.setIdReservation(exp);
- assertEquals(exp, instance2.getIdReservation());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement