@@ -12,8 +12,6 @@ import org.junit.jupiter.api.TestInstance
1212import java.util.*
1313import kotlin.test.*
1414
15- // TODO: light refactor on these examples so that they don't collect directly from find() op, but rather assign to val findFlow
16- // and then collect/println from that for consistency with other examples
1715@TestInstance(TestInstance .Lifecycle .PER_CLASS )
1816internal class QueryDocumentTest {
1917 // :snippet-start: query-data-model
@@ -67,22 +65,24 @@ internal class QueryDocumentTest {
6765 fun comparisonQueryTest () = runBlocking {
6866 // :snippet-start: comparison-filter
6967 val filter = Filters .gt(" qty" , 7 )
70- collection.find(filter).collect { println (it) }
68+ val findFlow = collection.find(filter)
69+ findFlow.collect { println (it) }
7170 // :snippet-end:
7271 // Junit test for the above code
7372 val expected = listOf (
7473 PaintOrder (1 , 9 , " red" , listOf (" A" , " E" )),
7574 PaintOrder (2 , 8 , " purple" , listOf (" B" , " D" , " F" ), 5 ),
7675 PaintOrder (7 , 8 , " green" , listOf (" C" , " E" ), 7 )
7776 )
78- assertEquals(expected, collection.find(filter) .toList() )
77+ assertEquals(expected, findFlow .toList() )
7978 }
8079
8180 @Test
8281 fun logicalQueryTest () = runBlocking {
8382 // :snippet-start: logical-filter
8483 val filter = Filters .and (Filters .lte(" qty" , 5 ), Filters .ne(" color" , " pink" ))
85- collection.find(filter).collect { println (it) }
84+ val findFlow = collection.find(filter)
85+ findFlow.collect { println (it) }
8686 // :snippet-end:
8787 // Junit test for the above code
8888 val expected = listOf (
@@ -96,42 +96,45 @@ internal class QueryDocumentTest {
9696 fun arrayQueryTest () = runBlocking {
9797 // :snippet-start: array-filter
9898 val filter = Filters .size(" vendor" , 3 )
99- collection.find(filter).collect { println (it) }
99+ val findFlow = collection.find(filter)
100+ findFlow.collect { println (it) }
100101 // :snippet-end:
101102 // Junit test for the above code
102103 val expected = listOf (
103104 PaintOrder (2 , 8 , " purple" , listOf (" B" , " D" , " F" ), 5 ),
104105 PaintOrder (8 , 7 , " black" , listOf (" A" , " C" , " D" ))
105106 )
106- assertEquals(expected, collection.find(filter) .toList() )
107+ assertEquals(expected, findFlow .toList() )
107108 }
108109
109110 @Test
110111 fun elementQueryTest () = runBlocking {
111112 // :snippet-start: element-filter
112113 val filter = Filters .exists(" rating" )
113- collection.find(filter).collect { println (it) }
114+ val findFlow = collection.find(filter)
115+ findFlow.collect { println (it) }
114116 // :snippet-end:
115117 // Junit test for the above code
116118 val expected = listOf (
117119 PaintOrder (2 , 8 , " purple" , listOf (" B" , " D" , " F" ), 5 ),
118120 PaintOrder (4 , 6 , " white" , listOf (" D" ), 9 ),
119121 PaintOrder (7 , 8 , " green" , listOf (" C" , " E" ), 7 )
120122 )
121- assertEquals(expected, collection.find(filter) .toList() )
123+ assertEquals(expected, findFlow .toList() )
122124 }
123125
124126 @Test
125127 fun evaluationQueryTest () = runBlocking {
126128 // :snippet-start: evaluation-filter
127129 val filter = Filters .regex(" color" , " k$" )
128- collection.find(filter).collect { println (it) }
130+ val findFlow = collection.find(filter)
131+ findFlow.collect { println (it) }
129132 // :snippet-end:
130133 // Junit test for the above code
131134 val expected = listOf (
132135 PaintOrder (6 , 3 , " pink" , listOf (" C" )),
133136 PaintOrder (8 , 7 , " black" , listOf (" A" , " C" , " D" ))
134137 )
135- assertEquals(expected, collection.find(filter) .toList() )
138+ assertEquals(expected, findFlow .toList() )
136139 }
137140}
0 commit comments