Search in sources :

Example 6 with Interval

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

the class ChangesShould 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);
    Changes.of(fourMinutes, fourMinutes);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 7 with Interval

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

the class ChangesShould 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);
    Changes.of(fourMinutes, null);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 8 with Interval

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

the class ChangesShould 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 = Changes.of(fourMinutes, fiveMinutes);
    assertEquals(fourMinutes, result.getPreviousValue());
    assertEquals(fiveMinutes, result.getNewValue());
}
Also used : Timestamp(com.google.protobuf.Timestamp) Interval(io.spine.time.Interval) Test(org.junit.Test)

Example 9 with Interval

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

the class EntityClassShould 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 EntityClass<NanoEntity> entityClass = new EntityClass<>(NanoEntity.class);
    final AbstractVersionableEntity<Long, StringValue> entity = entityClass.createEntity(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 10 with Interval

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

the class IntervalsShould method return_true_if_interval_contains_timestamp.

@Test
public void return_true_if_interval_contains_timestamp() {
    final Timestamp start = newTimestamp(5, 6);
    final Timestamp end = newTimestamp(10, 10);
    final Timestamp between = newTimestamp(7, 100);
    final Interval interval = Interval.newBuilder().setStart(start).setEnd(end).build();
    assertTrue(Intervals.contains(interval, between));
}
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