forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KNL-1536 - Fix duration() (sakaiproject#4611)
* KNL-1536 - Fix duration() * KNL-1536 - Add unit tests per earle
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
kernel/kernel-impl/src/test/java/org/sakaiproject/time/impl/test/BaseTimeServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.sakaiproject.user.impl; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.sakaiproject.time.api.Time; | ||
import org.sakaiproject.time.api.TimeService; | ||
import org.sakaiproject.time.api.TimeRange; | ||
import org.sakaiproject.tool.api.SessionManager; | ||
import org.sakaiproject.time.impl.BasicTimeService; | ||
import org.sakaiproject.time.impl.MyTime; | ||
import org.sakaiproject.time.impl.BasicTimeService.MyTimeRange; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Charles Severance | ||
*/ | ||
public class BaseTimeServiceTest { | ||
|
||
private BasicTimeService service; | ||
|
||
@Before | ||
public void setUp() { | ||
service = new BasicTimeService(); | ||
} | ||
|
||
@Test | ||
public void testDurtation() { | ||
Time ts = new MyTime(service, 100l); | ||
Time te = new MyTime(service, 142); | ||
|
||
// KNL-1536 The duration remains the same | ||
// regardless of included and/or excluded endpoints | ||
TimeRange tr1 = service.newTimeRange(ts, te, false, false); | ||
assertEquals(tr1.firstTime().getTime(), 101l); | ||
assertEquals(tr1.lastTime().getTime(), 141l); | ||
assertEquals(tr1.duration(),42l); | ||
|
||
tr1 = service.newTimeRange(ts, te, true, false); | ||
assertEquals(tr1.firstTime().getTime(), 100l); | ||
assertEquals(tr1.lastTime().getTime(), 141l); | ||
assertEquals(tr1.duration(),42l); | ||
|
||
tr1 = service.newTimeRange(ts, te, true, true); | ||
assertEquals(tr1.firstTime().getTime(), 100l); | ||
assertEquals(tr1.lastTime().getTime(), 142l); | ||
assertEquals(tr1.duration(),42l); | ||
|
||
tr1 = service.newTimeRange(ts, te, false, true); | ||
assertEquals(tr1.firstTime().getTime(), 101l); | ||
assertEquals(tr1.lastTime().getTime(), 142l); | ||
assertEquals(tr1.duration(),42l); | ||
} | ||
|
||
} |