@@ -14,8 +14,6 @@ import org.junit.jupiter.api.BeforeAll
1414import org.junit.jupiter.api.TestInstance
1515import kotlin.test.*
1616
17- // TODO: light refactor on these examples so that they don't collect directly from find() op, but rather assign to val findFlow
18- // and then collect/println from that for consistency with other examples
1917@TestInstance(TestInstance .Lifecycle .PER_CLASS )
2018internal class SearchTextTest {
2119 // :snippet-start: search-data-model
@@ -64,13 +62,14 @@ internal class SearchTextTest {
6462 // :snippet-end:
6563 // Junit test for the above code
6664 val testFilter = Filters .text(" Furious" )
67- collection.find(testFilter).collect { println (it) }
65+ val findFlow = collection.find(testFilter)
66+ findFlow.collect { println (it) }
6867 val expected = listOf (
6968 Movies (1 , " 2 Fast 2 Furious" , listOf (" undercover" , " drug dealer" )),
7069 Movies (3 , " Furious 7" , listOf (" emotional" )),
7170 Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
7271 )
73- assertEquals(expected, collection.find(testFilter) .sort(ascending(" _id" )).toList() )
72+ assertEquals(expected, findFlow .sort(ascending(" _id" )).toList() )
7473 }
7574
7675 @Test
@@ -89,57 +88,61 @@ internal class SearchTextTest {
8988 collection.createIndex(Indexes .text(" title" ))
9089 // :snippet-start: search-term
9190 val filter = Filters .text(" fast" )
92- collection.find(filter).collect { println (it) }
91+ val findFlow = collection.find(filter)
92+ findFlow.collect { println (it) }
9393 // :snippet-end:
9494 // Junit test for the above code
9595 val expected = listOf (
9696 Movies (1 , " 2 Fast 2 Furious" , listOf (" undercover" , " drug dealer" )),
9797 Movies (2 , " Fast 5" , listOf (" bank robbery" , " full team" ))
9898 )
99- assertEquals(expected, collection.find(filter) .sort(ascending(" _id" )).toList() )
99+ assertEquals(expected, findFlow .sort(ascending(" _id" )).toList() )
100100 }
101101
102102 @Test
103103 fun searchMultipleTermsTest () = runBlocking {
104104 collection.createIndex(Indexes .text(" title" ))
105105 // :snippet-start: search-multiple-terms
106106 val filter = Filters .text(" fate 7" )
107- collection.find(filter).collect { println (it) }
107+ val findFlow = collection.find(filter)
108+ findFlow.collect { println (it) }
108109 // :snippet-end:
109110 // Junit test for the above code
110111 val expected = listOf (
111112 Movies (3 , " Furious 7" , listOf (" emotional" )),
112113 Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
113114 )
114- assertEquals(expected, collection.find(filter) .toList() )
115+ assertEquals(expected, findFlow .toList() )
115116 }
116117
117118 @Test
118119 fun searchPhraseTest () = runBlocking {
119120 collection.createIndex(Indexes .text(" title" ))
120121 // :snippet-start: search-phrase
121122 val filter = Filters .text(" \" fate of the furious\" " )
122- collection.find(filter).collect { println (it) }
123+ val findFlow = collection.find(filter)
124+ findFlow.collect { println (it) }
123125 // :snippet-end:
124126 // Junit test for the above code
125127 val expected = listOf (
126128 Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
127129 )
128- assertEquals(expected, collection.find(filter) .toList() )
130+ assertEquals(expected, findFlow .toList() )
129131 }
130132
131133 @Test
132134 fun excludeTermTest () = runBlocking {
133135 collection.createIndex(Indexes .text(" title" ))
134136 // :snippet-start: exclude-term
135137 val filter = Filters .text(" furious -fast" )
136- collection.find(filter).collect { println (it) }
138+ val findFlow = collection.find(filter)
139+ findFlow.collect { println (it) }
137140 // :snippet-end:
138141 // Junit test for the above code
139142 val expected = listOf (
140143 Movies (3 , " Furious 7" , listOf (" emotional" )),
141144 Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
142145 )
143- assertEquals(expected, collection.find(filter) .sort(ascending(" _id" )).toList() )
146+ assertEquals(expected, findFlow .sort(ascending(" _id" )).toList() )
144147 }
145148}
0 commit comments