1
1
package tech .ydb .table .result .impl ;
2
2
3
+ import java .util .Arrays ;
3
4
import java .util .NoSuchElementException ;
4
5
5
6
import com .google .protobuf .NullValue ;
@@ -65,7 +66,7 @@ public void parseNotNullValue() {
65
66
.hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
66
67
.hasValuePb (pbValue );
67
68
checkCastException ("optional is not primitive" , () -> { optional .asData (); })
68
- .hasInMessage ("OptionalValue cannot be cast" );
69
+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
69
70
70
71
ValueReader valueReader = optionalReader .getOptionalItem ();
71
72
check ("value reader" , valueReader ).isNotNull ()
@@ -81,7 +82,7 @@ public void parseNotNullValue() {
81
82
.hasValuePb (pbValue )
82
83
.hasTextValue (NOT_NULL );
83
84
checkCastException ("value is not optinal" , () -> { value .asOptional (); })
84
- .hasInMessage ("PrimitiveValue$Text cannot be cast " );
85
+ .hasOneOfMessage ("PrimitiveValue$Text cannot be cast " , "PrimitiveValue$Text incompatible with " );
85
86
86
87
Assert .assertEquals ("optional item equals value" , value , optional .asOptional ().get ());
87
88
}
@@ -113,7 +114,7 @@ public void parseNullValue() {
113
114
.hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
114
115
.hasValuePb (pbValue );
115
116
checkCastException ("optional is not primitive" , () -> { optional .asData (); })
116
- .hasInMessage ("OptionalValue cannot be cast" );
117
+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
117
118
checkNoSuchElementException ("optional has not value" , () -> { optional .asOptional ().get (); })
118
119
.hasInMessage ("No value present" );
119
120
@@ -149,7 +150,7 @@ public void parseDoubleNullValue() {
149
150
.hasType (Type .Kind .OPTIONAL , DOUBLE_TYPE )
150
151
.hasValuePb (pbValue );
151
152
checkCastException ("optional is not primitive" , () -> { optional .asData (); })
152
- .hasInMessage ("OptionalValue cannot be cast" );
153
+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
153
154
checkNoSuchElementException ("optional has not value" , () -> { optional .asOptional ().get (); })
154
155
.hasInMessage ("No value present" );
155
156
@@ -189,7 +190,7 @@ public void parseDoubleInnerNullValue() {
189
190
.hasType (Type .Kind .OPTIONAL , DOUBLE_TYPE )
190
191
.hasValuePb (pbValue );
191
192
checkCastException ("optional is not primitive" , () -> { optional .asData (); })
192
- .hasInMessage ("OptionalValue cannot be cast" );
193
+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
193
194
194
195
ValueReader innerOptionalReader = optionalReader .getOptionalItem ();
195
196
check ("inner optinal reader" , innerOptionalReader ).isNotNull ()
@@ -204,7 +205,7 @@ public void parseDoubleInnerNullValue() {
204
205
.hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
205
206
.hasValuePb (innerPbValue );
206
207
checkCastException ("inner optional is not primitive" , () -> { innerOptional .asData (); })
207
- .hasInMessage ("OptionalValue cannot be cast" );
208
+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
208
209
checkNoSuchElementException ("inner optional has not value" , () -> { innerOptional .asOptional ().get (); })
209
210
.hasInMessage ("No value present" );
210
211
@@ -244,7 +245,7 @@ public void parseDoubleNotNullValue() {
244
245
.hasType (Type .Kind .OPTIONAL , DOUBLE_TYPE )
245
246
.hasValuePb (pbValue );
246
247
checkCastException ("optional is not primitive" , () -> { optional .asData (); })
247
- .hasInMessage ("OptionalValue cannot be cast" );
248
+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
248
249
249
250
ValueReader innerOptionalReader = optionalReader .getOptionalItem ();
250
251
check ("inner optinal reader" , innerOptionalReader ).isNotNull ()
@@ -259,7 +260,7 @@ public void parseDoubleNotNullValue() {
259
260
.hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
260
261
.hasValuePb (innerPbValue );
261
262
checkCastException ("optional is not primitive" , () -> { optional .asData (); })
262
- .hasInMessage ("OptionalValue cannot be cast" );
263
+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
263
264
264
265
ValueReader valueReader = innerOptionalReader .getOptionalItem ();
265
266
check ("inner value reader" , valueReader ).isNotNull ()
@@ -275,7 +276,7 @@ public void parseDoubleNotNullValue() {
275
276
.hasValuePb (innerPbValue )
276
277
.hasTextValue (NOT_NULL );
277
278
checkCastException ("inner value is not optinal" , () -> { value .asOptional (); })
278
- .hasInMessage ("PrimitiveValue$Text cannot be cast " );
279
+ .hasOneOfMessage ("PrimitiveValue$Text cannot be cast " , "PrimitiveValue$Text incompatible with " );
279
280
280
281
Assert .assertEquals ("inner optional item equals inner value" , value , innerOptional .asOptional ().get ());
281
282
}
@@ -415,5 +416,18 @@ private void hasInMessage(String part) {
415
416
String info = "cast exception message '" + message + "' hasn't '" + part + "'" ;
416
417
Assert .assertTrue (info , message .contains (part ));
417
418
}
419
+
420
+ private void hasOneOfMessage (String ... parts ) {
421
+ String message = exception .getMessage ();
422
+
423
+ for (String part : parts ) {
424
+ if (message .contains (part )) {
425
+ return ;
426
+ }
427
+ }
428
+
429
+ String info = "cast exception message '" + message + "' hasn't any of'" + Arrays .toString (parts ) + "'" ;
430
+ Assert .fail (info );
431
+ }
418
432
}
419
433
}
0 commit comments