11package tech .ydb .table .result .impl ;
22
3+ import java .util .Arrays ;
34import java .util .NoSuchElementException ;
45
56import com .google .protobuf .NullValue ;
@@ -65,7 +66,7 @@ public void parseNotNullValue() {
6566 .hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
6667 .hasValuePb (pbValue );
6768 checkCastException ("optional is not primitive" , () -> { optional .asData (); })
68- .hasInMessage ("OptionalValue cannot be cast" );
69+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
6970
7071 ValueReader valueReader = optionalReader .getOptionalItem ();
7172 check ("value reader" , valueReader ).isNotNull ()
@@ -81,7 +82,7 @@ public void parseNotNullValue() {
8182 .hasValuePb (pbValue )
8283 .hasTextValue (NOT_NULL );
8384 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 " );
8586
8687 Assert .assertEquals ("optional item equals value" , value , optional .asOptional ().get ());
8788 }
@@ -113,7 +114,7 @@ public void parseNullValue() {
113114 .hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
114115 .hasValuePb (pbValue );
115116 checkCastException ("optional is not primitive" , () -> { optional .asData (); })
116- .hasInMessage ("OptionalValue cannot be cast" );
117+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
117118 checkNoSuchElementException ("optional has not value" , () -> { optional .asOptional ().get (); })
118119 .hasInMessage ("No value present" );
119120
@@ -149,7 +150,7 @@ public void parseDoubleNullValue() {
149150 .hasType (Type .Kind .OPTIONAL , DOUBLE_TYPE )
150151 .hasValuePb (pbValue );
151152 checkCastException ("optional is not primitive" , () -> { optional .asData (); })
152- .hasInMessage ("OptionalValue cannot be cast" );
153+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
153154 checkNoSuchElementException ("optional has not value" , () -> { optional .asOptional ().get (); })
154155 .hasInMessage ("No value present" );
155156
@@ -189,7 +190,7 @@ public void parseDoubleInnerNullValue() {
189190 .hasType (Type .Kind .OPTIONAL , DOUBLE_TYPE )
190191 .hasValuePb (pbValue );
191192 checkCastException ("optional is not primitive" , () -> { optional .asData (); })
192- .hasInMessage ("OptionalValue cannot be cast" );
193+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
193194
194195 ValueReader innerOptionalReader = optionalReader .getOptionalItem ();
195196 check ("inner optinal reader" , innerOptionalReader ).isNotNull ()
@@ -204,7 +205,7 @@ public void parseDoubleInnerNullValue() {
204205 .hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
205206 .hasValuePb (innerPbValue );
206207 checkCastException ("inner optional is not primitive" , () -> { innerOptional .asData (); })
207- .hasInMessage ("OptionalValue cannot be cast" );
208+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
208209 checkNoSuchElementException ("inner optional has not value" , () -> { innerOptional .asOptional ().get (); })
209210 .hasInMessage ("No value present" );
210211
@@ -244,7 +245,7 @@ public void parseDoubleNotNullValue() {
244245 .hasType (Type .Kind .OPTIONAL , DOUBLE_TYPE )
245246 .hasValuePb (pbValue );
246247 checkCastException ("optional is not primitive" , () -> { optional .asData (); })
247- .hasInMessage ("OptionalValue cannot be cast" );
248+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
248249
249250 ValueReader innerOptionalReader = optionalReader .getOptionalItem ();
250251 check ("inner optinal reader" , innerOptionalReader ).isNotNull ()
@@ -259,7 +260,7 @@ public void parseDoubleNotNullValue() {
259260 .hasType (Type .Kind .OPTIONAL , OPTIONAL_TYPE )
260261 .hasValuePb (innerPbValue );
261262 checkCastException ("optional is not primitive" , () -> { optional .asData (); })
262- .hasInMessage ("OptionalValue cannot be cast" );
263+ .hasOneOfMessage ("OptionalValue cannot be cast" , "OptionalValue incompatible with " );
263264
264265 ValueReader valueReader = innerOptionalReader .getOptionalItem ();
265266 check ("inner value reader" , valueReader ).isNotNull ()
@@ -275,7 +276,7 @@ public void parseDoubleNotNullValue() {
275276 .hasValuePb (innerPbValue )
276277 .hasTextValue (NOT_NULL );
277278 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 " );
279280
280281 Assert .assertEquals ("inner optional item equals inner value" , value , innerOptional .asOptional ().get ());
281282 }
@@ -415,5 +416,18 @@ private void hasInMessage(String part) {
415416 String info = "cast exception message '" + message + "' hasn't '" + part + "'" ;
416417 Assert .assertTrue (info , message .contains (part ));
417418 }
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+ }
418432 }
419433}
0 commit comments