@@ -14,8 +14,6 @@ import org.junit.jupiter.api.BeforeAll
14
14
import org.junit.jupiter.api.TestInstance
15
15
import kotlin.test.*
16
16
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
19
17
@TestInstance(TestInstance .Lifecycle .PER_CLASS )
20
18
internal class SearchTextTest {
21
19
// :snippet-start: search-data-model
@@ -64,13 +62,14 @@ internal class SearchTextTest {
64
62
// :snippet-end:
65
63
// Junit test for the above code
66
64
val testFilter = Filters .text(" Furious" )
67
- collection.find(testFilter).collect { println (it) }
65
+ val findFlow = collection.find(testFilter)
66
+ findFlow.collect { println (it) }
68
67
val expected = listOf (
69
68
Movies (1 , " 2 Fast 2 Furious" , listOf (" undercover" , " drug dealer" )),
70
69
Movies (3 , " Furious 7" , listOf (" emotional" )),
71
70
Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
72
71
)
73
- assertEquals(expected, collection.find(testFilter) .sort(ascending(" _id" )).toList() )
72
+ assertEquals(expected, findFlow .sort(ascending(" _id" )).toList() )
74
73
}
75
74
76
75
@Test
@@ -89,57 +88,61 @@ internal class SearchTextTest {
89
88
collection.createIndex(Indexes .text(" title" ))
90
89
// :snippet-start: search-term
91
90
val filter = Filters .text(" fast" )
92
- collection.find(filter).collect { println (it) }
91
+ val findFlow = collection.find(filter)
92
+ findFlow.collect { println (it) }
93
93
// :snippet-end:
94
94
// Junit test for the above code
95
95
val expected = listOf (
96
96
Movies (1 , " 2 Fast 2 Furious" , listOf (" undercover" , " drug dealer" )),
97
97
Movies (2 , " Fast 5" , listOf (" bank robbery" , " full team" ))
98
98
)
99
- assertEquals(expected, collection.find(filter) .sort(ascending(" _id" )).toList() )
99
+ assertEquals(expected, findFlow .sort(ascending(" _id" )).toList() )
100
100
}
101
101
102
102
@Test
103
103
fun searchMultipleTermsTest () = runBlocking {
104
104
collection.createIndex(Indexes .text(" title" ))
105
105
// :snippet-start: search-multiple-terms
106
106
val filter = Filters .text(" fate 7" )
107
- collection.find(filter).collect { println (it) }
107
+ val findFlow = collection.find(filter)
108
+ findFlow.collect { println (it) }
108
109
// :snippet-end:
109
110
// Junit test for the above code
110
111
val expected = listOf (
111
112
Movies (3 , " Furious 7" , listOf (" emotional" )),
112
113
Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
113
114
)
114
- assertEquals(expected, collection.find(filter) .toList() )
115
+ assertEquals(expected, findFlow .toList() )
115
116
}
116
117
117
118
@Test
118
119
fun searchPhraseTest () = runBlocking {
119
120
collection.createIndex(Indexes .text(" title" ))
120
121
// :snippet-start: search-phrase
121
122
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) }
123
125
// :snippet-end:
124
126
// Junit test for the above code
125
127
val expected = listOf (
126
128
Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
127
129
)
128
- assertEquals(expected, collection.find(filter) .toList() )
130
+ assertEquals(expected, findFlow .toList() )
129
131
}
130
132
131
133
@Test
132
134
fun excludeTermTest () = runBlocking {
133
135
collection.createIndex(Indexes .text(" title" ))
134
136
// :snippet-start: exclude-term
135
137
val filter = Filters .text(" furious -fast" )
136
- collection.find(filter).collect { println (it) }
138
+ val findFlow = collection.find(filter)
139
+ findFlow.collect { println (it) }
137
140
// :snippet-end:
138
141
// Junit test for the above code
139
142
val expected = listOf (
140
143
Movies (3 , " Furious 7" , listOf (" emotional" )),
141
144
Movies (4 , " The Fate of the Furious" , listOf (" betrayal" ))
142
145
)
143
- assertEquals(expected, collection.find(filter) .sort(ascending(" _id" )).toList() )
146
+ assertEquals(expected, findFlow .sort(ascending(" _id" )).toList() )
144
147
}
145
148
}
0 commit comments