Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit ab9e03b

Browse files
committed
Updates BooleanSchemaTest
1 parent 5fb38ef commit ab9e03b

File tree

4 files changed

+100
-31
lines changed

4 files changed

+100
-31
lines changed

samples/client/petstore/kotlin/src/main/kotlin/org/openapijsonschematools/client/schemas/validation/TypeValidator.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ class TypeValidator : KeywordValidator {
1515
Void::class.java
1616
}
1717
is List<*> -> {
18-
MutableList::class.java
18+
List::class.java
1919
}
2020

2121
is Map<*, *> -> {
22-
MutableMap::class.java
22+
Map::class.java
23+
}
24+
25+
is Boolean -> {
26+
Boolean::class.java
2327
}
2428

2529
else -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.openapijsonschematools.client.schemas
2+
3+
import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags
4+
import org.openapijsonschematools.client.configurations.SchemaConfiguration
5+
import org.openapijsonschematools.client.exceptions.ValidationException
6+
import org.openapijsonschematools.client.schemas.BooleanJsonSchema.BooleanJsonSchema1
7+
import org.openapijsonschematools.client.schemas.validation.JsonSchema
8+
import org.openapijsonschematools.client.schemas.validation.PathToSchemasMap
9+
import org.openapijsonschematools.client.schemas.validation.ValidationMetadata
10+
import kotlin.test.Test
11+
import kotlin.test.assertFailsWith
12+
import kotlin.test.assertFalse
13+
import kotlin.test.assertTrue
14+
15+
class BooleanSchemaTest {
16+
@Test
17+
@Throws(ValidationException::class)
18+
fun testValidateTrue() {
19+
val validatedValue = booleanJsonSchema.validate(true, configuration)
20+
assertTrue(validatedValue)
21+
}
22+
23+
@Test
24+
@Throws(ValidationException::class)
25+
fun testValidateFalse() {
26+
val validatedValue = booleanJsonSchema.validate(false, configuration)
27+
assertFalse(validatedValue)
28+
}
29+
30+
@Test
31+
fun testExceptionThrownForInvalidType() {
32+
assertFailsWith<ValidationException>(
33+
block = {
34+
JsonSchema.validate(
35+
booleanJsonSchema,
36+
null,
37+
validationMetadata
38+
)
39+
}
40+
)
41+
}
42+
43+
companion object {
44+
val configuration = SchemaConfiguration(JsonSchemaKeywordFlags.Builder().build())
45+
val booleanJsonSchema = BooleanJsonSchema1.getInstance()
46+
val validationMetadata = ValidationMetadata(
47+
listOf("args[0"),
48+
configuration,
49+
PathToSchemasMap(),
50+
LinkedHashSet()
51+
)
52+
}
53+
}

src/main/resources/kotlin/src/main/kotlin/packagename/schemas/validation/TypeValidator.hbs

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ class TypeValidator : KeywordValidator {
1515
Void::class.java
1616
}
1717
is List<*> -> {
18-
MutableList::class.java
18+
List::class.java
1919
}
2020

2121
is Map<*, *> -> {
22-
MutableMap::class.java
22+
Map::class.java
23+
}
24+
25+
is Boolean -> {
26+
Boolean::class.java
2327
}
2428

2529
else -> {
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,53 @@
11
package {{{packageName}}}.schemas;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
53
import {{{packageName}}}.configurations.JsonSchemaKeywordFlags;
64
import {{{packageName}}}.configurations.SchemaConfiguration;
75
import {{{packageName}}}.exceptions.ValidationException;
86
import {{{packageName}}}.schemas.validation.JsonSchema;
97
import {{{packageName}}}.schemas.validation.PathToSchemasMap;
108
import {{{packageName}}}.schemas.validation.ValidationMetadata;
119

12-
import java.util.LinkedHashSet;
13-
import java.util.List;
10+
import kotlin.test.Test
11+
import kotlin.test.assertFailsWith
12+
import kotlin.test.assertFalse
13+
import kotlin.test.assertTrue
1414

15-
public class BooleanSchemaTest {
16-
static final SchemaConfiguration configuration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build());
17-
static final BooleanJsonSchema.BooleanJsonSchema1 booleanJsonSchema = BooleanJsonSchema.BooleanJsonSchema1.getInstance();
18-
static final ValidationMetadata validationMetadata = new ValidationMetadata(
19-
List.of("args[0"),
20-
configuration,
21-
new PathToSchemasMap(),
22-
new LinkedHashSet<>()
23-
);
24-
15+
class BooleanSchemaTest {
2516
@Test
26-
public void testValidateTrue() throws ValidationException {
27-
boolean validatedValue = booleanJsonSchema.validate(true, configuration);
28-
Assert.assertTrue(validatedValue);
17+
@Throws(ValidationException::class)
18+
fun testValidateTrue() {
19+
val validatedValue = booleanJsonSchema.validate(true, configuration)
20+
assertTrue(validatedValue)
2921
}
3022

3123
@Test
32-
public void testValidateFalse() throws ValidationException {
33-
boolean validatedValue = booleanJsonSchema.validate(false, configuration);
34-
Assert.assertFalse(validatedValue);
24+
@Throws(ValidationException::class)
25+
fun testValidateFalse() {
26+
val validatedValue = booleanJsonSchema.validate(false, configuration)
27+
assertFalse(validatedValue)
3528
}
3629

3730
@Test
38-
public void testExceptionThrownForInvalidType() {
39-
Assert.assertThrows(ValidationException.class, () -> JsonSchema.validate(
40-
booleanJsonSchema,
41-
null,
42-
validationMetadata
43-
));
31+
fun testExceptionThrownForInvalidType() {
32+
assertFailsWith<ValidationException>(
33+
block = {
34+
JsonSchema.validate(
35+
booleanJsonSchema,
36+
null,
37+
validationMetadata
38+
)
39+
}
40+
)
41+
}
42+
43+
companion object {
44+
val configuration = SchemaConfiguration(JsonSchemaKeywordFlags.Builder().build())
45+
val booleanJsonSchema = BooleanJsonSchema1.getInstance()
46+
val validationMetadata = ValidationMetadata(
47+
listOf("args[0"),
48+
configuration,
49+
PathToSchemasMap(),
50+
LinkedHashSet()
51+
)
4452
}
45-
}
53+
}

0 commit comments

Comments
 (0)