package Ġuk . gov . just ice . digital . h mp ps . send legal mailto pr is ons api . barcode Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Assertions . assertThat Exception OfType Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . springframework . dao . Data Integr ity Violation Exception Ċ import Ġorg . springframework . dao . Invalid DataAccess Api Usage Exception Ċ import Ġuk . gov . just ice . digital . h mp ps . send legal mailto pr is ons api . IntegrationTest Ċ Ċ class ĠBar code Recipient Repository Test Ġ: ĠIntegration Test () Ġ{ ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` should Ġsave Ġbarcode Ġrecipient `() Ġ{ ĊĠĠĠ Ġval Ġbarcode Ġ= ĠBar code (" 1 2 3 4 5 6 7 8 9 0 1 2 ") ĊĠĠĠ Ġbarcode Repository . save ( barcode ) ĊĊĠĠĠ Ġval Ġbarcode Recipient Ġ= ĠBar code Recipient ( ĊĠĠĠĠĠ Ġbarcode Ġ= Ġbarcode , ĊĠĠĠĠĠ Ġname Ġ= Ġ" F red ĠBlog gs ", ĊĠĠĠĠĠ Ġpr ison Code Ġ= Ġ" BX I ", ĊĠĠĠĠĠ Ġpr ison Number Ġ= Ġ" A 1 2 3 4 BC " ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġbarcode Recipient Repository . save ( barcode Recipient ) ĊĊĠĠĠ ĠassertThat ( barcode Recipient Repository . getBy Barcode ( barcode )) ĊĠĠĠĠĠ Ġ. using Recursive Comparison () ĊĠĠĠĠĠ Ġ. ign oring Fields (" id ") ĊĠĠĠĠĠ Ġ. isEqualTo ( barcode Recipient ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` should Ġnot Ġsave Ġgiven Ġbarcode Ġnot Ġpreviously Ġsaved Ġin Ġdatabase `() Ġ{ ĊĠĠĠ Ġval Ġbarcode Not Present In Database Ġ= ĠBar code (" 1 2 3 4 5 6 7 8 9 0 1 2 ") ĊĊĠĠĠ Ġval Ġbarcode Recipient Ġ= ĠBar code Recipient ( ĊĠĠĠĠĠ Ġbarcode Ġ= Ġbarcode Not Present In Database , ĊĠĠĠĠĠ Ġname Ġ= Ġ" F red ĠBlog gs ", ĊĠĠĠĠĠ Ġpr ison Code Ġ= Ġ" BX I ", ĊĠĠĠĠĠ Ġpr ison Number Ġ= Ġ" A 1 2 3 4 BC " ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat Exception OfType ( Invalid DataAccess Api Usage Exception :: class . java ) ĊĠĠĠĠĠ Ġ. is Thrown By Ġ{ Ġbarcode Recipient Repository . save ( barcode Recipient ) Ġ} ĊĠĠĠĠĠ Ġ. with Message Containing (" save Ġthe Ġtransient Ġinstance Ġbefore Ġflush ing ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` should Ġnot Ġsave Ġa Ġsecond Ġrecipient Ġfor Ġthe Ġsame Ġbarcode `() Ġ{ ĊĠĠĠ Ġval Ġbarcode Ġ= ĠBar code (" 1 2 3 4 5 6 7 8 9 0 1 2 ") ĊĠĠĠ Ġbarcode Repository . save ( barcode ) ĊĠĠĠ Ġbarcode Recipient Repository . save ( ĊĠĠĠĠĠ ĠBar code Recipient ( ĊĠĠĠĠĠĠĠ Ġbarcode Ġ= Ġbarcode , ĊĠĠĠĠĠĠĠ Ġname Ġ= Ġ" F red ĠBlog gs ", ĊĠĠĠĠĠĠĠ Ġpr ison Code Ġ= Ġ" BX I ", ĊĠĠĠĠĠĠĠ Ġpr ison Number Ġ= Ġ" A 1 2 3 4 BC " ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġsecond Barcode Recipient Ġ= ĠBar code Recipient ( ĊĠĠĠĠĠ Ġbarcode Ġ= Ġbarcode , ĊĠĠĠĠĠ Ġname Ġ= Ġ" John ĠSmith ", ĊĠĠĠĠĠ Ġpr ison Code Ġ= Ġ" LE I ", ĊĠĠĠĠĠ Ġpr ison Number Ġ= Ġ" Q 9 8 1 6 HG " ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat Exception OfType ( Data Integr ity Violation Exception :: class . java ) ĊĠĠĠĠĠ Ġ. is Thrown By Ġ{ Ġbarcode Recipient Repository . save ( second Barcode Recipient ) Ġ} ĊĠĠĠĠĠ Ġ. with Message Containing (" constraint Ġ[ barcode _ recipients _ barcode _ unique ]") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` should Ġnot Ġdelete Ġbarcode Ġgiven Ġa Ġrecipient Ġexists `() Ġ{ ĊĠĠĠ Ġval Ġbarcode Ġ= ĠBar code (" 1 2 3 4 5 6 7 8 9 0 1 2 ") ĊĠĠĠ Ġbarcode Repository . save ( barcode ) ĊĠĠĠ Ġbarcode Recipient Repository . save ( ĊĠĠĠĠĠ ĠBar code Recipient ( ĊĠĠĠĠĠĠĠ Ġbarcode Ġ= Ġbarcode , ĊĠĠĠĠĠĠĠ Ġname Ġ= Ġ" F red ĠBlog gs ", ĊĠĠĠĠĠĠĠ Ġpr ison Code Ġ= Ġ" BX I ", ĊĠĠĠĠĠĠĠ Ġpr ison Number Ġ= Ġ" A 1 2 3 4 BC " ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat Exception OfType ( Data Integr ity Violation Exception :: class . java ) ĊĠĠĠĠĠ Ġ. is Thrown By Ġ{ Ġbarcode Repository . delete ( barcode ) Ġ} ĊĠĠĠĠĠ Ġ. with Message Containing (" constraint Ġ[ barcode _ recipients _ barcode _ f key ]") ĊĠ Ġ} Ċ } Ċ