11package {{{ packageName }}} .schemas;
22
3- import org.checkerframework.checker.nullness.qual.Nullable;
4- import org.junit.Assert;
5- import org.junit.Test;
63import {{{ packageName }}} .configurations.JsonSchemaKeywordFlags;
74import {{{ packageName }}} .configurations.SchemaConfiguration;
85import {{{ packageName }}} .exceptions.ValidationException;
96import {{{ packageName }}} .schemas.validation.FrozenList;
107import {{{ packageName }}} .schemas.validation.FrozenMap;
118
12- import java.time.LocalDate;
13- import java.time.ZoneId;
14- import java.time.ZonedDateTime;
15- import java.util.ArrayList;
16- import java.util.LinkedHashMap;
17-
18-
19- public class AnyTypeSchemaTest {
20- static final AnyTypeJsonSchema.AnyTypeJsonSchema1 schema = AnyTypeJsonSchema.AnyTypeJsonSchema1.getInstance();
21- static final SchemaConfiguration configuration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build());
22-
23- @SuppressWarnings("nullness")
24- private Nothing? assertNull(@Nullable Object object) {
25- Assert.assertNull(object);
26- return null;
27- }
9+ import java.time.LocalDate
10+ import java.time.ZoneId
11+ import java.time.ZonedDateTime
12+ import kotlin.test.Test
13+ import kotlin.test.assertEquals
14+ import kotlin.test.assertFalse
15+ import kotlin.test.assertNull
16+ import kotlin.test.assertTrue
2817
18+ class AnyTypeSchemaTest {
2919 @Test
30- public void testValidateNull() throws ValidationException {
31- Nothing? validatedValue = schema.validate((Nothing?) null, configuration);
32- assertNull(validatedValue);
20+ @Throws(ValidationException::class)
21+ fun testValidateNull() {
22+ val validatedValue: Nothing? = schema.validate(null, configuration)
23+ assertNull(validatedValue)
3324 }
3425
3526 @Test
36- public void testValidateBoolean() throws ValidationException {
37- boolean trueValue = schema.validate(true, configuration);
38- Assert.assertTrue(trueValue);
39-
40- boolean falseValue = schema.validate(false, configuration);
41- Assert. assertFalse(falseValue);
27+ @Throws( ValidationException::class)
28+ fun testValidateBoolean() {
29+ val trueValue = schema.validate(true, configuration)
30+ assertTrue(trueValue)
31+ val falseValue = schema.validate(false, configuration)
32+ assertFalse(falseValue)
4233 }
4334
4435 @Test
45- public void testValidateInteger() throws ValidationException {
46- int validatedValue = schema.validate(1, configuration);
47- Assert.assertEquals(validatedValue, 1);
36+ @Throws(ValidationException::class)
37+ fun testValidateInteger() {
38+ val validatedValue = schema.validate(1, configuration)
39+ assertEquals(validatedValue.toLong(), 1)
4840 }
4941
5042 @Test
51- public void testValidateLong() throws ValidationException {
52- long validatedValue = schema.validate(1L, configuration);
53- Assert.assertEquals(validatedValue, 1L);
43+ @Throws(ValidationException::class)
44+ fun testValidateLong() {
45+ val validatedValue = schema.validate(1L, configuration)
46+ assertEquals(validatedValue, 1L)
5447 }
5548
5649 @Test
57- public void testValidateFloat() throws ValidationException {
58- float validatedValue = schema.validate(3.14f, configuration);
59- Assert.assertEquals(Float.compare(validatedValue, 3.14f), 0);
50+ @Throws(ValidationException::class)
51+ fun testValidateFloat() {
52+ val validatedValue = schema.validate(3.14f, configuration)
53+ assertEquals(validatedValue.compareTo(3.14f).toLong(), 0)
6054 }
6155
6256 @Test
63- public void testValidateDouble() throws ValidationException {
64- double validatedValue = schema.validate(70.6458763d, configuration);
65- Assert.assertEquals(Double.compare(validatedValue, 70.6458763d), 0);
57+ @Throws(ValidationException::class)
58+ fun testValidateDouble() {
59+ val validatedValue = schema.validate(70.6458763, configuration)
60+ assertEquals(validatedValue.compareTo(70.6458763).toLong(), 0)
6661 }
6762
6863 @Test
69- public void testValidateString() throws ValidationException {
70- String validatedValue = schema.validate("a", configuration);
71- Assert.assertEquals(validatedValue, "a");
64+ @Throws(ValidationException::class)
65+ fun testValidateString() {
66+ val validatedValue = schema.validate("a", configuration)
67+ assertEquals(validatedValue, "a")
7268 }
7369
7470 @Test
75- public void testValidateZonedDateTime() throws ValidationException {
76- String validatedValue = schema.validate(ZonedDateTime.of(2017, 7, 21, 17, 32, 28, 0, ZoneId.of("Z")), configuration);
77- Assert.assertEquals(validatedValue, "2017-07-21T17:32:28Z");
71+ @Throws(ValidationException::class)
72+ fun testValidateZonedDateTime() {
73+ val validatedValue =
74+ schema.validate(ZonedDateTime.of(2017, 7, 21, 17, 32, 28, 0, ZoneId.of("Z")), configuration)
75+ assertEquals(validatedValue, "2017-07-21T17:32:28Z")
7876 }
7977
8078 @Test
81- public void testValidateLocalDate() throws ValidationException {
82- String validatedValue = schema.validate(LocalDate.of(2017, 7, 21), configuration);
83- Assert.assertEquals(validatedValue, "2017-07-21");
79+ @Throws(ValidationException::class)
80+ fun testValidateLocalDate() {
81+ val validatedValue = schema.validate(LocalDate.of(2017, 7, 21), configuration)
82+ assertEquals(validatedValue, "2017-07-21")
8483 }
8584
8685 @Test
87- public void testValidateMap() throws ValidationException {
88- LinkedHashMap<String , Object> inMap = new LinkedHashMap<> ();
89- inMap.put("today", LocalDate.of(2017, 7, 21));
90- FrozenMap< ?> validatedValue = schema.validate(inMap, configuration);
91- LinkedHashMap<String , Object> outMap = new LinkedHashMap<> ();
92- outMap.put("today", "2017-07-21");
93- Assert.assertEquals(validatedValue, outMap);
86+ @Throws(ValidationException::class)
87+ fun testValidateMap() {
88+ val inMap = mapOf(
89+ "today" to LocalDate.of(2017, 7, 21)
90+ )
91+ val validatedValue: FrozenMap< *> = schema.validate(inMap, configuration)
92+ val outMap: Map<String , Any?> = mapOf(
93+ "today" to "2017-07-21"
94+ )
95+ assertEquals(validatedValue, outMap)
9496 }
9597
9698 @Test
97- public void testValidateList() throws ValidationException {
98- ArrayList<Object > inList = new ArrayList<> ();
99- inList.add(LocalDate.of(2017, 7, 21));
100- FrozenList< ?> validatedValue = schema.validate(inList, configuration);
101- ArrayList<Object > outList = new ArrayList<> ();
102- outList.add( "2017-07-21");
103- Assert.assertEquals(validatedValue, outList);
99+ @Throws(ValidationException::class)
100+ fun testValidateList() {
101+ val inList = listOf(
102+ LocalDate.of(2017, 7, 21)
103+ )
104+ val validatedValue: FrozenList< *> = schema.validate(inList, configuration)
105+ val outList: List<Any ?> = listOf("2017-07-21")
106+ assertEquals(validatedValue, outList)
104107 }
105- }
106108
109+ companion object {
110+ val schema = AnyTypeJsonSchema.AnyTypeJsonSchema1.getInstance()
111+ val configuration = SchemaConfiguration(JsonSchemaKeywordFlags.Builder().build())
112+ }
113+ }
0 commit comments