Search in sources :

Example 11 with Interval

use of io.spine.time.Interval in project core-java by SpineEventEngine.

the class IntervalsShould method return_duration_zero.

@Test
public void return_duration_zero() {
    final Timestamp start = newTimestamp(5, 6);
    final Interval interval = Interval.newBuilder().setStart(start).setEnd(start).build();
    assertEquals(0L, Intervals.toDuration(interval).getSeconds());
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 12 with Interval

use of io.spine.time.Interval in project core-java by SpineEventEngine.

the class IntervalsShould method calculate_duration_of_zero_interval.

@Test(expected = IllegalArgumentException.class)
public void calculate_duration_of_zero_interval() {
    final Timestamp start = newTimestamp(5, 6);
    final Timestamp end = newTimestamp(5, 6);
    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 13 with Interval

use of io.spine.time.Interval in project core-java by SpineEventEngine.

the class IntervalsShould method return_interval_between_two_timestamps.

@Test
public void return_interval_between_two_timestamps() {
    final Timestamp start = newTimestamp(5, 6);
    final Timestamp end = newTimestamp(10, 10);
    final Interval interval = Interval.newBuilder().setStart(start).setEnd(end).build();
    assertEquals(interval, Intervals.between(start, end));
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 14 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)

Example 15 with Interval

use of io.spine.time.Interval in project core-java by SpineEventEngine.

the class TimeChangesShould method do_not_accept_equal_Interval_values.

@Test(expected = IllegalArgumentException.class)
public void do_not_accept_equal_Interval_values() {
    final Timestamp fourMinutesAgo = TimeTests.Past.minutesAgo(4);
    final Timestamp now = getCurrentTime();
    final Interval fourMinutes = Intervals.between(now, fourMinutesAgo);
    TimeChanges.of(fourMinutes, fourMinutes);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Aggregations

Timestamp (com.google.protobuf.Timestamp)16 Interval (io.spine.time.Interval)16 Test (org.junit.Test)15 Duration (com.google.protobuf.Duration)3 StringValue (com.google.protobuf.StringValue)2 Command (io.spine.core.Command)1 IntervalChange (io.spine.time.change.IntervalChange)1