|
1 | 1 | /*
|
2 |
| - * Copyright 2022, TeamDev. All rights reserved. |
| 2 | + * Copyright 2024, TeamDev. All rights reserved. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
6 | 6 | * You may obtain a copy of the License at
|
7 | 7 | *
|
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 | *
|
10 | 10 | * Redistribution and use in source and/or binary forms, with or without
|
11 | 11 | * modification, must retain the above copyright notice and the following
|
|
24 | 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 | 25 | */
|
26 | 26 |
|
27 |
| -package io.spine.validate; |
| 27 | +package io.spine.validate |
28 | 28 |
|
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 |
36 | 34 |
|
37 | 35 | @DisplayName("`ValidationException` should")
|
38 |
| -class ValidationExceptionTest { |
| 36 | +internal class ValidationExceptionSpec { |
39 | 37 |
|
40 | 38 | @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 |
53 | 50 | }
|
54 | 51 |
|
55 | 52 | @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() |
63 | 59 | }
|
64 | 60 | }
|
0 commit comments