package testing;

import static org.junit.Assert.*;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;

import ostCom.OSTConnection;
import rest.JSONParsing;
import utils.Constants;
import classes.StopTime;
import classes.StopTimeList;
import enumerations.JSONClasses;

public class GetSchedules {

	/*
	 * Testar se os horarios devolvidos pertencem à trip associada 
	 * atribuida */
	@Test
	public void testAllSchedules() {
	
		int idRoute = 525;
		
		String myDate = "07:45";
		int rangeDate = 1;
			
		String schedulesRoutes = OSTConnection.getTimeSchedules(0, 25, idRoute, Constants.SMTUC, myDate, rangeDate);
		StopTimeList stopTimes = (StopTimeList)JSONParsing.parsed(schedulesRoutes, JSONClasses.StopTime);
		
		DateFormat dateFormat = new SimpleDateFormat("hh:mm");
		DateFormat rangeFormat = new SimpleDateFormat("hh");
		
		for (StopTime stoptime:stopTimes.getObjects()) {
			System.out.println(stoptime.toString());
			try {
				Date dateArrival = dateFormat.parse(stoptime.getArrival_times());
				Date dateDeparture = dateFormat.parse(stoptime.getDeparture_times());
				
				Date rangeParam = rangeFormat.parse(rangeDate+"");
				
				long arrivalTime = dateArrival.getTime();
				long departureTime = dateDeparture.getTime();
				
				long floorDate = arrivalTime - rangeParam.getTime();
				long ceilDate = arrivalTime + rangeParam.getTime();
				
				assertTrue( floorDate <= arrivalTime && arrivalTime <= ceilDate );
				assertTrue( floorDate <= departureTime && departureTime <= ceilDate );

			} catch (Exception e) {
				fail("Estudasses");
			}
		}
	}
}

@@ -944,60 +944,9 @@
 %7B%0A%09%09
-%09System.out.println(stoptime.toString());%0A%09%09%09try %7B%0A%09
+%0A
 %09%09%09D
@@ -1010,17 +1010,16 @@
 mes());%0A
-%09
 %09%09%09Date 
@@ -1086,22 +1086,20 @@
 ());%0A%09%09%09
-%09
 %0A%09%09%09
-%09
 Date ran
@@ -1140,27 +1140,25 @@
 ate+%22%22);%0A%09%09%09
-%09%0A%09
+%0A
 %09%09%09long arri
@@ -1182,33 +1182,32 @@
 ival.getTime();%0A
-%09
 %09%09%09long departur
@@ -1242,19 +1242,17 @@
 e();%0A%09%09%09
-%09%0A%09
+%0A
 %09%09%09long 
@@ -1299,17 +1299,16 @@
 Time();%0A
-%09
 %09%09%09long 
@@ -1357,19 +1357,17 @@
 e();%0A%09%09%09
-%09%0A%09
+%0A
 %09%09%09asser
@@ -1431,17 +1431,16 @@
 e );%0A%09%09%09
-%09
 assertTr
@@ -1505,65 +1505,8 @@
 e );
-%0A%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09fail(%22Estudasses%22);%0A%09%09%09%7D
 %0A%09%09%7D

Update GetSchedules.java