Skip to content

Commit be6c858

Browse files
Convert tests to Kotlin
1 parent 86245bc commit be6c858

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2022, TeamDev. All rights reserved.
2+
* Copyright 2024, TeamDev. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Redistribution and use in source and/or binary forms, with or without
1111
* modification, must retain the above copyright notice and the following
@@ -24,41 +24,37 @@
2424
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27-
package io.spine.validate;
27+
package io.spine.validate
2828

29-
import com.google.common.collect.ImmutableList;
30-
import io.spine.protobuf.AnyPacker;
31-
import org.junit.jupiter.api.DisplayName;
32-
import org.junit.jupiter.api.Test;
33-
34-
import static com.google.common.truth.Truth.assertThat;
35-
import static io.spine.base.Errors.fromThrowable;
29+
import io.kotest.matchers.shouldBe
30+
import io.spine.base.Errors
31+
import io.spine.protobuf.unpackGuessingType
32+
import org.junit.jupiter.api.DisplayName
33+
import org.junit.jupiter.api.Test
3634

3735
@DisplayName("`ValidationException` should")
38-
class ValidationExceptionTest {
36+
internal class ValidationExceptionSpec {
3937

4038
@Test
41-
@DisplayName("provide `ValidationError`")
42-
void error() {
43-
var violations =
44-
ImmutableList.of(ConstraintViolation.newBuilder()
45-
.setTypeName("example.org/example.Type")
46-
.setMsgFormat("Test error")
47-
.build());
48-
var exception = new ValidationException(violations);
49-
assertThat(exception.asMessage())
50-
.isEqualTo(ValidationError.newBuilder()
51-
.addAllConstraintViolation(violations)
52-
.build());
39+
fun `provide 'ValidationError'`() {
40+
val violations = listOf<@Validated ConstraintViolation>(
41+
constraintViolation {
42+
typeName = "example.org/example.Type"
43+
msgFormat = "Test error"
44+
}
45+
)
46+
val exception = ValidationException(violations)
47+
val expected = validationError { constraintViolation.addAll(violations) }
48+
49+
exception.asMessage() shouldBe expected
5350
}
5451

5552
@Test
56-
@DisplayName("convert `ValidationException` into an error")
57-
void validation() {
58-
var violation = ConstraintViolation.newBuilder().build();
59-
var exception = new ValidationException(violation);
60-
var error = fromThrowable(exception);
61-
assertThat(AnyPacker.unpack(error.getDetails()))
62-
.isEqualTo(exception.asMessage());
53+
fun `convert 'ValidationException' into an error`() {
54+
val violation = ConstraintViolation.newBuilder().build()
55+
val exception = ValidationException(violation)
56+
val error = Errors.fromThrowable(exception)
57+
58+
error.details.unpackGuessingType() shouldBe exception.asMessage()
6359
}
6460
}

0 commit comments

Comments
 (0)