package Ġuk . gov . just ice . digital . h mp ps . send legal mailto pr is ons api . magic link Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . mockito . kotlin . check Ċ import Ġorg . mockito . kotlin . given Ċ import Ġorg . mockito . kotlin . mock Ċ import Ġorg . mockito . kotlin . verify Ċ import Ġorg . springframework . mail . jav am ail . Java Mail Sender Ċ import Ġjava . time . Duration Ċ import Ġjava . time . temporal . Ch rono Unit Ċ import Ġjavax . mail . Session Ċ import Ġjavax . mail . internet . Mime Message Ċ import Ġjavax . mail . internet . Mime Multipart Ċ Ċ class ĠMagic Link Email Sender Test Ġ{ ĊĊĠ Ġprivate Ġval Ġmock Mail Sender : ĠJava Mail Sender Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġmagic Link Email Sender Ġ= ĠMagic Link Email Sender ( Magic Link Config ( Duration . of ( 1 0 , ĠCh rono Unit . MIN UTES ), Ġ" some - url "), Ġmock Mail Sender ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` The Ġmail Ġshould Ġbe Ġsent Ġto Ġthe Ġuser Ġwith Ġa Ġmagic Ġlink `() Ġ{ ĊĠĠĠ Ġval Ġsession : ĠSession ? Ġ= Ġnull ĊĠĠĠ Ġval Ġmime Message Ġ= ĠMime Message ( session ) ĊĠĠĠ Ġgiven ( mock Mail Sender . create Mime Message ()). willReturn ( mime Message ) ĊĊĠĠĠ Ġmagic Link Email Sender . send (" an . email @ company . com ", Ġ" this - is - a - secret ") ĊĊĠĠĠ Ġverify ( mock Mail Sender ). send ( ĊĠĠĠĠĠ Ġcheck < Mime Message > Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( it . subject ). isEqualTo (" Sign Ġin Ġto ĠSend Ġlegal Ġmail Ġto Ġpr is ons ") ĊĠĠĠĠĠĠĠ ĠassertThat ( it . all Recipients . map Ġ{ Ġrecipient Ġ-> Ġrecipient . toString () Ġ}). isEqualTo ( listOf (" an . email @ company . com ")) ĊĊĠĠĠĠĠĠĠ Ġval Ġbody Part Contents Ġ= Ġ( it . content Ġas ĠMime Multipart ). getBody Part Contents () ĊĠĠĠĠĠĠĠ ĠassertThat ( body Part Contents [" text / plain "]). contains (" 1 0 Ġminutes ") ĊĠĠĠĠĠĠĠ ĠassertThat ( body Part Contents [" text / plain "]). contains (" some - url ? secret = this - is - a - secret ") ĊĠĠĠĠĠĠĠ ĠassertThat ( body Part Contents [" text / html "]). contains (" 1 0 Ġminutes ") ĊĠĠĠĠĠĠĠ ĠassertThat ( body Part Contents [" text / html "]). contains ("< a Ġhref =\" some - url ? secret = this - is - a - secret \" ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠMime Multipart . getBody Part Contents (): ĠMap < String , ĠString > Ġ{ ĊĠĠĠ Ġval Ġbody Part Contents : ĠMutable Map < String , ĠString > Ġ= Ġmutable Map Of () ĊĠĠĠ Ġfor Ġ( idx Ġin Ġ 0 Ġuntil Ġthis . count ) Ġ{ ĊĠĠĠĠĠ Ġval Ġbody Part Ġ= Ġthis . getBody Part ( idx ) ĊĠĠĠĠĠ Ġif Ġ( body Part . content Ġis ĠMime Multipart ) Ġ{ ĊĠĠĠĠĠĠĠ Ġbody Part Contents . put All (( body Part . content Ġas ĠMime Multipart ). getBody Part Contents ()) ĊĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ Ġbody Part Contents [ body Part . data Handler . contentType . substring Before ("; ")] Ġ= Ġbody Part . data Handler . content . toString () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġbody Part Contents . toMap () ĊĠ Ġ} Ċ } Ċ