package Ġme . ch ill . authentication Ċ Ċ import Ġme . ch ill . exceptions . Spot ify Authentication Exception Ċ import Ġokhttp 3 . Http Url Ċ import Ġorg . junit . Test Ċ import Ġjava . net . URL Encoder Ċ import Ġkotlin . test . Before Test Ċ import Ġkotlin . test . Ignore Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠSpotify Authorization Flow Authorization Link Test Ġ{ ĊĠ Ġprivate Ġval ĠclientId Ġ= Ġ" client _ id " ĊĠ Ġprivate Ġval Ġclient Secret Ġ= Ġ" client _ secret " ĊĠ Ġprivate Ġval Ġredirect Url Ġ= Ġ" https :// woo j ia hao . github . io " ĊĠ Ġprivate Ġlateinit Ġvar Ġbare Helper : ĠSpotify Authentication Helper . Builder ĊĊĠ Ġ@ Before Test ĊĠ Ġfun Ġbefore Test () Ġ{ ĊĠĠĠ Ġbare Helper Ġ= ĠSpotify Authentication Helper . Builder () ĊĠĠĠĠĠ Ġ. clientId ( clientId ) ĊĠĠĠĠĠ Ġ. client Secret ( client Secret ) ĊĠĠĠĠĠ Ġ. redirect Url ( redirect Url ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ( expected Ġ= ĠSpotify Authentication Exception :: class ) ĊĠ Ġfun Ġmissing _ client _ id _ throws _ exception () Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠSpotify Authentication Helper . Builder () ĊĠĠĠĠĠ Ġ. redirect Url ( redirect Url ) ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ ĠSpotify Authorization Flow ( helper ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ( expected Ġ= ĠSpotify Authentication Exception :: class ) ĊĠ Ġfun Ġmissing _ redirect _ url _ throws _ exception () Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠSpotify Authentication Helper . Builder () ĊĠĠĠĠĠ Ġ. clientId ( clientId ) ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ ĠSpotify Authorization Flow ( helper ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ( expected Ġ= ĠSpotify Authentication Exception :: class ) ĊĠ Ġfun Ġmissing _ client _ secret _ throws _ exception () Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠSpotify Authentication Helper . Builder () ĊĠĠĠĠĠ Ġ. clientId ( clientId ) ĊĠĠĠĠĠ Ġ. redirect Url ( redirect Url ) ĊĠĠĠĠĠ Ġ. build () ĊĊĠĠĠ ĠSpotify Authorization Flow ( helper ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġbare _ url _ should _ be _ formatted _ proper ly () Ġ{ ĊĠĠĠ Ġtest Url ( bare Helper . build ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġshow _ dialog _ should _ add _ parameter _ to _ url () Ġ{ ĊĠĠĠ Ġtest Url ( bare Helper . show Dialog ( true ). build (), Ġmap Of (" show _ dialog " Ġto Ġ" true ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġscopes _ should _ add _ parameter _ to _ url () Ġ{ ĊĠĠĠ Ġval Ġscopes Ġ= ĠarrayOf ( ĊĠĠĠĠĠ ĠSpotify Scope . Follow Read , ĊĠĠĠĠĠ ĠSpotify Scope . Account Details Read ĊĠĠĠ Ġ) ĊĠĠĠ Ġscopes . forEach Ġ{ Ġbare Helper . add Scope ( it ) Ġ} ĊĠĠĠ Ġtest Url ( ĊĠĠĠĠĠ Ġbare Helper . build (), ĊĠĠĠĠĠ Ġmap Of (" scope " Ġto Ġscopes . as Sequence (). distinct (). join ToString (" Ġ") Ġ{ Ġit . scope Name Ġ}) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġduplicate _ scopes _ should _ not _ duplicate _ in _ url () Ġ{ ĊĠĠĠ Ġval Ġscopes Ġ= ĠlistOf ( ĊĠĠĠĠĠ ĠSpotify Scope . Birth Date Read , ĊĠĠĠĠĠ ĠSpotify Scope . Account Details Read , ĊĠĠĠĠĠ ĠSpotify Scope . Follow Modify , ĊĠĠĠĠĠ ĠSpotify Scope . Follow Modify ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġscopes In Url Ġ= Ġscopes . as Sequence (). distinct (). join ToString (" Ġ") Ġ{ Ġit . scope Name Ġ} ĊĠĠĠ Ġtest Url ( bare Helper . set Scopes ( scopes ). build (), Ġmap Of (" scope " Ġto Ġscopes In Url )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġtest Url ( helper : ĠSpotify Authentication Helper , Ġexpected Arguments : ĠMap < String , ĠString > Ġ= Ġempty Map ()) Ġ{ ĊĠĠĠ Ġval Ġbuilder Ġ= ĠHttp Url . Builder () ĊĠĠĠĠĠ Ġ. scheme (" https ") ĊĠĠĠĠĠ Ġ. host (" accounts . spotify . com ") ĊĠĠĠĠĠ Ġ. add Path Segment (" authorize ") ĊĠĠĠĠĠ Ġ. add QueryParameter (" client _ id ", ĠclientId ) ĊĠĠĠĠĠ Ġ. add QueryParameter (" redirect _ uri ", Ġredirect Url ) ĊĠĠĠĠĠ Ġ. add QueryParameter (" response _ type ", Ġ" code ") ĊĠĠĠ Ġexpected Arguments . forEach Ġ{ Ġkey , Ġvalue Ġ-> Ġbuilder . add QueryParameter ( key , Ġvalue ) Ġ} ĊĊĠĠĠ Ġval Ġflow Ġ= ĠSpotify Authorization Flow ( helper ) ĊĠĠĠ ĠassertEquals ( builder . build (). url (). toString (), Ġflow . generate Authorization Url (). toString ()) ĊĠ Ġ} Ċ }