|
| 1 | +package org.springdoc.ui; |
| 2 | + |
| 3 | +import java.util.Objects; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.BeforeEach; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | +import org.springdoc.core.properties.SwaggerUiConfigProperties; |
| 8 | + |
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 11 | + |
| 12 | +class AbstractSwaggerResourceResolverTest { |
| 13 | + private SwaggerUiConfigProperties swaggerUiConfigProperties; |
| 14 | + |
| 15 | + private AbstractSwaggerResourceResolver abstractSwaggerResourceResolver; |
| 16 | + |
| 17 | + private final String VERSION = "4.18.2"; |
| 18 | + |
| 19 | + @BeforeEach |
| 20 | + public void setup(){ |
| 21 | + swaggerUiConfigProperties = new SwaggerUiConfigProperties(); |
| 22 | + swaggerUiConfigProperties.setVersion(VERSION); |
| 23 | + abstractSwaggerResourceResolver = new AbstractSwaggerResourceResolver(swaggerUiConfigProperties); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + void findWebJarResourcePath() { |
| 28 | + String path = "swagger-ui/swagger-initializer.js"; |
| 29 | + |
| 30 | + String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path); |
| 31 | + assertEquals("swagger-ui/4.18.2/swagger-initializer.js", actual); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void returNullWhenPathIsSameAsWebjar() { |
| 36 | + String path = "swagger-ui"; |
| 37 | + |
| 38 | + String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path); |
| 39 | + assertTrue(Objects.isNull(actual)); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void returNullWhenVersionIsNull() { |
| 44 | + String path = "swagger-ui/swagger-initializer.js"; |
| 45 | + swaggerUiConfigProperties.setVersion(null); |
| 46 | + |
| 47 | + String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path); |
| 48 | + assertTrue(Objects.isNull(actual)); |
| 49 | + } |
| 50 | +} |
0 commit comments