Search in sources :

Example 1 with Interval

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());
}
Also used : IntervalChange(io.spine.time.change.IntervalChange) Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 2 with Interval

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);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 3 with Interval

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());
}
Also used : StringValue(com.google.protobuf.StringValue) Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 4 with Interval

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);
}
Also used : Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 5 with Interval

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);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Aggregations

Timestamp (com.google.protobuf.Timestamp)11 Interval (io.spine.time.Interval)11 Test (org.junit.Test)10 Duration (com.google.protobuf.Duration)3 StringValue (com.google.protobuf.StringValue)1 Command (io.spine.base.Command)1 IntervalChange (io.spine.time.change.IntervalChange)1