Commit 58b878a9 authored by Robert Hitt's avatar Robert Hitt
Browse files

Added unit tests for FacilityPresenter

- also fixed some logic errors in FacilityPresenter
parent b402be52
......@@ -96,7 +96,7 @@ public class FacilityPresenter {
// Else return the opening time of the next day
int nextDay = (currentDay + 1) % openTimesList.size();
int nextDay = findNextDay(openTimesList, currentDay);
String nextDayStr = parseIntToDay(nextDay);
String openingTime = openTimesList.get(nextDay).getStartTime();
......@@ -107,6 +107,17 @@ public class FacilityPresenter {
return durationMessage;
}
// Returns the next open day in the list of OpenTimes
private int findNextDay(RealmList<OpenTimes> openTimesList, int current) {
int nextDay = openTimesList.first().getStartDay();
for(OpenTimes o : openTimesList) {
if(o.getStartDay() > current)
nextDay = o.getStartDay();
}
return nextDay;
}
// Parses 24 hour formatted time String to 12 hour formatted time String
private String parseTo12HourTime(String time) {
try {
......
package srct.whatsopen;
import org.junit.Before;
import org.junit.Test;
import java.util.Calendar;
import io.realm.RealmList;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.MainSchedule;
import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.ui.presenters.FacilityPresenter;
import static org.junit.Assert.*;
......@@ -9,4 +16,79 @@ import static org.junit.Assert.*;
public class FacilityPresenterUnitTest {
FacilityPresenter mPresenter;
Facility mFacility;
Calendar now;
@Before
public void setUp() {
mPresenter = new FacilityPresenter();
OpenTimes o1 = new OpenTimes(0, 0, "11:00:00", "18:00:00"); // Mondays 11:00-18:00
OpenTimes o2 = new OpenTimes(1, 1, "13:00:00", "18:00:00"); // Tuesdays 13:00-18:00
RealmList<OpenTimes> openTimesList = new RealmList<>();
openTimesList.add(o1);
openTimesList.add(o2);
MainSchedule mainSchedule = new MainSchedule(openTimesList);
mFacility = new Facility("Chef's Table at Brooklyn Fare", "Whitetop Hall",
mainSchedule, false, true);
now = Calendar.getInstance();
}
@Test
public void testFacilityMessageOpensToday() {
// Set date
now.set(2017, 0, 9, 10, 0); // Monday, 1/9/2017, 10:00:00
String statusDuration = mPresenter.getStatusDuration(mFacility, now);
assertEquals("Opens today at 11:00 AM", statusDuration);
}
@Test
public void testFacilityMessageOpensNotToday() {
// Set date
now.set(2017, 0, 11, 10, 0); // Wednesday, 1/11/2017, 10:00:00
String statusDuration = mPresenter.getStatusDuration(mFacility, now);
assertEquals("Opens on Monday at 11:00 AM", statusDuration);
}
@Test
public void testFacilityMessageCloses() {
// Set date
now.set(2017, 0, 9, 13, 0); // Monday, 1/9/2017, 13:00:00
mFacility.setOpen(true);
String statusDuration = mPresenter.getStatusDuration(mFacility, now);
assertEquals("Closes at 6:00 PM", statusDuration);
}
@Test
public void testFacilityMessageNoSchedule() {
// Set date
now.set(2017, 0, 9, 13, 0); // Monday, 1/9/2017, 13:00:00
mFacility.setMainSchedule(new MainSchedule(new RealmList<OpenTimes>()));
String statusDuration = mPresenter.getStatusDuration(mFacility, now);
assertEquals("No open time on schedule", statusDuration);
}
@Test
public void testFacilitySchedule() {
String schedule = mPresenter.getSchedule(mFacility);
assertEquals("<b>Monday</b>: 11:00 AM - 6:00 PM<br/>" +
"<b>Tuesday</b>: 1:00 PM - 6:00 PM", schedule);
}
@Test
public void testFacilityScheduleNoSchedule() {
mFacility.setMainSchedule(new MainSchedule(new RealmList<OpenTimes>()));
String schedule = mPresenter.getSchedule(mFacility);
assertEquals("No schedule available", schedule);
}
}
......@@ -33,12 +33,13 @@ public class MainPresenterUnitTest {
mFacility = new Facility("The French Laundry", "Johnson Center",
mainSchedule, false, true);
now = Calendar.getInstance();
}
@Test
public void testFacilityIsOpen() {
// Set date
now = Calendar.getInstance();
now.set(2017, 0, 9, 12, 0); // Monday, 1/9/2017, 12:00:00
assertTrue(mPresenter.getOpenStatus(mFacility, now));
......@@ -47,7 +48,6 @@ public class MainPresenterUnitTest {
@Test
public void testFacilityIsClosed() {
// Set date
now = Calendar.getInstance();
now.set(2017, 1, 10, 12, 0); // Tuesday, 1/10/2017, 12:00:00
assertFalse(mPresenter.getOpenStatus(mFacility, now));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment