|
| 1 | +package io.cucumber.messages; |
| 2 | + |
| 3 | +import io.cucumber.messages.types.Duration; |
| 4 | +import io.cucumber.messages.types.Exception; |
| 5 | +import io.cucumber.messages.types.Timestamp; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | + |
| 8 | +import java.util.Optional; |
| 9 | + |
| 10 | +import static org.junit.jupiter.api.Assertions.assertAll; |
| 11 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 12 | + |
| 13 | +class ConvertorTest { |
| 14 | + |
| 15 | + @Test |
| 16 | + void convertsExceptionToMessage() { |
| 17 | + Exception e = Convertor.toMessage(new RuntimeException("Hello world!")); |
| 18 | + Exception e2 = Convertor.toMessage(new RuntimeException()); |
| 19 | + assertAll( |
| 20 | + () -> assertEquals(Optional.of("Hello world!"), e.getMessage()), |
| 21 | + () -> assertEquals(Optional.empty(), e2.getMessage()), |
| 22 | + () -> assertEquals("java.lang.RuntimeException", e.getType()), |
| 23 | + () -> assertEquals("java.lang.RuntimeException", e2.getType()) |
| 24 | + ); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + void convertsToAndFromTimestamp() { |
| 29 | + java.time.Instant javaInstant = java.time.Instant.now(); |
| 30 | + Timestamp timestamp = Convertor.toMessage(javaInstant); |
| 31 | + java.time.Instant javaInstantAgain = Convertor.toInstant(timestamp); |
| 32 | + |
| 33 | + assertEquals(javaInstant, javaInstantAgain); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void convertsToAndFromDuration() { |
| 38 | + java.time.Duration javaDuration = java.time.Duration.ofSeconds(3, 161000); |
| 39 | + Duration duration = Convertor.toMessage(javaDuration); |
| 40 | + java.time.Duration javaDurationAgain = Convertor.toDuration(duration); |
| 41 | + |
| 42 | + assertEquals(javaDuration, javaDurationAgain); |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments