use of io.spine.time.Interval in project core-java by SpineEventEngine.
the class TimeChangesShould method create_IntervalChange_instance.
@Test
public void create_IntervalChange_instance() {
final Timestamp fiveMinutesAgo = TimeTests.Past.minutesAgo(5);
final Timestamp fourMinutesAgo = TimeTests.Past.minutesAgo(4);
final Timestamp now = getCurrentTime();
final Interval fourMinutes = Intervals.between(fourMinutesAgo, now);
final Interval fiveMinutes = Intervals.between(fiveMinutesAgo, now);
final IntervalChange result = TimeChanges.of(fourMinutes, fiveMinutes);
assertEquals(fourMinutes, result.getPreviousValue());
assertEquals(fiveMinutes, result.getNewValue());
}
use of io.spine.time.Interval in project core-java by SpineEventEngine.
the class TimeChangesShould method do_not_accept_null_Interval_previousValue.
@Test(expected = NullPointerException.class)
public void do_not_accept_null_Interval_previousValue() {
final Timestamp fourMinutesAgo = TimeTests.Past.minutesAgo(4);
final Timestamp now = getCurrentTime();
final Interval fourMinutes = Intervals.between(fourMinutesAgo, now);
TimeChanges.of(null, fourMinutes);
}
use of io.spine.time.Interval in project core-java by SpineEventEngine.
the class EntityShould method create_and_initialize_entity_instance.
@Test
public void create_and_initialize_entity_instance() {
final Long id = 100L;
final Timestamp before = TimeTests.Past.secondsAgo(1);
// Create and init the entity.
final Constructor<BareBonesEntity> ctor = getConstructor(BareBonesEntity.class, Long.class);
final AbstractVersionableEntity<Long, StringValue> entity = createEntity(ctor, id);
final Timestamp after = Time.getCurrentTime();
// The interval with a much earlier start to allow non-zero interval on faster computers.
final Interval whileWeCreate = Intervals.between(before, after);
assertEquals(id, entity.getId());
assertEquals(0, entity.getVersion().getNumber());
assertTrue(Intervals.contains(whileWeCreate, entity.whenModified()));
assertEquals(StringValue.getDefaultInstance(), entity.getState());
assertFalse(entity.isArchived());
assertFalse(entity.isDeleted());
}
use of io.spine.time.Interval in project core-java by SpineEventEngine.
the class IntervalsShould method calculate_duration_of_interval.
@Test
public void calculate_duration_of_interval() {
final Timestamp start = newTimestamp(5, 6);
final Timestamp end = newTimestamp(10, 10);
final Duration expectedDuration = Duration.newBuilder().setSeconds(end.getSeconds() - start.getSeconds()).setNanos(end.getNanos() - start.getNanos()).build();
final Interval interval = Intervals.between(start, end);
final Duration actualDuration = Intervals.toDuration(interval);
assertEquals(expectedDuration, actualDuration);
}
use of io.spine.time.Interval in project core-java by SpineEventEngine.
the class TimeChangesShould method do_not_accept_null_Interval_newValue.
@Test(expected = NullPointerException.class)
public void do_not_accept_null_Interval_newValue() {
final Timestamp fourMinutesAgo = TimeTests.Past.minutesAgo(4);
final Timestamp now = getCurrentTime();
final Interval fourMinutes = Intervals.between(fourMinutesAgo, now);
TimeChanges.of(fourMinutes, null);
}
Aggregations