package Ġcom . us yr le . ae ther stream . controller Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġcom . us yr le . ae ther stream . repo . Plan ar Card Ċ import Ġcom . us yr le . ae ther stream . repo . Plan ar Deck Ċ import Ġcom . us yr le . ae ther stream . repo . Plan ar Deck Repository Ċ import Ġcom . us yr le . ae ther stream . service . Plane Service Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . mockito .* Ċ import Ġjava . util .* Ċ Ċ internal Ġclass ĠPlane Controller Test Ġ{ ĊĊĠĠĠ Ġval Ġtest Cards Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠ ĠPlan ar Card (" Plane 1 ", Ġ" plane ", Ġ" https :// api . sc ry fall . com ", Ġ 1 2 3 4 1 ), ĊĠĠĠĠĠĠĠ ĠPlan ar Card (" Plane 2 ", Ġ" plane ", Ġ" https :// api . sc ry fall . com ", Ġ 1 2 3 4 2 ), ĊĠĠĠĠĠĠĠ ĠPlan ar Card (" Plane 3 ", Ġ" plane ", Ġ" https :// api . sc ry fall . com ", Ġ 1 2 3 4 3 ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġtest Current Card Ġ= ĠPlan ar Card (" Current ", Ġ" plane ", Ġ" https :// api . sc ry fall . com ", Ġ 9 9 9 9 9 ) ĊĊĠĠĠ Ġ@ Captor ĊĠĠĠ Ġlateinit Ġvar Ġdeck Captor : ĠArgument Captor < Plan ar Deck > ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġmock Plane Service : ĠPlane Service ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġmock Repository : ĠPlan ar Deck Repository ĊĊĠĠĠ Ġ@ Inject Mocks ĊĠĠĠ Ġlateinit Ġvar Ġsubject : ĠPlane Controller ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Plane Service . generate Plan ar Deck ( any (), Ġany ())). thenReturn ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgenerate New Plan ar Deck _ gener ates With Requested Values () Ġ{ ĊĠĠĠĠĠĠĠ Ġsubject . generate New Plan ar Deck ( Generate Request ( 2 0 , Ġfalse )) ĊĊĠĠĠĠĠĠĠ Ġverify ( mock Plane Service ). generate Plan ar Deck ( 2 0 , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgenerate New Plan ar Deck _ defaults To Ten Cards And Use Ph en om ena () Ġ{ ĊĠĠĠĠĠĠĠ Ġsubject . generate New Plan ar Deck ( Generate Request ( null , Ġnull )) ĊĊĠĠĠĠĠĠĠ Ġverify ( mock Plane Service ). generate Plan ar Deck ( 1 0 , Ġtrue ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgenerate New Plan ar Deck _ returns Basic Info About Deck () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Plane Service . generate Plan ar Deck ( any (), Ġany ())). thenReturn ( test Deck ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual : ĠPlan ar Deck Info Ġ= Ġsubject . generate New Plan ar Deck ( Generate Request ( null , Ġnull )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual . deck Size ). isEqualTo ( test Cards . size Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . startTime ). isEqualTo ( test Deck . startTime . to Instant (). epoch Second ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . current Plane ). isEqualTo ( test Deck . current Card ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . id ). isEqualTo ( test Deck . id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Plan ar Deck Info _ returns Basic Info About Deck () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . of ( test Deck )) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . get Plan ar Deck Info (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual !!. deck Size ). isEqualTo ( test Cards . size Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . startTime ). isEqualTo ( test Deck . startTime . to Instant (). epoch Second ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . current Plane ). isEqualTo ( test Deck . current Card ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . id ). isEqualTo ( test Deck . id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Plan ar Deck Info _ returns Null If NotFound () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . empty ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . get Plan ar Deck Info (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Plan ar Deck Info _ includes Spatial Mer ging Plane If Any () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġspatial Mer ging Card Ġ= Ġtest Cards [ 0 ], ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . of ( test Deck )) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . get Plan ar Deck Info (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual !!. current Plane ). isEqualTo ( test Current Card ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . spatial Mer ging Plane ). isEqualTo ( test Cards [ 0 ]) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Plan ar Deck Info _ includes Inter plan ar Tunnel Planes If Any () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinter plan ar Cards Ġ= Ġtest Cards . sub List ( 0 , Ġ 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . of ( test Deck )) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . get Plan ar Deck Info (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual !!. current Plane ). isEqualTo ( test Current Card ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . inter plan ar Planes ). isEqualTo ( test Deck . inter plan ar Cards ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Next Plan ar Card _ returns Basic Info About Deck () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . of ( test Deck )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Plane Service . play Next Plan ar Card ( test Deck )). thenReturn ( test Deck ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . play Next Plan ar Card (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual !!. deck Size ). isEqualTo ( test Cards . size Ġ+ Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . startTime ). isEqualTo ( test Deck . startTime . to Instant (). epoch Second ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . current Plane ). isEqualTo ( test Deck . current Card ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . id ). isEqualTo ( test Deck . id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Next Plan ar Card _ returns Null If NotFound () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . empty ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . play Next Plan ar Card (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Next Plan ar Card _ includes Spatial Mer ging Plane If Any () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġspatial Mer ging Card Ġ= Ġtest Cards [ 0 ], ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . of ( test Deck )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Plane Service . play Next Plan ar Card ( test Deck )). thenReturn ( test Deck ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . play Next Plan ar Card (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual !!. current Plane ). isEqualTo ( test Current Card ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . spatial Mer ging Plane ). isEqualTo ( test Cards [ 0 ]) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Next Plan ar Card _ passes Requested Plane To Service () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinter plan ar Cards Ġ= Ġtest Cards . sub List ( 0 , Ġ 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . of ( test Deck )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Plane Service . play Next Plan ar Card ( any (), Ġany ())). thenReturn ( test Deck ) ĊĊĠĠĠĠĠĠĠ Ġsubject . play Next Plan ar Card (" TEST ", Ġtest Cards . last (). mult iverse Id ) ĊĊĠĠĠĠĠĠĠ Ġverify ( mock Plane Service ). play Next Plan ar Card ( test Deck , Ġtest Cards . last (). mult iverse Id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġplay Next Plan ar Card _ includes Inter plan ar Tunnel Planes If Any () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Deck Ġ= ĠPlan ar Deck ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcards Ġ= Ġtest Cards , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠstartTime Ġ= ĠDate (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Card Ġ= Ġtest Current Card , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinter plan ar Cards Ġ= Ġtest Cards . sub List ( 0 , Ġ 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= Ġ" TEST " ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Repository . findById (" TEST ")). thenReturn ( Optional . of ( test Deck )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Plane Service . play Next Plan ar Card ( test Deck )). thenReturn ( test Deck ) ĊĊĠĠĠĠĠĠĠ Ġval Ġactual Ġ= Ġsubject . play Next Plan ar Card (" TEST ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( actual !!. current Plane ). isEqualTo ( test Current Card ) ĊĠĠĠĠĠĠĠ ĠassertThat ( actual . inter plan ar Planes ). isEqualTo ( test Deck . inter plan ar Cards ) ĊĠĠĠ Ġ} Ċ } Ċ