package Ġde . hol ist icon . rank ed . view . leader board Ċ Ċ import Ġde . hol ist icon . rank ed . model . UserName Ċ import Ġde . hol ist icon . rank ed . model . event . Player Ranking Changed Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġjava . time . Instant Ċ import Ġjava . util .* Ċ Ċ class ĠPlayer Ranking By E lo Handler Spec Ġ{ ĊĊĠ Ġprivate Ġval Ġhandler Ġ= ĠPlayer Ranking By E lo Handler () ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġ// Ġfor Ġeach Ġtest , Ġmake Ġsure Ġno Ġplayers Ġare Ġpresent ĊĠĠĠ ĠassertThat ( handler . get ()). isEmpty () ĊĠ Ġ} ĊĊĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` a Ġnew Ġplayer Ġranking Ġis Ġadded `() Ġ{ ĊĠĠĠ Ġhandler . on ( Player Ranking Changed ( UserName (" ker mit "), Ġ 1 0 0 0 ), ĠInstant . now ()) ĊĊĠĠĠ Ġval Ġuser By E lo Rank Ġ= Ġhandler . get () ĊĊĠĠĠ ĠassertThat ( user By E lo Rank ). has Size ( 1 ) ĊĠĠĠ ĠassertThat ( user By E lo Rank [ 0 ]). isEqualTo ( Player E lo (" ker mit ", Ġ 1 0 0 0 )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` a Ġplayer Ġranking Ġis Ġupdated `() Ġ{ ĊĠĠĠ Ġhandler . on ( Player Ranking Changed ( UserName (" ker mit "), Ġ 1 0 0 0 ), ĠInstant . now ()) ĊĠĠĠ Ġhandler . on ( Player Ranking Changed ( UserName (" ker mit "), Ġ 2 0 0 0 ), ĠInstant . now ()) ĊĊĠĠĠ Ġval Ġuser By E lo Rank Ġ= Ġhandler . get () ĊĊĠĠĠ ĠassertThat ( user By E lo Rank ). has Size ( 1 ) ĊĠĠĠ ĠassertThat ( user By E lo Rank [ 0 ]). isEqualTo ( Player E lo (" ker mit ", Ġ 2 0 0 0 )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` two Ġplayers Ġare Ġsorted Ġby Ġrank `() Ġ{ ĊĠĠĠ Ġhandler . on ( Player Ranking Changed ( UserName (" ker mit "), Ġ 1 0 0 0 ), ĠInstant . now ()) ĊĠĠĠ Ġhandler . on ( Player Ranking Changed ( UserName (" pig gy "), Ġ 2 0 0 0 ), ĠInstant . now ()) ĊĊĠĠĠ Ġval Ġuser By E lo Rank Ġ= Ġhandler . get () ĊĊĠĠĠ ĠassertThat ( user By E lo Rank ). has Size ( 2 ) ĊĠĠĠ ĠassertThat ( user By E lo Rank [ 0 ]). isEqualTo ( Player E lo (" pig gy ", Ġ 2 0 0 0 )) ĊĠĠĠ ĠassertThat ( user By E lo Rank [ 1 ]). isEqualTo ( Player E lo (" ker mit ", Ġ 1 0 0 0 )) ĊĠ Ġ} Ċ } ĊĊ Ċ class ĠPlayer E lo Spec Ġ{ ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` other Ġe lo Ġis Ġgreater `() Ġ{ ĊĠĠĠ ĠassertThat ( Player E lo (" ker mit ", Ġ 1 0 0 0 ). compareTo ( Player E lo (" pig gy ", Ġ 2 0 0 0 ))). isEqualTo ( 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` other Ġe lo Ġis Ġsmaller `() Ġ{ ĊĠĠĠ ĠassertThat ( Player E lo (" ker mit ", Ġ 2 0 0 0 ). compareTo ( Player E lo (" pig gy ", Ġ 1 0 0 0 ))). isEqualTo (- 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` sort Ġlist Ġby Ġcomp arable `() Ġ{ ĊĠĠĠ Ġval Ġlist Ġ= ĠlistOf ( Player E lo (" ker mit ", Ġ 1 0 0 0 ), ĠPlayer E lo (" pig gy ", Ġ 2 0 0 0 )). sorted () ĊĊĠĠĠ ĠassertThat ( list . first (). userName ). isEqualTo ( UserName (" pig gy ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` sort Ġset Ġby Ġcomp arable `() Ġ{ ĊĠĠĠ Ġval Ġtree Ġ= ĠTree Set < Player E lo >() ĊĊĠĠĠ Ġtree . add ( Player E lo (" ker mit ", Ġ 1 0 0 0 )) ĊĠĠĠ ĠassertThat ( tree . first (). userName ). isEqualTo ( UserName (" ker mit ")) ĊĊĠĠĠ Ġtree . add ( Player E lo (" pig gy ", Ġ 2 0 0 0 )) ĊĠĠĠ ĠassertThat ( tree . first (). userName ). isEqualTo ( UserName (" pig gy ")) ĊĠ Ġ} Ċ } Ċ