6767 * Unit tests for {@link R2dbcEntityTemplate}.
6868 *
6969 * @author Mark Paluch
70+ * @author Jose Luis Leon
7071 */
7172public class R2dbcEntityTemplateUnitTests {
7273
@@ -245,8 +246,8 @@ void shouldDeleteByQuery() {
245246 @ Test // gh-220
246247 void shouldDeleteEntity () {
247248
248- Person person = new Person ();
249- person . id = "Walter" ;
249+ Person person = Person . empty () //
250+ . withId ( "Walter" ) ;
250251 recorder .addStubbing (s -> s .startsWith ("DELETE" ), Collections .emptyList ());
251252
252253 entityTemplate .delete (person ) //
@@ -390,7 +391,7 @@ void insertShouldInvokeCallback() {
390391 ValueCapturingAfterSaveCallback afterSave = new ValueCapturingAfterSaveCallback ();
391392
392393 entityTemplate .setEntityCallbacks (ReactiveEntityCallbacks .create (beforeConvert , beforeSave , afterSave ));
393- entityTemplate .insert (new Person ()).as (StepVerifier ::create ) //
394+ entityTemplate .insert (Person . empty ()).as (StepVerifier ::create ) //
394395 .assertNext (actual -> {
395396 assertThat (actual .id ).isEqualTo ("after-save" );
396397 assertThat (actual .name ).isEqualTo ("before-convert" );
@@ -439,10 +440,10 @@ void updateShouldInvokeCallback() {
439440 ValueCapturingBeforeSaveCallback beforeSave = new ValueCapturingBeforeSaveCallback ();
440441 ValueCapturingAfterSaveCallback afterSave = new ValueCapturingAfterSaveCallback ();
441442
442- Person person = new Person ();
443- person . id = "the-id" ;
444- person . name = "name" ;
445- person . description = "description" ;
443+ Person person = Person . empty () //
444+ . withId ( "the-id" ) //
445+ . withName ( "name" ) //
446+ . withDescription ( "description" ) ;
446447
447448 entityTemplate .setEntityCallbacks (ReactiveEntityCallbacks .create (beforeConvert , beforeSave , afterSave ));
448449 entityTemplate .update (person ).as (StepVerifier ::create ) //
@@ -460,7 +461,8 @@ void updateShouldInvokeCallback() {
460461 Parameter .from ("before-save" ));
461462 }
462463
463- @ ToString
464+ @ Value
465+ @ With
464466 static class Person {
465467
466468 @ Id String id ;
@@ -469,12 +471,8 @@ static class Person {
469471
470472 String description ;
471473
472- public String getName () {
473- return name ;
474- }
475-
476- public void setName (String name ) {
477- this .name = name ;
474+ public static Person empty () {
475+ return new Person (null , null , null );
478476 }
479477 }
480478
@@ -548,8 +546,8 @@ static class ValueCapturingBeforeConvertCallback extends ValueCapturingEntityCal
548546 public Mono <Person > onBeforeConvert (Person entity , SqlIdentifier table ) {
549547
550548 capture (entity );
551- entity . name = "before-convert" ;
552- return Mono .just (entity );
549+ Person person = entity . withName ( "before-convert" ) ;
550+ return Mono .just (person );
553551 }
554552 }
555553
@@ -573,9 +571,9 @@ public Mono<Person> onAfterSave(Person entity, OutboundRow outboundRow, SqlIdent
573571
574572 capture (entity );
575573
576- Person person = new Person ();
577- person . id = "after-save" ;
578- person . name = entity .name ;
574+ Person person = Person . empty () //
575+ . withId ( "after-save" ) //
576+ . withName ( entity .getName ()) ;
579577
580578 return Mono .just (person );
581579 }
@@ -588,9 +586,9 @@ static class ValueCapturingAfterConvertCallback extends ValueCapturingEntityCall
588586 public Mono <Person > onAfterConvert (Person entity , SqlIdentifier table ) {
589587
590588 capture (entity );
591- Person person = new Person ();
592- person . id = "after-convert" ;
593- person . name = entity .name ;
589+ Person person = Person . empty () //
590+ . withId ( "after-convert" ) //
591+ . withName ( entity .getName ()) ;
594592
595593 return Mono .just (person );
596594 }
0 commit comments