Skip to content

Commit

Permalink
KNL-1536 - Fix duration() (sakaiproject#4611)
Browse files Browse the repository at this point in the history
* KNL-1536 - Fix duration()

* KNL-1536 - Add unit tests per earle
  • Loading branch information
csev authored Jul 18, 2017
1 parent 9d4b521 commit eadc96e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,8 @@ public int hashCode() {
*/
public long duration()
{
return (lastTime().getTime() - firstTime().getTime());
// KNL-1536, SAK-30793, SAK-23076 - Get the *actual* duration - Ignore fudging
return (lastTime(0).getTime() - firstTime(0).getTime());

} // duration

Expand Down
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);
}

}

0 comments on commit eadc96e

Please sign in to comment.