package Ġcom . t ng tech . ch system . service . match Ċ Ċ import Ġcom . t ng tech . ch system . dto . Play ed Match Ċ import Ġcom . t ng tech . ch system . entities . Match Entity Ċ import Ġcom . t ng tech . ch system . entities . Player Entity Ċ import Ġcom . t ng tech . ch system . entities . Tournament Entity Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . fail Ċ import Ġjava . time . LocalDateTime Ċ import Ġjava . util .* Ċ Ċ internal Ġclass ĠMatch Service UnitTest Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġmatch Service Ġ= ĠMatch Service () ĊĊĠĠĠ Ġprivate Ġval Ġtournament Ġ= ĠTo urnament Entity () ĊĠĠĠ Ġprivate Ġval Ġplayer 1 Ġ= ĠPlayer Entity ( name Ġ= Ġ" Alex ") ĊĠĠĠ Ġprivate Ġval Ġplayer 2 Ġ= ĠPlayer Entity ( name Ġ= Ġ" B ert ") ĊĠĠĠ Ġprivate Ġval Ġplayer 3 Ġ= ĠPlayer Entity ( name Ġ= Ġ" Ca es ar ") ĊĊĠĠĠ Ġprivate Ġval Ġplayers Ġ= Ġset Of ( player 1 , Ġplayer 2 , Ġplayer 3 ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠconvertTo Play ed Matches () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmatch Ġ= ĠMatch Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtournament Ġ= Ġtournament , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġround Index Ġ= Ġ 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplayer 1 Ġ= Ġplayer 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplayer 2 Ġ= Ġplayer 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwins Player 1 Ġ= Ġ 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwins Player 2 Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġplayed Matches Ġ= Ġmatch Service . convertTo Play ed Matches ( set Of ( match )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġfail (" Conversion Ġshould Ġwork Ġin Ġthis Ġcase Ġsince Ġresults Ġare Ġentered ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches ). has Size ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches . first (). id ). isEqualTo ( match . id ) ĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches . first (). tournament ). isEqualTo ( tournament ) ĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches . first (). round Index ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches . first (). player 1 ). isEqualTo ( player 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches . first (). player 2 ). isEqualTo ( player 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches . first (). wins Player 1 ). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches . first (). wins Player 2 ). isEqualTo ( 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` convertTo Play ed Matches Ġa Ġmatch Ġwith Ġmissing Ġresults `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmatch Ġ= ĠMatch Entity ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtournament Ġ= Ġtournament , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġround Index Ġ= Ġ 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplayer 1 Ġ= Ġplayer 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġplayer 2 Ġ= Ġplayer 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwins Player 1 Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwins Player 2 Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġplayed Matches Ġ= Ġmatch Service . convertTo Play ed Matches ( set Of ( match )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( play ed Matches ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` map Players To Matches Ġno Ġmatches Ġplayed `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġplayer To Matches Ġ= Ġmatch Service . map Players To Matches ( players , Ġempty Set ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( player To Matches [ player 1 ]). isEmpty () ĊĠĠĠĠĠĠĠ ĠassertThat ( player To Matches [ player 2 ]). isEmpty () ĊĠĠĠĠĠĠĠ ĠassertThat ( player To Matches [ player 3 ]). isEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` map Players To Matches Ġsome Ġmatches Ġplayed `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmatch 1 2 Ġ= Ġcreate Match ( player 1 , Ġplayer 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġmatch 2 3 Ġ= Ġcreate Match ( player 2 , Ġplayer 3 ) ĊĠĠĠĠĠĠĠ Ġval Ġmatch 1 3 Ġ= Ġcreate Match ( player 1 , Ġplayer 3 ) ĊĠĠĠĠĠĠĠ Ġval Ġmatch 1 By e Ġ= Ġcreate Match ( player 1 , Ġnull ) ĊĠĠĠĠĠĠĠ Ġval Ġmatch 2 By e Ġ= Ġcreate Match ( player 2 , Ġnull ) ĊĠĠĠĠĠĠĠ Ġval Ġmatch 3 By e Ġ= Ġcreate Match ( player 3 , Ġnull ) ĊĊĠĠĠĠĠĠĠ Ġval Ġplayed Matches : ĠSet < Play ed Match > Ġ= Ġset Of ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmatch 1 2 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmatch 2 3 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmatch 1 3 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmatch 1 By e , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmatch 2 By e , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmatch 3 By e ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġplayer To Matches Ġ= Ġmatch Service . map Players To Matches ( players , Ġplayed Matches ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( player To Matches [ player 1 ]). contains Exactly In Any Order ( match 1 2 , Ġmatch 1 3 , Ġmatch 1 By e ) ĊĠĠĠĠĠĠĠ ĠassertThat ( player To Matches [ player 2 ]). contains Exactly In Any Order ( match 1 2 , Ġmatch 2 3 , Ġmatch 2 By e ) ĊĠĠĠĠĠĠĠ ĠassertThat ( player To Matches [ player 3 ]). contains Exactly In Any Order ( match 2 3 , Ġmatch 1 3 , Ġmatch 3 By e ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Match ( player 1 : ĠPlayer Entity , Ġplayer 2 : ĠPlayer Entity ?): ĠPlay ed Match Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠPlay ed Match ( UUID . randomUUID (), Ġtournament , Ġ 1 , Ġplayer 1 , Ġplayer 2 , Ġ 0 , Ġ 0 , ĠLocalDateTime . now ()) ĊĠĠĠ Ġ} Ċ }