Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. @Test
  2. public void testWholeStreet(){
  3.  
  4. mockSensor1 = mock(Sensor.class);
  5. mockSensor2 = mock(Sensor.class);
  6. actuator = mock(Actuators.class);
  7. newCarData = new CarData(actuator, currentPosition, false, mockSensor1, mockSensor2, 0);
  8. //empty road till 100 so it can park
  9. for (int i = 0; i < 500; i++) {
  10. testCar.moveForward(newCarData);
  11. if (i < 101){
  12. when(newCarData.getSensorOne().getSensorAverageValue()).thenReturn(200);
  13. when(newCarData.getSensorTwo().getSensorAverageValue()).thenReturn(200);
  14. testCar.park(newCarData);
  15. assertEquals(newCarData.isParked(), true);
  16. }
  17. if (i > 101 && i < 103) {
  18. testCar.unPark(newCarData);
  19. assertEquals(newCarData.isParked(), false);
  20. when(newCarData.getSensorOne().getSensorAverageValue()).thenReturn(200);
  21. when(newCarData.getSensorTwo().getSensorAverageValue()).thenReturn(200);
  22. //when the park() method is called, the car moves 5m to check for available car sports, the empty car sports found will be
  23. //5 with the mocked sensors, to prevent it from parking still, we set the car in -3 parking sports hence the
  24. //available parking pots will be -2 + 5 = 3 so it wont have sufficent place to park.
  25. newCarData.setEmptyPlaces(-2);
  26. testCar.park(newCarData);
  27. assertEquals(newCarData.isParked(), false);
  28. }
  29. if (i > 250 && i < 501){
  30. when(newCarData.getSensorOne().getSensorAverageValue()).thenReturn(200);
  31. when(newCarData.getSensorTwo().getSensorAverageValue()).thenReturn(200);
  32. testCar.park(newCarData);
  33. assertEquals(newCarData.isParked(), true);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement