Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-android
Commits
58b878a9
Commit
58b878a9
authored
Jan 08, 2017
by
Robert Hitt
Browse files
Added unit tests for FacilityPresenter
- also fixed some logic errors in FacilityPresenter
parent
b402be52
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/srct/whatsopen/ui/presenters/FacilityPresenter.java
View file @
58b878a9
...
@@ -96,7 +96,7 @@ public class FacilityPresenter {
...
@@ -96,7 +96,7 @@ public class FacilityPresenter {
// Else return the opening time of the next day
// 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
nextDayStr
=
parseIntToDay
(
nextDay
);
String
openingTime
=
openTimesList
.
get
(
nextDay
).
getStartTime
();
String
openingTime
=
openTimesList
.
get
(
nextDay
).
getStartTime
();
...
@@ -107,6 +107,17 @@ public class FacilityPresenter {
...
@@ -107,6 +107,17 @@ public class FacilityPresenter {
return
durationMessage
;
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
// Parses 24 hour formatted time String to 12 hour formatted time String
private
String
parseTo12HourTime
(
String
time
)
{
private
String
parseTo12HourTime
(
String
time
)
{
try
{
try
{
...
...
app/src/test/java/srct/whatsopen/FacilityPresenterUnitTest.java
View file @
58b878a9
package
srct.whatsopen
;
package
srct.whatsopen
;
import
org.junit.Before
;
import
org.junit.Test
;
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
srct.whatsopen.ui.presenters.FacilityPresenter
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.*;
...
@@ -9,4 +16,79 @@ import static org.junit.Assert.*;
...
@@ -9,4 +16,79 @@ import static org.junit.Assert.*;
public
class
FacilityPresenterUnitTest
{
public
class
FacilityPresenterUnitTest
{
FacilityPresenter
mPresenter
;
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
);
}
}
}
app/src/test/java/srct/whatsopen/MainPresenterUnitTest.java
View file @
58b878a9
...
@@ -33,12 +33,13 @@ public class MainPresenterUnitTest {
...
@@ -33,12 +33,13 @@ public class MainPresenterUnitTest {
mFacility
=
new
Facility
(
"The French Laundry"
,
"Johnson Center"
,
mFacility
=
new
Facility
(
"The French Laundry"
,
"Johnson Center"
,
mainSchedule
,
false
,
true
);
mainSchedule
,
false
,
true
);
now
=
Calendar
.
getInstance
();
}
}
@Test
@Test
public
void
testFacilityIsOpen
()
{
public
void
testFacilityIsOpen
()
{
// Set date
// Set date
now
=
Calendar
.
getInstance
();
now
.
set
(
2017
,
0
,
9
,
12
,
0
);
// Monday, 1/9/2017, 12:00:00
now
.
set
(
2017
,
0
,
9
,
12
,
0
);
// Monday, 1/9/2017, 12:00:00
assertTrue
(
mPresenter
.
getOpenStatus
(
mFacility
,
now
));
assertTrue
(
mPresenter
.
getOpenStatus
(
mFacility
,
now
));
...
@@ -47,7 +48,6 @@ public class MainPresenterUnitTest {
...
@@ -47,7 +48,6 @@ public class MainPresenterUnitTest {
@Test
@Test
public
void
testFacilityIsClosed
()
{
public
void
testFacilityIsClosed
()
{
// Set date
// Set date
now
=
Calendar
.
getInstance
();
now
.
set
(
2017
,
1
,
10
,
12
,
0
);
// Tuesday, 1/10/2017, 12:00:00
now
.
set
(
2017
,
1
,
10
,
12
,
0
);
// Tuesday, 1/10/2017, 12:00:00
assertFalse
(
mPresenter
.
getOpenStatus
(
mFacility
,
now
));
assertFalse
(
mPresenter
.
getOpenStatus
(
mFacility
,
now
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment