|
| 1 | +package io.github.malczuuu.problem4j.core; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotSame; |
| 5 | + |
| 6 | +import java.net.URI; |
| 7 | +import java.util.Arrays; |
| 8 | +import java.util.function.Function; |
| 9 | +import java.util.stream.Collectors; |
| 10 | +import java.util.stream.Stream; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | + |
| 13 | +class ProblemTests { |
| 14 | + |
| 15 | + @Test |
| 16 | + void givenProblemStatus_shouldSetTitleAndStatus() { |
| 17 | + Problem problem = Problem.builder().status(ProblemStatus.MULTI_STATUS).build(); |
| 18 | + |
| 19 | + assertEquals(ProblemStatus.MULTI_STATUS.getTitle(), problem.getTitle()); |
| 20 | + assertEquals(ProblemStatus.MULTI_STATUS.getStatus(), problem.getStatus()); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + void givenProblem_whenToBuilder_shouldBeAbleToRecreateOriginal() { |
| 25 | + Problem problem = |
| 26 | + Problem.builder() |
| 27 | + .type(URI.create("http://example.org/problem1")) |
| 28 | + .title("Problem1") |
| 29 | + .status(400) |
| 30 | + .detail("this is problem1") |
| 31 | + .instance(URI.create("http://example.org/instance1")) |
| 32 | + .extension("extCode1", "extValue1") |
| 33 | + .extension(Problem.extension("extCode2", "extValue2")) |
| 34 | + .extension( |
| 35 | + Arrays.asList( |
| 36 | + Problem.extension("extCode3", "extValue3"), |
| 37 | + Problem.extension("extCode4", "extValue4"))) |
| 38 | + .extension( |
| 39 | + Stream.of( |
| 40 | + Problem.extension("extCode5", "extValue5"), |
| 41 | + Problem.extension("extCode6", "extValue6"), |
| 42 | + Problem.extension("extCode7", "extValue7")) |
| 43 | + .collect(Collectors.toMap(Problem.Extension::getKey, Function.identity()))) |
| 44 | + .build(); |
| 45 | + |
| 46 | + ProblemBuilder builder = problem.toBuilder(); |
| 47 | + Problem copy = builder.build(); |
| 48 | + |
| 49 | + assertNotSame(problem, copy); |
| 50 | + assertEquals(problem, copy); |
| 51 | + } |
| 52 | +} |
0 commit comments