package Ġcom . sh ap osh ny k Ċ Ċ import Ġorg . junit . Test Ċ import Ġjava . net . URI Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠUni Builder Test Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsimp liest Url Can Be Built () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com ") ĊĠĠĠĠĠĠĠ ĠassertEquals (" https :// www . sh ap osh ny k . com ", Ġuri . base ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("", Ġuri . path ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( emptyList (), Ġuri . params ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com "), Ġuri . build ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġuri 2 Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com /") ĊĠĠĠĠĠĠĠ ĠassertEquals (" https :// www . sh ap osh ny k . com ", Ġuri 2 . base ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("/", Ġuri 2 . path ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( emptyList (), Ġuri 2 . params ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / "), Ġuri 2 . build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsimple Url Can Be Built () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġuri 2 Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com : 8 0 8 0 / page . html ") ĊĠĠĠĠĠĠĠ ĠassertEquals (" https :// www . sh ap osh ny k . com : 8 0 8 0 ", Ġuri 2 . base ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("/ page . html ", Ġuri 2 . path ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( emptyList (), Ġuri 2 . params ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com : 8 0 8 0 / page . html "), Ġuri 2 . build ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġuri 3 Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html ") ĊĠĠĠĠĠĠĠ ĠassertEquals (" https :// www . sh ap osh ny k . com ", Ġuri 3 . base ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("/ page . html ", Ġuri 3 . path ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( emptyList (), Ġuri 3 . params ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html "), Ġuri 3 . build ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġuri 4 Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 & q 2 = v 2 ") ĊĠĠĠĠĠĠĠ ĠassertEquals (" https :// www . sh ap osh ny k . com ", Ġuri 4 . base ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("/ page . html ", Ġuri 4 . path ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( Pair (" q 1 ", Ġ" v 1 "), ĠPair (" q 2 ", Ġ" v 2 ")), Ġuri 4 . params ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 & q 2 = v 2 "), Ġuri 4 . build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġparams Can Be Added () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 & q 2 = v 2 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 2 ", Ġ" v 2 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsame Params Can Be Added () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 & q 1 = v 2 & q 1 = v 3 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 2 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 3 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġvalues Are Esc aped () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 % 3 Dv 2 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 = v 2 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 % 3 Cv 2 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 < v 2 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 % 3 Cv 2 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 < v 2 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? q 1 = v 1 % 2 6 v 2 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 & v 2 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġparams Are Esc aped () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? qv 1 % 3 Dv 2 = 1 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" qv 1 = v 2 ", Ġ" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? qv 1 % 3 Cv 2 = 1 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" qv 1 < v 2 ", Ġ" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? qv 1 % 3 Cv 2 = 1 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" qv 1 < v 2 ", Ġ" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / page . html ? qv 1 % 2 6 v 2 = 1 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" qv 1 & v 2 ", Ġ" 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġpath Changed () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / about . html "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. path ("/ about . html ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / about . html ? q 1 = v 1 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. path ("/ about . html ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com ? q 1 = v 1 "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. path ("") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. param (" q 1 ", Ġ" v 1 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠIllegalArgumentException :: class ) ĊĠĠĠ Ġfun Ġinvalid Path Rejected () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com / page . html "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / about . html "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. path (" about . html ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠIllegalArgumentException :: class ) ĊĠĠĠ Ġfun Ġinvalid App ended Path Rejected () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com / about . html "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. append Path (" about . html ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġparams Can Be Dropped () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbuilder Ġ= ĠUni Builder . of (" https :// www . sh ap osh ny k . com ? q = v 1 "); ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( URI (" https :// www . sh ap osh ny k . com "), Ġbuilder ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. drop Params () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build ()) ĊĠĠĠ Ġ} Ċ } Ċ