Skip to content

Commit d23cdcf

Browse files
committed
fix test compilation errors
1 parent d036552 commit d23cdcf

File tree

7 files changed

+79
-71
lines changed

7 files changed

+79
-71
lines changed

firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/core/DataConnectGrpcClient.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.firebase.dataconnect.core
1818

1919
import com.google.firebase.dataconnect.*
20-
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment
20+
import com.google.firebase.dataconnect.DataConnectPathSegment
2121
import com.google.firebase.dataconnect.core.DataConnectGrpcClientGlobals.toErrorInfoImpl
2222
import com.google.firebase.dataconnect.core.LoggerGlobals.warn
2323
import com.google.firebase.dataconnect.util.ProtoUtil.decodeFromStruct
@@ -140,15 +140,16 @@ internal object DataConnectGrpcClientGlobals {
140140
private fun ListValue.toPathSegment() =
141141
valuesList.map {
142142
when (it.kindCase) {
143-
Value.KindCase.STRING_VALUE -> PathSegment.Field(it.stringValue)
144-
Value.KindCase.NUMBER_VALUE -> PathSegment.ListIndex(it.numberValue.toInt())
143+
Value.KindCase.STRING_VALUE -> DataConnectPathSegment.Field(it.stringValue)
144+
Value.KindCase.NUMBER_VALUE -> DataConnectPathSegment.ListIndex(it.numberValue.toInt())
145145
// The cases below are expected to never occur; however, implement some logic for them
146146
// to avoid things like throwing exceptions in those cases.
147-
Value.KindCase.NULL_VALUE -> PathSegment.Field("null")
148-
Value.KindCase.BOOL_VALUE -> PathSegment.Field(it.boolValue.toString())
149-
Value.KindCase.LIST_VALUE -> PathSegment.Field(it.listValue.toCompactString())
150-
Value.KindCase.STRUCT_VALUE -> PathSegment.Field(it.structValue.toCompactString())
151-
else -> PathSegment.Field(it.toString())
147+
Value.KindCase.NULL_VALUE -> DataConnectPathSegment.Field("null")
148+
Value.KindCase.BOOL_VALUE -> DataConnectPathSegment.Field(it.boolValue.toString())
149+
Value.KindCase.LIST_VALUE -> DataConnectPathSegment.Field(it.listValue.toCompactString())
150+
Value.KindCase.STRUCT_VALUE ->
151+
DataConnectPathSegment.Field(it.structValue.toCompactString())
152+
else -> DataConnectPathSegment.Field(it.toString())
152153
}
153154
}
154155

firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/core/DataConnectOperationFailureResponseImpl.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package com.google.firebase.dataconnect.core
1818

1919
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse
2020
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo
21-
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment
21+
import com.google.firebase.dataconnect.DataConnectPathSegment
2222
import java.util.Objects
2323
import kotlinx.serialization.json.JsonObject
2424

@@ -44,8 +44,10 @@ internal class DataConnectOperationFailureResponseImpl<Data>(
4444
override fun toString(): String =
4545
"DataConnectOperationFailureResponseImpl(rawData=$rawData, data=$data, errors=$errors)"
4646

47-
internal class ErrorInfoImpl(override val message: String, override val path: List<PathSegment>) :
48-
ErrorInfo {
47+
internal class ErrorInfoImpl(
48+
override val message: String,
49+
override val path: List<DataConnectPathSegment>,
50+
) : ErrorInfo {
4951

5052
override fun equals(other: Any?): Boolean =
5153
other is ErrorInfoImpl && other.message == message && other.path == path
@@ -55,13 +57,13 @@ internal class DataConnectOperationFailureResponseImpl<Data>(
5557
override fun toString(): String = buildString {
5658
path.forEachIndexed { segmentIndex, segment ->
5759
when (segment) {
58-
is PathSegment.Field -> {
60+
is DataConnectPathSegment.Field -> {
5961
if (segmentIndex != 0) {
6062
append('.')
6163
}
6264
append(segment.field)
6365
}
64-
is PathSegment.ListIndex -> {
66+
is DataConnectPathSegment.ListIndex -> {
6567
append('[').append(segment.index).append(']')
6668
}
6769
}
Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package com.google.firebase.dataconnect
2020

21-
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment
2221
import com.google.firebase.dataconnect.testutil.property.arbitrary.DataConnectArb.fieldPathSegment as fieldPathSegmentArb
2322
import com.google.firebase.dataconnect.testutil.property.arbitrary.DataConnectArb.listIndexPathSegment as listIndexPathSegmentArb
2423
import com.google.firebase.dataconnect.testutil.property.arbitrary.dataConnect
@@ -40,43 +39,43 @@ import org.junit.Test
4039
private val propTestConfig =
4140
PropTestConfig(iterations = 20, edgeConfig = EdgeConfig(edgecasesGenerationProbability = 0.25))
4241

43-
/** Unit tests for [PathSegment.Field] */
44-
class DataConnectOperationFailureResponsePathSegmentFieldUnitTest {
42+
/** Unit tests for [DataConnectPathSegment.Field] */
43+
class DataConnectPathSegmentFieldUnitTest {
4544

4645
@Test
4746
fun `constructor should set field property`() = runTest {
4847
checkAll(propTestConfig, Arb.dataConnect.string()) { field ->
49-
val pathSegment = PathSegment.Field(field)
48+
val pathSegment = DataConnectPathSegment.Field(field)
5049
pathSegment.field shouldBeSameInstanceAs field
5150
}
5251
}
5352

5453
@Test
5554
fun `toString() should return a string equal to the field property`() = runTest {
56-
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: PathSegment.Field ->
55+
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: DataConnectPathSegment.Field ->
5756
pathSegment.toString() shouldBeSameInstanceAs pathSegment.field
5857
}
5958
}
6059

6160
@Test
6261
fun `equals() should return true for the exact same instance`() = runTest {
63-
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: PathSegment.Field ->
62+
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: DataConnectPathSegment.Field ->
6463
pathSegment.equals(pathSegment) shouldBe true
6564
}
6665
}
6766

6867
@Test
6968
fun `equals() should return true for an equal instance`() = runTest {
70-
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment1: PathSegment.Field ->
71-
val pathSegment2 = PathSegment.Field(pathSegment1.field)
69+
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment1: DataConnectPathSegment.Field ->
70+
val pathSegment2 = DataConnectPathSegment.Field(pathSegment1.field)
7271
pathSegment1.equals(pathSegment2) shouldBe true
7372
pathSegment2.equals(pathSegment1) shouldBe true
7473
}
7574
}
7675

7776
@Test
7877
fun `equals() should return false for null`() = runTest {
79-
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: PathSegment.Field ->
78+
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: DataConnectPathSegment.Field ->
8079
pathSegment.equals(null) shouldBe false
8180
}
8281
}
@@ -85,7 +84,7 @@ class DataConnectOperationFailureResponsePathSegmentFieldUnitTest {
8584
fun `equals() should return false for a different type`() = runTest {
8685
val otherTypes = Arb.choice(Arb.string(), Arb.int(), listIndexPathSegmentArb())
8786
checkAll(propTestConfig, fieldPathSegmentArb(), otherTypes) {
88-
pathSegment: PathSegment.Field,
87+
pathSegment: DataConnectPathSegment.Field,
8988
other ->
9089
pathSegment.equals(other) shouldBe false
9190
}
@@ -94,8 +93,8 @@ class DataConnectOperationFailureResponsePathSegmentFieldUnitTest {
9493
@Test
9594
fun `equals() should return false when field differs`() = runTest {
9695
checkAll(propTestConfig, fieldPathSegmentArb(), fieldPathSegmentArb()) {
97-
pathSegment1: PathSegment.Field,
98-
pathSegment2: PathSegment.Field ->
96+
pathSegment1: DataConnectPathSegment.Field,
97+
pathSegment2: DataConnectPathSegment.Field ->
9998
assume(pathSegment1.field != pathSegment2.field)
10099
pathSegment1.equals(pathSegment2) shouldBe false
101100
}
@@ -104,7 +103,7 @@ class DataConnectOperationFailureResponsePathSegmentFieldUnitTest {
104103
@Test
105104
fun `hashCode() should return the same value each time it is invoked on a given object`() =
106105
runTest {
107-
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: PathSegment.Field ->
106+
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment: DataConnectPathSegment.Field ->
108107
val hashCode1 = pathSegment.hashCode()
109108
pathSegment.hashCode() shouldBe hashCode1
110109
pathSegment.hashCode() shouldBe hashCode1
@@ -113,60 +112,64 @@ class DataConnectOperationFailureResponsePathSegmentFieldUnitTest {
113112

114113
@Test
115114
fun `hashCode() should return the same value on equal objects`() = runTest {
116-
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment1: PathSegment.Field ->
117-
val pathSegment2 = PathSegment.Field(pathSegment1.field)
115+
checkAll(propTestConfig, fieldPathSegmentArb()) { pathSegment1: DataConnectPathSegment.Field ->
116+
val pathSegment2 = DataConnectPathSegment.Field(pathSegment1.field)
118117
pathSegment1.hashCode() shouldBe pathSegment2.hashCode()
119118
}
120119
}
121120

122121
@Test
123122
fun `hashCode() should return a different value if field is different`() = runTest {
124123
checkAll(propTestConfig, fieldPathSegmentArb(), fieldPathSegmentArb()) {
125-
pathSegment1: PathSegment.Field,
126-
pathSegment2: PathSegment.Field ->
124+
pathSegment1: DataConnectPathSegment.Field,
125+
pathSegment2: DataConnectPathSegment.Field ->
127126
assume(pathSegment1.field.hashCode() != pathSegment2.field.hashCode())
128127
pathSegment1.hashCode() shouldNotBe pathSegment2.hashCode()
129128
}
130129
}
131130
}
132131

133-
/** Unit tests for [PathSegment.ListIndex] */
134-
class DataConnectOperationFailureResponsePathSegmentListIndexUnitTest {
132+
/** Unit tests for [DataConnectPathSegment.ListIndex] */
133+
class DataConnectPathSegmentListIndexUnitTest {
135134

136135
@Test
137136
fun `constructor should set index property`() = runTest {
138137
checkAll(propTestConfig, Arb.int()) { listIndex ->
139-
val pathSegment = PathSegment.ListIndex(listIndex)
138+
val pathSegment = DataConnectPathSegment.ListIndex(listIndex)
140139
pathSegment.index shouldBe listIndex
141140
}
142141
}
143142

144143
@Test
145144
fun `toString() should return a string equal to the index property`() = runTest {
146-
checkAll(propTestConfig, listIndexPathSegmentArb()) { pathSegment: PathSegment.ListIndex ->
145+
checkAll(propTestConfig, listIndexPathSegmentArb()) {
146+
pathSegment: DataConnectPathSegment.ListIndex ->
147147
pathSegment.toString() shouldBe "${pathSegment.index}"
148148
}
149149
}
150150

151151
@Test
152152
fun `equals() should return true for the exact same instance`() = runTest {
153-
checkAll(propTestConfig, listIndexPathSegmentArb()) { pathSegment: PathSegment.ListIndex ->
153+
checkAll(propTestConfig, listIndexPathSegmentArb()) {
154+
pathSegment: DataConnectPathSegment.ListIndex ->
154155
pathSegment.equals(pathSegment) shouldBe true
155156
}
156157
}
157158

158159
@Test
159160
fun `equals() should return true for an equal instance`() = runTest {
160-
checkAll(propTestConfig, listIndexPathSegmentArb()) { pathSegment1: PathSegment.ListIndex ->
161-
val pathSegment2 = PathSegment.ListIndex(pathSegment1.index)
161+
checkAll(propTestConfig, listIndexPathSegmentArb()) {
162+
pathSegment1: DataConnectPathSegment.ListIndex ->
163+
val pathSegment2 = DataConnectPathSegment.ListIndex(pathSegment1.index)
162164
pathSegment1.equals(pathSegment2) shouldBe true
163165
pathSegment2.equals(pathSegment1) shouldBe true
164166
}
165167
}
166168

167169
@Test
168170
fun `equals() should return false for null`() = runTest {
169-
checkAll(propTestConfig, listIndexPathSegmentArb()) { pathSegment: PathSegment.ListIndex ->
171+
checkAll(propTestConfig, listIndexPathSegmentArb()) {
172+
pathSegment: DataConnectPathSegment.ListIndex ->
170173
pathSegment.equals(null) shouldBe false
171174
}
172175
}
@@ -175,7 +178,7 @@ class DataConnectOperationFailureResponsePathSegmentListIndexUnitTest {
175178
fun `equals() should return false for a different type`() = runTest {
176179
val otherTypes = Arb.choice(Arb.string(), Arb.int(), fieldPathSegmentArb())
177180
checkAll(propTestConfig, listIndexPathSegmentArb(), otherTypes) {
178-
pathSegment: PathSegment.ListIndex,
181+
pathSegment: DataConnectPathSegment.ListIndex,
179182
other ->
180183
pathSegment.equals(other) shouldBe false
181184
}
@@ -184,8 +187,8 @@ class DataConnectOperationFailureResponsePathSegmentListIndexUnitTest {
184187
@Test
185188
fun `equals() should return false when field differs`() = runTest {
186189
checkAll(propTestConfig, listIndexPathSegmentArb(), listIndexPathSegmentArb()) {
187-
pathSegment1: PathSegment.ListIndex,
188-
pathSegment2: PathSegment.ListIndex ->
190+
pathSegment1: DataConnectPathSegment.ListIndex,
191+
pathSegment2: DataConnectPathSegment.ListIndex ->
189192
assume(pathSegment1.index != pathSegment2.index)
190193
pathSegment1.equals(pathSegment2) shouldBe false
191194
}
@@ -194,7 +197,8 @@ class DataConnectOperationFailureResponsePathSegmentListIndexUnitTest {
194197
@Test
195198
fun `hashCode() should return the same value each time it is invoked on a given object`() =
196199
runTest {
197-
checkAll(propTestConfig, listIndexPathSegmentArb()) { pathSegment: PathSegment.ListIndex ->
200+
checkAll(propTestConfig, listIndexPathSegmentArb()) {
201+
pathSegment: DataConnectPathSegment.ListIndex ->
198202
val hashCode1 = pathSegment.hashCode()
199203
pathSegment.hashCode() shouldBe hashCode1
200204
pathSegment.hashCode() shouldBe hashCode1
@@ -203,17 +207,18 @@ class DataConnectOperationFailureResponsePathSegmentListIndexUnitTest {
203207

204208
@Test
205209
fun `hashCode() should return the same value on equal objects`() = runTest {
206-
checkAll(propTestConfig, listIndexPathSegmentArb()) { pathSegment1: PathSegment.ListIndex ->
207-
val pathSegment2 = PathSegment.ListIndex(pathSegment1.index)
210+
checkAll(propTestConfig, listIndexPathSegmentArb()) {
211+
pathSegment1: DataConnectPathSegment.ListIndex ->
212+
val pathSegment2 = DataConnectPathSegment.ListIndex(pathSegment1.index)
208213
pathSegment1.hashCode() shouldBe pathSegment2.hashCode()
209214
}
210215
}
211216

212217
@Test
213218
fun `hashCode() should return a different value if index is different`() = runTest {
214219
checkAll(propTestConfig, listIndexPathSegmentArb(), listIndexPathSegmentArb()) {
215-
pathSegment1: PathSegment.ListIndex,
216-
pathSegment2: PathSegment.ListIndex ->
220+
pathSegment1: DataConnectPathSegment.ListIndex,
221+
pathSegment2: DataConnectPathSegment.ListIndex ->
217222
assume(pathSegment1.index.hashCode() != pathSegment2.index.hashCode())
218223
pathSegment1.hashCode() shouldNotBe pathSegment2.hashCode()
219224
}

firebase-dataconnect/src/test/kotlin/com/google/firebase/dataconnect/core/DataConnectGrpcClientUnitTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package com.google.firebase.dataconnect.core
1919

2020
import com.google.firebase.dataconnect.DataConnectOperationException
2121
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo
22-
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment
22+
import com.google.firebase.dataconnect.DataConnectPathSegment
2323
import com.google.firebase.dataconnect.DataConnectUntypedData
2424
import com.google.firebase.dataconnect.FirebaseDataConnect
2525
import com.google.firebase.dataconnect.core.DataConnectGrpcClient.OperationResult
@@ -523,16 +523,16 @@ class DataConnectGrpcClientUnitTest {
523523

524524
fun random(rs: RandomSource): GraphqlErrorInfo {
525525

526-
val dataConnectErrorPath = mutableListOf<PathSegment>()
526+
val dataConnectErrorPath = mutableListOf<DataConnectPathSegment>()
527527
val graphqlErrorPath = ListValue.newBuilder()
528528
repeat(6) {
529529
if (rs.random.nextFloat() < 0.33f) {
530530
val pathComponent = randomInts.next(rs)
531-
dataConnectErrorPath.add(PathSegment.ListIndex(pathComponent))
531+
dataConnectErrorPath.add(DataConnectPathSegment.ListIndex(pathComponent))
532532
graphqlErrorPath.addValues(Value.newBuilder().setNumberValue(pathComponent.toDouble()))
533533
} else {
534534
val pathComponent = randomPathComponents.next(rs)
535-
dataConnectErrorPath.add(PathSegment.Field(pathComponent))
535+
dataConnectErrorPath.add(DataConnectPathSegment.Field(pathComponent))
536536
graphqlErrorPath.addValues(Value.newBuilder().setStringValue(pathComponent))
537537
}
538538
}

firebase-dataconnect/src/test/kotlin/com/google/firebase/dataconnect/core/DataConnectOperationFailureResponseImplUnitTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package com.google.firebase.dataconnect.core
2121

22-
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment
22+
import com.google.firebase.dataconnect.DataConnectPathSegment
2323
import com.google.firebase.dataconnect.core.DataConnectOperationFailureResponseImpl.ErrorInfoImpl
2424
import com.google.firebase.dataconnect.testutil.property.arbitrary.DataConnectArb.errorPath as errorPathArb
2525
import com.google.firebase.dataconnect.testutil.property.arbitrary.DataConnectArb.fieldPathSegment as fieldPathSegmentArb
@@ -283,7 +283,7 @@ class DataConnectOperationFailureResponseImplErrorInfoImplUnitTest {
283283
fun `equals() should return false when path differs`() = runTest {
284284
checkAll(propTestConfig, Arb.dataConnect.operationErrorInfo(), errorPathArb()) {
285285
errorInfo1: ErrorInfoImpl,
286-
otherPath: List<PathSegment> ->
286+
otherPath: List<DataConnectPathSegment> ->
287287
assume(errorInfo1.path != otherPath)
288288
val errorInfo2 = ErrorInfoImpl(errorInfo1.message, otherPath)
289289
errorInfo1.equals(errorInfo2) shouldBe false
@@ -323,7 +323,7 @@ class DataConnectOperationFailureResponseImplErrorInfoImplUnitTest {
323323
fun `hashCode() should return a different value if path is different`() = runTest {
324324
checkAll(propTestConfig, Arb.dataConnect.operationErrorInfo(), errorPathArb()) {
325325
errorInfo1: ErrorInfoImpl,
326-
otherPath: List<PathSegment> ->
326+
otherPath: List<DataConnectPathSegment> ->
327327
assume(errorInfo1.path.hashCode() != otherPath.hashCode())
328328
val errorInfo2 = ErrorInfoImpl(errorInfo1.message, otherPath)
329329
errorInfo1.equals(errorInfo2) shouldBe false
@@ -334,17 +334,17 @@ class DataConnectOperationFailureResponseImplErrorInfoImplUnitTest {
334334
private object MyArb {
335335

336336
fun samplePathSegments(
337-
field: Arb<PathSegment.Field> = fieldPathSegmentArb(),
338-
listIndex: Arb<PathSegment.ListIndex> = listIndexPathSegmentArb(),
337+
field: Arb<DataConnectPathSegment.Field> = fieldPathSegmentArb(),
338+
listIndex: Arb<DataConnectPathSegment.ListIndex> = listIndexPathSegmentArb(),
339339
): Arb<SamplePathSegments> =
340340
Arb.bind(field, field, listIndex, listIndex) { field1, field2, listIndex1, listIndex2 ->
341341
SamplePathSegments(field1, field2, listIndex1, listIndex2)
342342
}
343343

344344
data class SamplePathSegments(
345-
val field1: PathSegment.Field,
346-
val field2: PathSegment.Field,
347-
val listIndex1: PathSegment.ListIndex,
348-
val listIndex2: PathSegment.ListIndex,
345+
val field1: DataConnectPathSegment.Field,
346+
val field2: DataConnectPathSegment.Field,
347+
val listIndex1: DataConnectPathSegment.ListIndex,
348+
val listIndex2: DataConnectPathSegment.ListIndex,
349349
)
350350
}

firebase-dataconnect/src/test/kotlin/com/google/firebase/dataconnect/testutil/property/arbitrary/arbs.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package com.google.firebase.dataconnect.testutil.property.arbitrary
2020

21-
import com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment
21+
import com.google.firebase.dataconnect.DataConnectPathSegment
2222
import com.google.firebase.dataconnect.FirebaseDataConnect.CallerSdkType
2323
import com.google.firebase.dataconnect.OperationRef
2424
import com.google.firebase.dataconnect.core.DataConnectAppCheck
@@ -80,7 +80,7 @@ internal fun DataConnectArb.dataConnectGrpcMetadata(
8080

8181
internal fun DataConnectArb.operationErrorInfo(
8282
message: Arb<String> = string(),
83-
path: Arb<List<PathSegment>> = errorPath(),
83+
path: Arb<List<DataConnectPathSegment>> = errorPath(),
8484
): Arb<ErrorInfoImpl> =
8585
Arb.bind(message, path) { message0, path0 -> ErrorInfoImpl(message0, path0) }
8686

0 commit comments

Comments
 (0)