-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add unit test for additional branches
- Loading branch information
Showing
4 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/test/java/com/endava/cats/context/CatsGlobalContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.endava.cats.context; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.headers.Header; | ||
import io.swagger.v3.oas.models.parameters.Parameter; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
@QuarkusTest | ||
class CatsGlobalContextTest { | ||
|
||
@Test | ||
void shouldAddExample() { | ||
CatsGlobalContext context = new CatsGlobalContext(); | ||
context.addGeneratedExample("/test", List.of("example")); | ||
|
||
Assertions.assertThat(context.getGeneratedExamplesCache().get("/test")).containsExactly("example"); | ||
} | ||
|
||
@Test | ||
void shouldResolveParametersReferences() { | ||
CatsGlobalContext context = new CatsGlobalContext(); | ||
OpenAPI openAPI = Mockito.mock(OpenAPI.class); | ||
Components components = Mockito.mock(Components.class); | ||
Mockito.when(openAPI.getComponents()).thenReturn(components); | ||
Map<String, Parameter> parameterMap = Map.of("Example", new Parameter()); | ||
Mockito.when(components.getParameters()).thenReturn(parameterMap); | ||
context.init(openAPI, List.of(), new Properties(), new CatsConfiguration("1", "2", "3", List.of(), 4, 5, 6)); | ||
|
||
String reference = "#/components/parameters/Example"; | ||
Object resolvedObject = context.getObjectFromPathsReference(reference); | ||
|
||
Assertions.assertThat(resolvedObject).isNotNull(); | ||
|
||
String otherReference = "#/components/parameters/OtherExample"; | ||
Object otherResolvedObject = context.getObjectFromPathsReference(otherReference); | ||
Assertions.assertThat(otherResolvedObject).isNull(); | ||
} | ||
|
||
@Test | ||
void shouldResolveHeadersReferences() { | ||
CatsGlobalContext context = new CatsGlobalContext(); | ||
OpenAPI openAPI = Mockito.mock(OpenAPI.class); | ||
Components components = Mockito.mock(Components.class); | ||
Mockito.when(openAPI.getComponents()).thenReturn(components); | ||
Map<String, io.swagger.v3.oas.models.headers.Header> headerMap = Map.of("Example", new Header()); | ||
Mockito.when(components.getHeaders()).thenReturn(headerMap); | ||
context.init(openAPI, List.of(), new Properties(), new CatsConfiguration("1", "2", "3", List.of(), 4, 5, 6)); | ||
|
||
String reference = "#/components/headers/Example"; | ||
Object resolvedObject = context.getObjectFromPathsReference(reference); | ||
|
||
Assertions.assertThat(resolvedObject).isNotNull(); | ||
|
||
String otherReference = "#/components/headers/OtherExample"; | ||
Object otherResolvedObject = context.getObjectFromPathsReference(otherReference); | ||
Assertions.assertThat(otherResolvedObject).isNull(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.endava.cats.util; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
@QuarkusTest | ||
class JsonSetTest { | ||
|
||
@Test | ||
void shouldReturnSize() { | ||
JsonSet jsonSet = new JsonSet(); | ||
Assertions.assertThat(jsonSet.size()).isZero(); | ||
|
||
jsonSet.add("test"); | ||
Assertions.assertThat(jsonSet.size()).isOne(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("jsonSetTestDataProvider") | ||
void testJsonSet(String[] jsonStrings, int expectedSize) { | ||
JsonSet jsonSet = new JsonSet(); | ||
for (String jsonString : jsonStrings) { | ||
jsonSet.add(jsonString); | ||
} | ||
Assertions.assertThat(jsonSet.size()).isEqualTo(expectedSize); | ||
} | ||
|
||
private static Stream<Object[]> jsonSetTestDataProvider() { | ||
return Stream.of( | ||
new Object[]{new String[]{}, 0}, | ||
new Object[]{new String[]{"test"}, 1}, | ||
new Object[]{new String[]{"{\"field\":\"value\"}", "{\"field\":\"value\"}"}, 1}, | ||
new Object[]{new String[]{"{\"field\":\"value\"}", "{\"field\":\"otherValue\"}"}, 1}, | ||
new Object[]{new String[]{"{\"field\":\"value\"}", "{\"field1\":\"otherValue\"}"}, 2} | ||
); | ||
} | ||
} |