2929import com .arcadedb .graph .MutableVertex ;
3030import com .arcadedb .query .sql .executor .Result ;
3131import com .arcadedb .query .sql .executor .ResultSet ;
32- import org .assertj .core .api .Assertions ;
3332import org .junit .jupiter .api .Test ;
3433
35- import java .text .*;
36- import java .util .*;
34+ import java .text .SimpleDateFormat ;
35+ import java .util .ArrayList ;
36+ import java .util .Arrays ;
37+ import java .util .Calendar ;
38+ import java .util .Date ;
39+ import java .util .HashMap ;
40+ import java .util .Map ;
3741
3842import static org .assertj .core .api .Assertions .assertThat ;
39- import static org .assertj .core .api .Assertions .fail ;
43+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
4044
4145public class DocumentValidationTest extends TestHelper {
4246
@@ -279,12 +283,8 @@ public void testRequiredValidationEdge() {
279283 database .transaction (() -> {
280284 final MutableVertex v1 = database .newVertex ("V" ).save ();
281285 final MutableVertex v2 = database .newVertex ("V" ).save ();
282- try {
283- v1 .newEdge ("E" , v2 );
284- Assertions .fail ();
285- } catch (ValidationException e ) {
286- // EXPECTED
287- }
286+ assertThatThrownBy (() -> v1 .newEdge ("E" , v2 ))
287+ .isInstanceOf (ValidationException .class );
288288
289289 final MutableEdge e = v1 .newEdge ("E" , v2 , "id" , "12345" );
290290 assertThat (e .getString ("id" )).isEqualTo ("12345" );
@@ -303,26 +303,14 @@ public void testRequiredValidationEdgeSQL() {
303303 database .transaction (() -> {
304304 final MutableVertex v1 = database .newVertex ("V" ).save ();
305305 final MutableVertex v2 = database .newVertex ("V" ).save ();
306- try {
307- database .command ("sql" , "create edge E from ? to ?" , v1 , v2 );
308- Assertions .fail ();
309- } catch (ValidationException e ) {
310- // EXPECTED
311- }
312-
313- try {
314- database .command ("sql" , "create edge E from ? to ? set a = '12345'" , v1 , v2 );
315- Assertions .fail ();
316- } catch (ValidationException e ) {
317- // EXPECTED
318- }
319-
320- try {
321- database .command ("sql" , "create edge E from ? to ? set a = '12345', b = '4444'" , v1 , v2 );
322- Assertions .fail ();
323- } catch (ValidationException e ) {
324- // EXPECTED
325- }
306+ assertThatThrownBy (() -> database .command ("sql" , "create edge E from ? to ?" , v1 , v2 ))
307+ .isInstanceOf (ValidationException .class );
308+
309+ assertThatThrownBy (() -> database .command ("sql" , "create edge E from ? to ? set a = '12345'" , v1 , v2 ))
310+ .isInstanceOf (ValidationException .class );
311+
312+ assertThatThrownBy (() -> database .command ("sql" , "create edge E from ? to ? set a = '12345', b = '4444'" , v1 , v2 ))
313+ .isInstanceOf (ValidationException .class );
326314
327315 final Edge e = database .command ("sql" , "create edge E from ? to ? set a = '12345', b = '4444', c = '2222'" , v1 , v2 )
328316 .nextIfAvailable ().getEdge ().get ();
@@ -348,12 +336,9 @@ public void testValidationNotValidEmbedded() {
348336
349337 final MutableDocument embedded = d .newEmbeddedDocument ("EmbeddedValidation" , "embedded" );
350338 embedded .set ("test" , "test" );
351- try {
352- d .validate ();
353- fail ("Validation doesn't throw exception" );
354- } catch (final ValidationException e ) {
355- assertThat (e .toString ().contains ("int" )).isTrue ();
356- }
339+ assertThatThrownBy (() -> d .validate ())
340+ .isInstanceOf (ValidationException .class )
341+ .hasMessageContaining ("int" );
357342 }
358343
359344 @ Test
@@ -381,12 +366,9 @@ public void testValidationNotValidEmbeddedList() {
381366 final MutableDocument embeddedInList2 = d .newEmbeddedDocument ("EmbeddedValidation" , "embeddedList" );
382367 embeddedInList2 .set ("int" , 30 );
383368
384- try {
385- d .validate ();
386- fail ("Validation doesn't throw exception" );
387- } catch (final ValidationException e ) {
388- assertThat (e .toString ().contains ("long" )).isTrue ();
389- }
369+ assertThatThrownBy (() -> d .validate ())
370+ .isInstanceOf (ValidationException .class )
371+ .hasMessageContaining ("long" );
390372 }
391373
392374 @ Test
@@ -415,12 +397,9 @@ public void testValidationNotValidEmbeddedMap() {
415397 embeddedInMap2 .set ("int" , 30 );
416398 embeddedMap .put ("2" , embeddedInMap2 );
417399
418- try {
419- d .validate ();
420- fail ("Validation doesn't throw exception" );
421- } catch (final ValidationException e ) {
422- assertThat (e .toString ().contains ("long" )).isTrue ();
423- }
400+ assertThatThrownBy (() -> d .validate ())
401+ .isInstanceOf (ValidationException .class )
402+ .hasMessageContaining ("long" );
424403 }
425404
426405 @ Test
@@ -736,19 +715,11 @@ public void testPropertyMetadataAreSavedAndReloadded() {
736715 @ Test
737716 public void testMinMaxNotApplicable () {
738717 final DocumentType clazz = database .getSchema ().getOrCreateDocumentType ("Validation" );
739- try {
740- clazz .createProperty ("invString" , Type .STRING ).setMin ("-1" );
741- fail ("" );
742- } catch (IllegalArgumentException e ) {
743- // EXPECTED
744- }
745-
746- try {
747- clazz .createProperty ("invBinary" , Type .LIST ).setMax ("-1" );
748- fail ("" );
749- } catch (IllegalArgumentException e ) {
750- // EXPECTED
751- }
718+ assertThatThrownBy (() -> clazz .createProperty ("invString" , Type .STRING ).setMin ("-1" ))
719+ .isInstanceOf (IllegalArgumentException .class );
720+
721+ assertThatThrownBy (() -> clazz .createProperty ("invBinary" , Type .LIST ).setMax ("-1" ))
722+ .isInstanceOf (IllegalArgumentException .class );
752723 }
753724
754725 @ Test
@@ -762,31 +733,25 @@ public void testEmbeddedDocumentConversion() {
762733 }
763734
764735 private void checkFieldValue (final Document toCheck , final String field , final Object newValue ) {
765- try {
736+ assertThatThrownBy (() -> {
766737 final MutableDocument newD = database .newDocument (toCheck .getTypeName ()).fromMap (toCheck .toMap ());
767738 newD .set (field , newValue );
768739 newD .validate ();
769- fail ("" );
770- } catch (final ValidationException v ) {
771- }
740+ }).isInstanceOf (ValidationException .class );
772741 }
773742
774743 private void checkRequireField (final MutableDocument toCheck , final String fieldName ) {
775- try {
744+ assertThatThrownBy (() -> {
776745 final MutableDocument newD = database .newDocument (toCheck .getTypeName ()).fromMap (toCheck .toMap ());
777746 newD .remove (fieldName );
778747 newD .validate ();
779- fail ("" );
780- } catch (final ValidationException v ) {
781- }
748+ }).isInstanceOf (ValidationException .class );
782749 }
783750
784751 private void checkReadOnlyField (final MutableDocument toCheck , final String fieldName ) {
785- try {
752+ assertThatThrownBy (() -> {
786753 toCheck .remove (fieldName );
787754 toCheck .validate ();
788- fail ("" );
789- } catch (final ValidationException v ) {
790- }
755+ }).isInstanceOf (ValidationException .class );
791756 }
792757}
0 commit comments