Skip to content

Commit 9c7dd52

Browse files
authored
Resolve TODO to refactor Search and Skip test snippets (#105)
# Pull Request Info [PR Reviewing Guidelines](https://github.com/mongodb/docs-java/blob/master/REVIEWING.md) Missed these TODOs on #99 JIRA - no jira Staging - https://docs-mongodbcom-staging.corp.mongodb.com/kotlin/docsworker-xlarge/no-jira-refactor/fundamentals/crud/read-operations/text/ - https://docs-mongodbcom-staging.corp.mongodb.com/kotlin/docsworker-xlarge/no-jira-refactor/fundamentals/crud/read-operations/skip/ ## Self-Review Checklist - [ ] Is this free of any warnings or errors in the RST? - [ ] Did you run a spell-check? - [ ] Did you run a grammar-check? - [ ] Are all the links working?
1 parent 298b164 commit 9c7dd52

9 files changed

+36
-28
lines changed

examples/src/test/kotlin/SearchTextTest.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import org.junit.jupiter.api.BeforeAll
1414
import org.junit.jupiter.api.TestInstance
1515
import 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)
2018
internal 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
}

examples/src/test/kotlin/SkipTest.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import org.junit.jupiter.api.TestInstance
1414
import java.util.*
1515
import 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)
2018
internal class SkipTest {
2119
// :snippet-start: skip-data-model
@@ -94,16 +92,15 @@ internal class SkipTest {
9492
val results = collection.find(filter)
9593
.sort(descending(PaintOrder::qty.name))
9694
.skip(5)
97-
.collect { println(it) }
95+
results.collect { println(it) }
9896
// :snippet-end:
9997
// Junit test for the above code
10098
val expected = listOf(
10199
PaintOrder(4, 6, "white"),
102100
PaintOrder(1, 5, "red"),
103101
PaintOrder(6, 3, "pink")
104102
)
105-
assertEquals(expected, collection.find(filter).sort(descending(PaintOrder::qty.name))
106-
.skip(5).toList() )
103+
assertEquals(expected, results.toList() )
107104
}
108105

109106
@Test
@@ -115,7 +112,8 @@ internal class SkipTest {
115112
Aggregates.sort(descending(PaintOrder::qty.name)),
116113
Aggregates.skip(5)
117114
)
118-
collection.aggregate(aggregate).collect { println(it) }
115+
val findFlow = collection.aggregate(aggregate)
116+
findFlow.collect { println(it) }
119117
// :snippet-end:
120118

121119
// Junit test for the above code
@@ -124,7 +122,7 @@ internal class SkipTest {
124122
PaintOrder(1, 5, "red"),
125123
PaintOrder(6, 3, "pink")
126124
)
127-
assertEquals(expected, collection.aggregate(aggregate).toList())
125+
assertEquals(expected, findFlow.toList())
128126
}
129127

130128
@Test
@@ -136,9 +134,10 @@ internal class SkipTest {
136134
Aggregates.sort(descending(PaintOrder::qty.name)),
137135
Aggregates.skip(9)
138136
)
139-
collection.aggregate(emptyQuery).collect { println(it) }
137+
val findFlow = collection.aggregate(emptyQuery)
138+
findFlow.collect { println(it) }
140139
// :snippet-end:
141140
// Junit test for the above code
142-
assertTrue(collection.aggregate(emptyQuery).toList().isEmpty())
141+
assertTrue(findFlow.toList().isEmpty())
143142
}
144143
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
val filter = Filters.text("furious -fast")
2-
collection.find(filter).collect { println(it) }
2+
val findFlow = collection.find(filter)
3+
findFlow.collect { println(it) }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
val filter = Filters.text("fate 7")
2-
collection.find(filter).collect { println(it) }
2+
val findFlow = collection.find(filter)
3+
findFlow.collect { println(it) }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
val filter = Filters.text("\"fate of the furious\"")
2-
collection.find(filter).collect { println(it) }
2+
val findFlow = collection.find(filter)
3+
findFlow.collect { println(it) }
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
val filter = Filters.text("fast")
2-
collection.find(filter).collect { println(it) }
2+
val findFlow = collection.find(filter)
3+
findFlow.collect { println(it) }

source/examples/generated/SkipTest.snippet.aggregation.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ val aggregate = listOf(
44
Aggregates.sort(descending(PaintOrder::qty.name)),
55
Aggregates.skip(5)
66
)
7-
collection.aggregate(aggregate).collect { println(it) }
7+
val findFlow = collection.aggregate(aggregate)
8+
findFlow.collect { println(it) }

source/examples/generated/SkipTest.snippet.find-iterable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ val filter = Filters.empty()
22
val results = collection.find(filter)
33
.sort(descending(PaintOrder::qty.name))
44
.skip(5)
5-
.collect { println(it) }
5+
results.collect { println(it) }

source/examples/generated/SkipTest.snippet.no-results.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ val emptyQuery = listOf(
44
Aggregates.sort(descending(PaintOrder::qty.name)),
55
Aggregates.skip(9)
66
)
7-
collection.aggregate(emptyQuery).collect { println(it) }
7+
val findFlow = collection.aggregate(emptyQuery)
8+
findFlow.collect { println(it) }

0 commit comments

Comments
 (0)