|
15 | 15 | import javax.validation.UnexpectedTypeException;
|
16 | 16 | import java.util.function.Function;
|
17 | 17 |
|
18 |
| -import static org.junit.jupiter.api.Assertions.assertTrue; |
19 |
| -import static org.junit.jupiter.api.Assertions.assertNull; |
20 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
21 |
| -import static org.junit.jupiter.api.Assertions.assertThrows; |
| 18 | +import static org.junit.jupiter.api.Assertions.*; |
22 | 19 |
|
23 | 20 | class ApiTransformationConfigTest {
|
24 |
| - private AbstractApiDocService abstractApiDocService; |
| 21 | + private AbstractApiDocService<?, ?> abstractApiDocService; |
25 | 22 |
|
26 |
| - private ApiTransformationConfig apiTransformationConfig = new ApiTransformationConfig(null); |
27 |
| - private Function<String, AbstractApiDocService> beanApiDocFactory = apiTransformationConfig.beanApiDocFactory(); |
| 23 | + private final ApiTransformationConfig apiTransformationConfig = new ApiTransformationConfig(null); |
| 24 | + private final Function<String, AbstractApiDocService<?, ?>> beanApiDocFactory = apiTransformationConfig.beanApiDocFactory(); |
28 | 25 |
|
29 | 26 | @BeforeEach
|
30 | 27 | void setUp() {
|
31 | 28 | abstractApiDocService = null;
|
32 | 29 | }
|
33 | 30 |
|
34 | 31 | @Test
|
35 |
| - void testApiDocFactory_whenSwagerDocIsPresent() { |
| 32 | + void givenSwaggerJson_whenGetApiDocService_thenReturnApiDocV2Service() { |
36 | 33 | abstractApiDocService = beanApiDocFactory.apply("{\"swagger\": \"2.0\"}");
|
37 | 34 | assertTrue(abstractApiDocService instanceof ApiDocV2Service, "AbstractApiDocService is not ApiDocV2Service");
|
38 | 35 | }
|
39 | 36 |
|
40 | 37 | @Test
|
41 |
| - void testApiDocFactory_whenOpenApiDocIsPresent() { |
| 38 | + void givenOpenApiJson_whenGetApiDocService_thenReturnApiDocV3Service() { |
42 | 39 | abstractApiDocService = beanApiDocFactory.apply("{\"openapi\": \"3.0\"}");
|
43 | 40 | assertTrue(abstractApiDocService instanceof ApiDocV3Service, "AbstractApiDocService is not ApiDocV3Service");
|
44 | 41 | }
|
45 | 42 |
|
46 | 43 | @Test
|
47 |
| - void testApiDocFactory_whenApDocIsNotOpenApiNorSwagger() { |
| 44 | + void givenSwaggerYml_whenGetApiDocService_thenReturnApiDocV2Service() { |
| 45 | + abstractApiDocService = beanApiDocFactory.apply("swagger: 2.0"); |
| 46 | + assertTrue(abstractApiDocService instanceof ApiDocV2Service, "AbstractApiDocService is not ApiDocV2Service"); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void givenOpenApiYml_whenGetApiDocService_thenReturnApiDocV3Service() { |
| 51 | + abstractApiDocService = beanApiDocFactory.apply("openapi: 3.0"); |
| 52 | + assertTrue(abstractApiDocService instanceof ApiDocV3Service, "AbstractApiDocService is not ApiDocV3Service"); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void givenApiDocNotInOpenApiNorSwagger_whenGetApiDocService_thenReturnNull() { |
48 | 57 | abstractApiDocService = beanApiDocFactory.apply("{\"superapi\": \"3.0\"}");
|
49 | 58 | assertNull(abstractApiDocService, "abstractApiDocService is not null");
|
50 | 59 | }
|
51 | 60 |
|
52 | 61 | @Test
|
53 |
| - void testApiDocFactory_whenApDocVersionIsNotAsExpectedFormat() { |
| 62 | + void givenApDocVersionIsNotAsExpectedFormat_whenGetApiDocService_thenThrowException() { |
54 | 63 | Exception exception = assertThrows(UnexpectedTypeException.class, () -> {
|
55 | 64 | abstractApiDocService = beanApiDocFactory.apply("FAILED FORMAT");
|
56 | 65 | });
|
57 | 66 | assertNull(abstractApiDocService);
|
58 | 67 | assertEquals("Response is not a Swagger or OpenAPI type object.", exception.getMessage());
|
59 | 68 | }
|
60 |
| - |
61 | 69 | }
|
0 commit comments