package Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . api Ċ Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . api . Fight Data . Geo location Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . api . Fight Result . Player Ċ import Ġcom . n ha ar man . mock it ok otlin 2 .* Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . junit . jupiter . Mockito Extension Ċ import Ġorg . mockito . junit . jupiter . Mockito Settings Ċ import Ġorg . mockito . quality . Strict ness Ċ Ċ @ Extend With ( Mockito Extension :: class ) Ċ class ĠUsers Service Test Ġ{ ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġrandom Service : ĠRandom Service ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġstorage Service : ĠStorage Service ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Create User () Ġ{ Ċĉ ĉ val Ġusers Service Ġ= ĠUsers Service ( random Service , Ġstorage Service ) Ċĉ ĉ val ĠuserData Ġ= ĠUser Data (" ve get a ") Ċĉ ĉ wh enever ( random Service . generate ( 1 0 0 0 0 0 0 )). do Return ( 1 2 3 4 5 6 ) Ċĉ ĉ users Service Ċĉĉĉ ĉ . create With ( userData ) Ċĉĉĉ ĉ . also Ġ{ Ġuser Ġ-> Ċĉĉĉĉ ĉ assertThat ( user . nickname ). isEqualTo (" ve get a ") Ċĉĉĉĉ ĉ assertThat ( user . id ). isEqualTo ( 1 2 3 4 5 6 ) Ċĉĉĉĉ ĉ verify ( random Service ). generate ( 1 0 0 0 0 0 0 ) Ċĉĉĉĉ ĉ verify ( storage Service ). store User ( user ) Ċĉĉĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Missing Nick name () Ġ{ Ċĉ ĉ val Ġusers Service Ġ= ĠUsers Service ( random Service , Ġstorage Service ) Ċĉ ĉ val ĠuserData Ġ= ĠUser Data ( null ) Ċĉ ĉ assert Throws < IllegalArgumentException > Ġ{ Ġusers Service . create With ( userData ) Ġ} Ċĉĉĉ ĉ . also Ġ{ Ġe Ġ-> Ċĉĉĉĉ ĉ assertThat ( e . message ). isEqualTo (" missing Ġnickname ") Ċĉĉĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet User () Ġ{ Ċĉ ĉ val Ġusers Service Ġ= ĠUsers Service ( random Service , Ġstorage Service ) Ċĉ ĉ val Ġuser Ġ= ĠUser ( 1 2 3 4 5 6 , Ġ" ve get a ") Ċĉ ĉ wh enever ( storage Service . find User ( 1 2 3 4 5 6 )). do Return ( user ) Ċĉ ĉ users Service Ċĉĉĉ ĉ . getUser ( 1 2 3 4 5 6 ) Ċĉĉĉ ĉ . also Ġ{ Ġfound Ġ-> Ċĉĉĉĉ ĉ assertThat ( found ). isEqualTo Comp aring Field By Field ( user ) Ċĉĉĉĉ ĉ verify ( storage Service ). find User ( 1 2 3 4 5 6 ) Ċĉĉĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Cannot GetUser () Ġ{ Ċĉ ĉ val Ġusers Service Ġ= ĠUsers Service ( random Service , Ġstorage Service ) Ċĉ ĉ assert Throws < User NotFoundException > Ġ{ Ġusers Service . getUser ( 1 2 3 4 5 6 ) Ġ} Ċĉĉĉ ĉ . also Ġ{ Ġe Ġ-> Ċĉĉĉĉ ĉ assertThat ( e . message ). isEqualTo (" user Ġ 1 2 3 4 5 6 Ġnot Ġfound ") Ċĉĉĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet User Available Cards () Ġ{ Ċĉ ĉ val Ġusers Service Ġ= ĠUsers Service ( random Service , Ġstorage Service ) Ċĉ ĉ val Ġuser Ġ= ĠUser ( 1 2 3 4 5 6 , Ġ" ve get a ") Ċĉ ĉ val Ġcards Ġ= ĠlistOf ( Ċĉĉĉ ĉ Card ( 1 , Ġ" h ulk ", Ġ" big ", Ġ" h ulk . jpg ", Ġ 2 3 ), Ċĉĉĉ ĉ Card ( 2 , Ġ" iron Ġman ", Ġ" metal ", Ġ" iron _ man . jpg ", Ġ 4 5 )) Ċĉ ĉ wh enever ( storage Service . find User ( 1 2 3 4 5 6 )). do Return ( user ) Ċĉ ĉ wh enever ( storage Service . getUser Available Cards ( 1 2 3 4 5 6 )). do Return ( cards ) Ċĉ ĉ users Service Ċĉĉĉ ĉ . get Cards Of ( 1 2 3 4 5 6 ) Ċĉĉĉ ĉ . also Ġ{ Ġfound Ġ-> Ċĉĉĉĉ ĉ assertThat ( found ). has Same Elements As ( cards ) Ċĉĉĉĉ ĉ verify ( storage Service ). find User ( 1 2 3 4 5 6 ) Ċĉĉĉĉ ĉ verify ( storage Service ). getUser Available Cards ( 1 2 3 4 5 6 ) Ċĉĉĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet User Available Cards Empty () Ġ{ Ċĉ ĉ val Ġusers Service Ġ= ĠUsers Service ( random Service , Ġstorage Service ) Ċĉ ĉ val Ġuser Ġ= ĠUser ( 1 2 3 4 5 6 , Ġ" ve get a ") Ċĉ ĉ wh enever ( storage Service . find User ( 1 2 3 4 5 6 )). do Return ( user ) Ċĉ ĉ users Service Ċĉĉĉ ĉ . get Cards Of ( 1 2 3 4 5 6 ) Ċĉĉĉ ĉ . also Ġ{ Ġcards Ġ-> Ċĉĉĉĉ ĉ assertThat ( cards ). isEmpty () Ċĉĉĉĉ ĉ verify ( storage Service ). find User ( 1 2 3 4 5 6 ) Ċĉĉĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Create Team () Ġ{ Ċĉ ĉ val ĠuserService Ġ= ĠUsers Service ( random Service , Ġstorage Service ) Ċĉ ĉ val Ġsuper hero es Ġ= ĠlistOf ( 1 , Ġ 2 , Ġ 3 , Ġ 4 ) Ċĉ ĉ val Ġteam Data Ġ= ĠUser Team Data ( 1 2 3 4 5 6 , Ġsuper hero es ) Ċĉ ĉ val Ġuser Ġ= ĠUser ( 1 2 3 4 5 6 , Ġ" ve get a ") Ċĉ ĉ wh enever ( random Service . generate ( 1 0 0 0 0 0 0 )). do Return ( 4 5 ) Ċĉ ĉ wh enever ( storage Service . find User ( 1 2 3 4 5 6 )). do Return ( user ) Ċĉ ĉ userService Ċĉĉĉ ĉ . create Team ( team Data ) Ċĉĉĉ ĉ . also Ġ{ Ġteam Created Ġ-> Ċĉĉĉĉ ĉ assertThat ( team Created . id ). isEqualTo ( 4 5 ) Ċĉĉĉĉ ĉ assertThat ( team Created . super hero es ). has Same Elements As ( super hero es ) Ċĉĉĉĉ ĉ verify ( storage Service ). find User ( 1 2 3 4 5 6 ) Ċĉĉĉĉ ĉ verify ( storage Service ). store User Team ( 1 2 3 4 5 6 , Ġteam Created ) Ċĉĉĉ ĉ } Ċ ĉ } Ċ Ċ } Ċ Ċ @ Extend With ( Mockito Extension :: class ) Ċ @ Mockito Settings ( strict ness Ġ= ĠStrict ness . LEN IENT ) Ċ class ĠTeams Service Test Ġ{ ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġmar vel Service : ĠMar vel Service ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġstorage Service : ĠStorage Service ĊĊ ĉ @ Test Ċ ĉ fun ĠtestGet Team () Ġ{ Ċĉ ĉ val Ġteams Service Ġ= ĠTeams Service ( mar vel Service , Ġstorage Service ) Ċĉ ĉ val Ġteam Id Ġ= Ġ 4 5 Ċĉ ĉ val Ġteam Ġ= ĠTeam ( team Id , ĠlistOf ( 1 , Ġ 2 , Ġ 3 , Ġ 4 )) Ċĉ ĉ val Ġh ulk Ġ= ĠCard ( 1 , Ġ" h ulk ", Ġ" big ", Ġ" h ulk . jpg ", Ġ 2 3 ) Ċĉ ĉ val Ġir on Man Ġ= ĠCard ( 2 , Ġ" iron Ġman ", Ġ" metal ", Ġ" iron _ man . jpg ", Ġ 4 5 ) Ċĉ ĉ val Ġcapt ain America Ġ= ĠCard ( 3 , Ġ" capt ain Ġa mer ica ", Ġ" shield ", Ġ" capt ain _ americ a . jpg ", Ġ 8 0 ) Ċĉ ĉ val Ġsp ider Man Ġ= ĠCard ( 4 , Ġ" spider Ġman ", Ġ" web ", Ġ" spider _ man . jpg ", Ġ 6 7 ) Ċĉ ĉ wh enever ( storage Service . find Team ( 4 5 )). do Return ( team ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 1 )). do Return ( h ulk ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 2 )). do Return ( iron Man ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 3 )). do Return ( capt ain America ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 4 )). do Return ( spider Man ) Ċĉ ĉ teams Service Ċĉĉĉ ĉ . get Team ( 4 5 ) Ċĉĉĉ ĉ . also Ġ{ Ġcards Ġ-> Ċĉĉĉĉ ĉ assertThat ( cards ). contains ( h ulk ). contains ( iron Man ). contains ( capt ain America ). contains ( spider Man ) Ċĉĉĉĉ ĉ verify ( storage Service ). find Team ( 4 5 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 1 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 2 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 3 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 4 ) Ċĉĉĉ ĉ } Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Team NotFound () Ġ{ Ċĉ ĉ val Ġteams Service Ġ= ĠTeams Service ( mar vel Service , Ġstorage Service ) Ċĉ ĉ wh enever ( storage Service . find Team ( 4 5 )). do Return ( null ) Ċĉ ĉ assert Throws < Team NotFoundException > Ġ{ Ġteams Service . get Team ( 4 5 ) Ġ} Ċĉĉĉ ĉ . also Ġ{ Ġexception Ġ-> Ċĉĉĉĉ ĉ assertThat ( exception . message ). isEqualTo (" team Ġ 4 5 Ġnot Ġfound ") Ċĉĉĉĉ ĉ verify ( storage Service ). find Team ( 4 5 ) Ċĉĉĉĉ ĉ verify ( mar vel Service , Ġnever ()). get Card Of ( any ()) Ċĉĉĉ ĉ } Ċ ĉ } Ċ Ċ } Ċ Ċ @ Extend With ( Mockito Extension :: class ) Ċ @ Mockito Settings ( strict ness Ġ= ĠStrict ness . LEN IENT ) Ċ class ĠF ight Service Test Ġ{ ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġusers Service : ĠUsers Service ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġstorage Service : ĠStorage Service ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġrandom Service : ĠRandom Service ĊĊ ĉ @ Mock Ċ ĉ private Ġlateinit Ġvar Ġmar vel Service : ĠMar vel Service ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Fight () Ġ{ Ċĉ ĉ val Ġfight Service Ġ= ĠF ight Service ( mar vel Service , Ġusers Service , Ġstorage Service , Ġrandom Service ) Ċĉ ĉ val Ġgeo location Ġ= ĠGeo location ( latitude Ġ= Ġ 1 2 3 1 2 3 1 , Ġlongitude Ġ= Ġ 5 3 2 3 4 ) Ċĉ ĉ val ĠuserId Ġ= Ġ 1 2 3 4 5 6 Ċĉ ĉ val Ġopponent Id Ġ= Ġ 1 0 0 0 0 0 Ċĉ ĉ val Ġdata Ġ= ĠF ight Data ( user _ id Ġ= ĠuserId , Ġgeo location Ġ= Ġgeo location , Ġtimestamp Ġ= Ġ 1 5 0 0 0 0 0 0 3 4 ) Ċĉ ĉ val Ġuser Team Ġ= ĠTeam ( 2 3 , ĠlistOf ( 1 , Ġ 2 , Ġ 3 , Ġ 4 )) Ċĉ ĉ val Ġopponent Team Ġ= ĠTeam ( 4 5 , ĠlistOf ( 5 , Ġ 6 , Ġ 7 , Ġ 8 )) Ċĉ ĉ val Ġh ulk Ġ= ĠCard ( 1 , Ġ" h ulk ", Ġ" big ", Ġ" h ulk . jpg ", Ġ 2 3 ) Ċĉ ĉ val Ġir on Man Ġ= ĠCard ( 2 , Ġ" iron Ġman ", Ġ" metal ", Ġ" iron _ man . jpg ", Ġ 4 5 ) Ċĉ ĉ val Ġcapt ain America Ġ= ĠCard ( 3 , Ġ" capt ain Ġa mer ica ", Ġ" shield ", Ġ" capt ain _ americ a . jpg ", Ġ 8 0 ) Ċĉ ĉ val Ġsp ider Man Ġ= ĠCard ( 4 , Ġ" spider Ġman ", Ġ" web ", Ġ" spider _ man . jpg ", Ġ 6 7 ) Ċĉ ĉ val Ġth or Ġ= ĠCard ( 5 , Ġ" thor ", Ġ" hammer ", Ġ" thor . jpg ", Ġ 8 9 ) Ċĉ ĉ val Ġdr Str ange Ġ= ĠCard ( 6 , Ġ" dr Ġstrange ", Ġ" time ", Ġ" dr _ str ange . jpg ", Ġ 8 1 ) Ċĉ ĉ val Ġant Man Ġ= ĠCard ( 7 , Ġ" ant Ġman ", Ġ" ants ", Ġ" ant _ man . jpg ", Ġ 5 5 ) Ċĉ ĉ val Ġf alcon Ġ= ĠCard ( 8 , Ġ" f alcon ", Ġ" w ings ", Ġ" f alcon . jpg ", Ġ 3 2 ) Ċĉ ĉ wh enever ( users Service . getUser ( userId )). do Return ( User ( userId , Ġ" ve get a ")) Ċĉ ĉ wh enever ( users Service . getUser ( opp onent Id )). do Return ( User ( opp onent Id , Ġ" g oku ")) Ċĉ ĉ wh enever ( storage Service . find An Opp onent For ( userId )). do Return ( opp onent Id ) Ċĉ ĉ wh enever ( storage Service . find User Team ( userId )). do Return ( user Team ) Ċĉ ĉ wh enever ( storage Service . find User Team ( opp onent Id )). do Return ( opp onent Team ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 1 )). do Return ( h ulk ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 2 )). do Return ( iron Man ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 3 )). do Return ( capt ain America ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 4 )). do Return ( spider Man ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 5 )). do Return ( thor ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 6 )). do Return ( dr Str ange ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 7 )). do Return ( ant Man ) Ċĉ ĉ wh enever ( mar vel Service . get Card Of ( 8 )). do Return ( f alcon ) Ċĉ ĉ wh enever ( random Service . generate ( 1 0 0 0 0 )). do Return ( 1 ) Ċĉ ĉ fight Service Ċĉĉĉ ĉ . fight ( data ) Ċĉĉĉ ĉ . also Ġ{ Ġfight Result Ġ-> Ċĉĉĉĉ ĉ assertThat ( fight Result . id ). isEqualTo ( 1 ) Ċĉĉĉĉ ĉ assertThat ( fight Result . winner ). isEqualTo (" g oku ") Ċĉĉĉĉ ĉ assertThat ( fight Result . players [ 0 ]). isEqualTo ( Player ( userId , Ġ" ve get a ", Ġ 2 3 , Ġ 2 1 5 )) Ċĉĉĉĉ ĉ assertThat ( fight Result . players [ 1 ]). isEqualTo ( Player ( opp onent Id , Ġ" g oku ", Ġ 4 5 , Ġ 2 5 7 , Ġtrue )) Ċĉĉĉĉ ĉ verify ( users Service ). getUser ( userId ) Ċĉĉĉĉ ĉ verify ( users Service ). getUser ( opp onent Id ) Ċĉĉĉĉ ĉ verify ( storage Service ). find An Opp onent For ( userId ) Ċĉĉĉĉ ĉ verify ( storage Service ). find User Team ( userId ) Ċĉĉĉĉ ĉ verify ( storage Service ). find User Team ( opp onent Id ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 1 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 2 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 3 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 4 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 5 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 6 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 7 ) Ċĉĉĉĉ ĉ verify ( mar vel Service ). get Card Of ( 8 ) Ċĉĉĉĉ ĉ verify ( random Service ). generate ( 1 0 0 0 0 ) Ċĉĉĉ ĉ } Ċ ĉ } Ċ Ċ } Ċ