-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception to TestStepFinished TestRunFinished (#122)
- Loading branch information
1 parent
b6db6db
commit b61f824
Showing
23 changed files
with
518 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
.idea/ | ||
node_modules | ||
.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
java/src/generated/java/io/cucumber/messages/types/Exception.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.cucumber.messages.types; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
// Generated code | ||
@SuppressWarnings("unused") | ||
public final class Exception { | ||
private final String type; | ||
private final String message; | ||
|
||
public Exception( | ||
String type, | ||
String message | ||
) { | ||
this.type = requireNonNull(type, "Exception.type cannot be null"); | ||
this.message = message; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public Optional<String> getMessage() { | ||
return Optional.ofNullable(message); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Exception that = (Exception) o; | ||
return | ||
type.equals(that.type) && | ||
Objects.equals(message, that.message); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash( | ||
type, | ||
message | ||
); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Exception{" + | ||
"type=" + type + | ||
", message=" + message + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.cucumber.messages; | ||
|
||
import io.cucumber.messages.types.Duration; | ||
import io.cucumber.messages.types.Exception; | ||
import io.cucumber.messages.types.Timestamp; | ||
|
||
public final class Convertor { | ||
|
||
private Convertor(){ | ||
|
||
} | ||
|
||
public static Exception toMessage(Throwable t) { | ||
return new Exception(t.getClass().getName(), t.getMessage()); | ||
} | ||
|
||
public static Timestamp toMessage(java.time.Instant instant) { | ||
return new Timestamp(instant.getEpochSecond(), (long) instant.getNano()); | ||
} | ||
|
||
public static Duration toMessage(java.time.Duration duration) { | ||
return new Duration(duration.getSeconds(), (long) duration.getNano()); | ||
} | ||
|
||
public static java.time.Instant toInstant(Timestamp timestamp) { | ||
return java.time.Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); | ||
} | ||
|
||
public static java.time.Duration toDuration(Duration duration) { | ||
return java.time.Duration.ofSeconds(duration.getSeconds(), duration.getNanos()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
java/src/test/java/io/cucumber/messages/ConvertorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.cucumber.messages; | ||
|
||
import io.cucumber.messages.types.Duration; | ||
import io.cucumber.messages.types.Exception; | ||
import io.cucumber.messages.types.Timestamp; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class ConvertorTest { | ||
|
||
@Test | ||
void convertsExceptionToMessage() { | ||
Exception e = Convertor.toMessage(new RuntimeException("Hello world!")); | ||
Exception e2 = Convertor.toMessage(new RuntimeException()); | ||
assertAll( | ||
() -> assertEquals(Optional.of("Hello world!"), e.getMessage()), | ||
() -> assertEquals(Optional.empty(), e2.getMessage()), | ||
() -> assertEquals("java.lang.RuntimeException", e.getType()), | ||
() -> assertEquals("java.lang.RuntimeException", e2.getType()) | ||
); | ||
} | ||
|
||
@Test | ||
void convertsToAndFromTimestamp() { | ||
java.time.Instant javaInstant = java.time.Instant.now(); | ||
Timestamp timestamp = Convertor.toMessage(javaInstant); | ||
java.time.Instant javaInstantAgain = Convertor.toInstant(timestamp); | ||
|
||
assertEquals(javaInstant, javaInstantAgain); | ||
} | ||
|
||
@Test | ||
void convertsToAndFromDuration() { | ||
java.time.Duration javaDuration = java.time.Duration.ofSeconds(3, 161000); | ||
Duration duration = Convertor.toMessage(javaDuration); | ||
java.time.Duration javaDurationAgain = Convertor.toDuration(duration); | ||
|
||
assertEquals(javaDuration, javaDurationAgain); | ||
} | ||
|
||
} |
33 changes: 0 additions & 33 deletions
33
java/src/test/java/io/cucumber/messages/TimeConversionTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.