Skip to content

Commit d6f4811

Browse files
author
Oryan M
committed
Update assert statements
1 parent f803d2b commit d6f4811

17 files changed

+159
-136
lines changed

src/test/kotlin/graphql/kickstart/tools/BuiltInIdTest.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ class BuiltInIdTest {
4545
"""
4646
}
4747

48-
assert(data["itemByLongId"] != null)
49-
assert((data["itemByLongId"] as Map<*, *>)["id"] == "1")
48+
assertEquals(data["itemByLongId"], mapOf("id" to "1"))
5049
}
5150

5251
@Test
@@ -61,9 +60,11 @@ class BuiltInIdTest {
6160
"""
6261
}
6362

64-
assert(data["itemsByLongIds"] != null)
65-
assert(((data["itemsByLongIds"] as List<*>).size == 3))
66-
assert(((data["itemsByLongIds"] as List<*>)[0] as Map<*, *>)["id"] == "1")
63+
assertEquals(data["itemsByLongIds"], listOf(
64+
mapOf("id" to "1"),
65+
mapOf("id" to "2"),
66+
mapOf("id" to "3")
67+
))
6768
}
6869

6970
@Test
@@ -78,8 +79,7 @@ class BuiltInIdTest {
7879
"""
7980
}
8081

81-
assert(data["itemByUuidId"] != null)
82-
assert((data["itemByUuidId"] as Map<*, *>)["id"] == "00000000-0000-0000-0000-000000000000")
82+
assertEquals(data["itemByUuidId"], mapOf("id" to "00000000-0000-0000-0000-000000000000"))
8383
}
8484

8585
@Test
@@ -94,9 +94,11 @@ class BuiltInIdTest {
9494
"""
9595
}
9696

97-
assert(data["itemsByUuidIds"] != null)
98-
assert(((data["itemsByUuidIds"] as List<*>).size == 3))
99-
assert(((data["itemsByUuidIds"] as List<*>)[0] as Map<*, *>)["id"] == "00000000-0000-0000-0000-000000000000")
97+
assertEquals(data["itemsByUuidIds"], listOf(
98+
mapOf("id" to "00000000-0000-0000-0000-000000000000"),
99+
mapOf("id" to "11111111-1111-1111-1111-111111111111"),
100+
mapOf("id" to "22222222-2222-2222-2222-222222222222")
101+
))
100102
}
101103

102104
class QueryWithLongItemResolver : GraphQLQueryResolver {

src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import graphql.schema.DataFetchingEnvironment
99
import graphql.schema.GraphQLFieldDefinition
1010
import graphql.schema.idl.SchemaDirectiveWiring
1111
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
12-
import org.junit.Assert
1312
import org.junit.Ignore
1413
import org.junit.Test
15-
import java.util.function.BiFunction
1614

1715
class DirectiveTest {
1816
@Test
@@ -72,7 +70,7 @@ class DirectiveTest {
7270
)
7371
)
7472

75-
Assert.assertEquals(expected, result.getData<Map<String, List<*>>>())
73+
assertEquals(result.getData(), expected)
7674
}
7775

7876
@Test
@@ -140,7 +138,7 @@ class DirectiveTest {
140138
val parentType = environment.fieldsContainer
141139

142140
val originalDataFetcher = environment.codeRegistry.getDataFetcher(parentType, field)
143-
val wrappedDataFetcher = DataFetcherFactories.wrapDataFetcher(originalDataFetcher, BiFunction { env, value ->
141+
val wrappedDataFetcher = DataFetcherFactories.wrapDataFetcher(originalDataFetcher, { _, value ->
144142
(value as? String)?.toUpperCase()
145143
})
146144

src/test/kotlin/graphql/kickstart/tools/EndToEndTest.kt

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class EndToEndTest {
5555
"""
5656
}
5757

58-
assert(data["addItem"] != null)
58+
assertNotNull(data["addItem"])
5959
}
6060

6161
@Test
@@ -93,7 +93,7 @@ class EndToEndTest {
9393
latch.await(3, TimeUnit.SECONDS)
9494

9595
assert(result.errors.isEmpty())
96-
assert(returnedItem?.get("onItemCreated")?.get("id") == 1)
96+
assertEquals(returnedItem?.get("onItemCreated"), mapOf("id" to 1))
9797
}
9898

9999
@Test
@@ -109,7 +109,7 @@ class EndToEndTest {
109109
"""
110110
}
111111

112-
assert(data["itemsByInterface"] != null)
112+
assertNotNull(data["itemsByInterface"])
113113
}
114114

115115
@Test
@@ -131,7 +131,7 @@ class EndToEndTest {
131131
"""
132132
}
133133

134-
assert(data["allItems"] != null)
134+
assertNotNull(data["allItems"])
135135
}
136136

137137
@Test
@@ -154,12 +154,13 @@ class EndToEndTest {
154154
"""
155155
}
156156

157-
val items = data["nestedUnionItems"] as List<Map<String, Int>>
158-
assert(items[0]["itemId"] == 0)
159-
assert(items[1]["itemId"] == 1)
160-
assert(items[2]["otherItemId"] == 0)
161-
assert(items[3]["otherItemId"] == 1)
162-
assert(items[4]["thirdItemId"] == 100)
157+
assertEquals(data["nestedUnionItems"], listOf(
158+
mapOf("itemId" to 0),
159+
mapOf("itemId" to 1),
160+
mapOf("otherItemId" to 0),
161+
mapOf("otherItemId" to 1),
162+
mapOf("thirdItemId" to 100)
163+
))
163164
}
164165

165166
@Test
@@ -174,7 +175,7 @@ class EndToEndTest {
174175
"""
175176
}
176177

177-
assert(data["itemByUUID"] != null)
178+
assertNotNull(data["itemByUUID"])
178179
}
179180

180181
@Test
@@ -187,7 +188,7 @@ class EndToEndTest {
187188
"""
188189
}
189190

190-
assert((data["echoFiles"] as ArrayList<String>).joinToString(",") == "Hello,World")
191+
assertEquals(data["echoFiles"], listOf("Hello", "World"))
191192
}
192193

193194
@Test
@@ -203,7 +204,7 @@ class EndToEndTest {
203204
"""
204205
}
205206

206-
assert(data["propertyHashMapItems"] == listOf(mapOf("name" to "bob", "age" to 55)))
207+
assertEquals(data["propertyHashMapItems"], listOf(mapOf("name" to "bob", "age" to 55)))
207208
}
208209

209210
@Test
@@ -219,7 +220,7 @@ class EndToEndTest {
219220
"""
220221
}
221222

222-
assert(data["propertySortedMapItems"] == listOf(
223+
assertEquals(data["propertySortedMapItems"], listOf(
223224
mapOf("name" to "Arthur", "age" to 76),
224225
mapOf("name" to "Jane", "age" to 28)
225226
))
@@ -245,7 +246,7 @@ class EndToEndTest {
245246
"""
246247
}
247248

248-
assert(data["propertyMapWithComplexItems"] == listOf(mapOf("nameId" to mapOf("id" to 150), "age" to 72)))
249+
assertEquals(data["propertyMapWithComplexItems"], listOf(mapOf("nameId" to mapOf("id" to 150), "age" to 72)))
249250
}
250251

251252
// This behavior is consistent with PropertyDataFetcher
@@ -262,7 +263,7 @@ class EndToEndTest {
262263
"""
263264
}
264265

265-
assert(data["propertyMapMissingNamePropItems"] == listOf(mapOf("name" to null, "age" to 55)))
266+
assertEquals(data["propertyMapMissingNamePropItems"], listOf(mapOf("name" to null, "age" to 55)))
266267
}
267268

268269
// In this test a dictonary entry for the schema type NestedComplexMapItem is defined
@@ -286,7 +287,7 @@ class EndToEndTest {
286287
"""
287288
}
288289

289-
assert(data["propertyMapWithNestedComplexItems"] == listOf(mapOf("nested" to mapOf("item" to mapOf("id" to 63)), "age" to 72)))
290+
assertEquals(data["propertyMapWithNestedComplexItems"], listOf(mapOf("nested" to mapOf("item" to mapOf("id" to 63)), "age" to 72)))
290291
}
291292

292293
@Test
@@ -305,8 +306,8 @@ class EndToEndTest {
305306
"""
306307
}
307308

308-
assert((data["missing"] as List<*>).size > 1)
309-
assert((data["present"] as List<*>).size == 1)
309+
assertEquals(data["missing"], listOf(mapOf("id" to 0), mapOf("id" to 1)))
310+
assertEquals(data["present"], listOf(mapOf("id" to 0)))
310311
}
311312

312313
@Test
@@ -325,8 +326,8 @@ class EndToEndTest {
325326
"""
326327
}
327328

328-
assert((data["missing"] as List<*>).size > 1)
329-
assert((data["present"] as List<*>).size == 1)
329+
assertEquals(data["missing"], listOf(mapOf("id" to 0), mapOf("id" to 1)))
330+
assertEquals(data["present"], listOf(mapOf("id" to 0)))
330331
}
331332

332333
@Test
@@ -345,8 +346,8 @@ class EndToEndTest {
345346
"""
346347
}
347348

348-
assert(data["missing"] == null)
349-
assert(data["present"] != null)
349+
assertNull(data["missing"])
350+
assertNotNull(data["present"])
350351
}
351352

352353
@Test
@@ -381,7 +382,7 @@ class EndToEndTest {
381382
"""
382383
}
383384

384-
assert(data["__type"] != null)
385+
assertNotNull(data["__type"])
385386
}
386387

387388
@Test
@@ -398,8 +399,8 @@ class EndToEndTest {
398399
"""
399400
}
400401

401-
assert((data as Map<*, *>).containsKey("complexNullableType"))
402-
assert(data["complexNullableType"] == null)
402+
assert(data.containsKey("complexNullableType"))
403+
assertNull(data["complexNullableType"])
403404
}
404405

405406
@Test
@@ -412,7 +413,7 @@ class EndToEndTest {
412413
"""
413414
}
414415

415-
assert(data["complexInputType"] != null)
416+
assertNotNull(data["complexInputType"])
416417
}
417418

418419
@Test
@@ -428,9 +429,10 @@ class EndToEndTest {
428429
"""
429430
}
430431

431-
assert(data["extendedType"] != null)
432-
assert((data["extendedType"] as Map<*, *>)["first"] != null)
433-
assert((data["extendedType"] as Map<*, *>)["second"] != null)
432+
assertEquals(data["extendedType"], mapOf(
433+
"first" to "test",
434+
"second" to "test"
435+
))
434436
}
435437

436438
@Test
@@ -443,7 +445,7 @@ class EndToEndTest {
443445
"""
444446
}
445447

446-
assert(data["propertyField"] != null)
448+
assertNotNull(data["propertyField"])
447449
}
448450

449451
@Test
@@ -456,7 +458,7 @@ class EndToEndTest {
456458
"""
457459
}
458460

459-
assert(data["enumInputType"] == "TYPE_2")
461+
assertEquals(data["enumInputType"], "TYPE_2")
460462
}
461463

462464
@Test
@@ -469,7 +471,7 @@ class EndToEndTest {
469471
"""
470472
}
471473

472-
assert(data["customScalarMapInputType"] == mapOf("test" to "me"))
474+
assertEquals(data["customScalarMapInputType"], mapOf("test" to "me"))
473475
}
474476

475477
@Test
@@ -482,7 +484,7 @@ class EndToEndTest {
482484
"""
483485
}
484486

485-
assert(data["saveUser"] == "John/secret")
487+
assertEquals(data["saveUser"], "John/secret")
486488
}
487489

488490
@Test
@@ -497,7 +499,7 @@ class EndToEndTest {
497499
"""
498500
}
499501

500-
assert(data["itemWithGenericProperties"] == mapOf("keys" to listOf("A", "B")))
502+
assertEquals(data["itemWithGenericProperties"], mapOf("keys" to listOf("A", "B")))
501503
}
502504

503505
@Test
@@ -512,7 +514,7 @@ class EndToEndTest {
512514
"""
513515
}
514516

515-
assert(data["itemByBuiltInId"] != null)
517+
assertNotNull(data["itemByBuiltInId"])
516518
}
517519

518520
@Test
@@ -527,7 +529,7 @@ class EndToEndTest {
527529
"""
528530
}
529531

530-
assert((data["dataFetcherResult"] as Map<*, *>)["name"] == "item1")
532+
assertEquals(data["dataFetcherResult"], mapOf("name" to "item1"))
531533
}
532534

533535
@Test
@@ -543,7 +545,7 @@ class EndToEndTest {
543545
"""
544546
}
545547

546-
assert(data["coroutineItems"] == listOf(
548+
assertEquals(data["coroutineItems"], listOf(
547549
mapOf("id" to 0, "name" to "item1"),
548550
mapOf("id" to 1, "name" to "item2")
549551
))
@@ -573,7 +575,7 @@ class EndToEndTest {
573575
val subscriberResult = subscriber.requestNextElement() as ExecutionResultImpl
574576
val subscriberData = subscriberResult.getData() as Map<String, Map<String, Any>>?
575577
assert(result.errors.isEmpty())
576-
assert(subscriberData?.get("onItemCreatedCoroutineChannel")?.get("id") == 1)
578+
assertEquals(subscriberData?.get("onItemCreatedCoroutineChannel"), mapOf("id" to 1))
577579
subscriber.expectCompletion()
578580
}
579581

@@ -601,7 +603,7 @@ class EndToEndTest {
601603
val subscriberResult = subscriber.requestNextElement() as ExecutionResultImpl
602604
val subscriberData = subscriberResult.getData() as Map<String, Map<String, Any>>?
603605
assert(result.errors.isEmpty())
604-
assert(subscriberData?.get("onItemCreatedCoroutineChannelAndSuspendFunction")?.get("id") == 1)
606+
assertEquals(subscriberData?.get("onItemCreatedCoroutineChannelAndSuspendFunction"), mapOf("id" to 1))
605607
subscriber.expectCompletion()
606608
}
607609

@@ -617,7 +619,10 @@ class EndToEndTest {
617619
"""
618620
}
619621

620-
assert((data["arrayItems"] as List<*>).filterIsInstance<Map<*, *>>().map { it["name"] } == listOf("item1", "item2"))
622+
assertEquals(data["arrayItems"], listOf(
623+
mapOf("name" to "item1"),
624+
mapOf("name" to "item2")
625+
))
621626
}
622627

623628
@Test
@@ -630,7 +635,8 @@ class EndToEndTest {
630635
"""
631636
))
632637

633-
assert(result.errors.size == 1)
634-
assert((result.errors[0] as ExceptionWhileDataFetching).exception is IllegalArgumentException)
638+
assertEquals(result.errors.size, 1)
639+
val exceptionWhileDataFetching = result.errors[0] as ExceptionWhileDataFetching
640+
assert(exceptionWhileDataFetching.exception is IllegalArgumentException)
635641
}
636642
}

src/test/kotlin/graphql/kickstart/tools/EnumDefaultValueTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class EnumDefaultValueTest {
4141
"""
4242
}
4343

44-
assert(data["test"] == "createdOn")
44+
assertEquals(data["test"], "createdOn")
4545
}
4646

4747
class MySortSpecifier {

0 commit comments

Comments
 (0)