/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 1 7 ĠD uck Duck Go Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . duck duck go . app . tracker detection Ċ Ċ import Ġcom . duck duck go . app . privacy . db . User Whitelist Dao Ċ import Ġcom . duck duck go . app . tracker detection . model . Tracking Event Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . eq Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertNull Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ class ĠTracker Detector Client Type Test Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġmock Entity Lookup : ĠEntity Lookup Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġvar Ġmock Blocking Client : ĠClient Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġvar Ġmock Whitelist Client : ĠClient Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġvar Ġmock User Whitelist Dao : ĠUser Whitelist Dao Ġ= Ġmock () ĊĊĠĠĠ Ġprivate Ġvar Ġtest ee Ġ= ĠTracker Detector Impl ( mock Entity Lookup , Ġmock User Whitelist Dao ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġbefore () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( mock User Whitelist Dao . contains ( any ())). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Blocking Client . matches ( eq ( Url . BLOCK ED ), Ġany ())). thenReturn ( Client . Result ( true )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Blocking Client . matches ( eq ( Url . BLOCK ED _ AND _ WHITE LIST ED ), Ġany ())). thenReturn ( Client . Result ( true )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Blocking Client . matches ( eq ( Url . WHITE LIST ED ), Ġany ())). thenReturn ( Client . Result ( false )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Blocking Client . matches ( eq ( Url . UN LIST ED ), Ġany ())). thenReturn ( Client . Result ( false )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Blocking Client . name ). thenReturn ( Client . Client Name . TD S ) ĊĠĠĠĠĠĠĠ Ġtest ee . add Client ( mock Blocking Client ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( mock Whitelist Client . matches ( eq ( Url . BLOCK ED ), Ġany ())). thenReturn ( Client . Result ( false )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Whitelist Client . matches ( eq ( Url . BLOCK ED _ AND _ WHITE LIST ED ), Ġany ())). thenReturn ( Client . Result ( true )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Whitelist Client . matches ( eq ( Url . WHITE LIST ED ), Ġany ())). thenReturn ( Client . Result ( true )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Whitelist Client . matches ( eq ( Url . UN LIST ED ), Ġany ())). thenReturn ( Client . Result ( false )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Whitelist Client . name ). thenReturn ( Client . Client Name . TEMP OR ARY _ WHITE LIST ) ĊĠĠĠĠĠĠĠ Ġtest ee . add Client ( mock Whitelist Client ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Url Matches Only In Blocking Client Then Evaluate Returns Tracking Event () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġurl Ġ= ĠUrl . BLOCK ED ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠTracking Event ( document Url , Ġurl , Ġnull , Ġnull , Ġtrue , Ġnull ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected , Ġtest ee . evaluate ( url , Ġdocument Url )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Url Matches Only In Wh itelisted Client Then Evaluate Returns Null () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġurl Ġ= ĠUrl . WHITE LIST ED ĊĠĠĠĠĠĠĠ ĠassertNull ( test ee . evaluate ( url , Ġdocument Url )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Url Matches In Blocking And Wh itelisted Client Then Evaluate Returns Null () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġurl Ġ= ĠUrl . BLOCK ED _ AND _ WHITE LIST ED ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= ĠTracking Event ( document Url , Ġurl , Ġnull , Ġnull , Ġfalse , Ġnull ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected , Ġtest ee . evaluate ( url , Ġdocument Url )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwhen Url DoesNot Match In Any Clients Then Evaluate Returns Null () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġurl Ġ= ĠUrl . UN LIST ED ĊĠĠĠĠĠĠĠ ĠassertNull ( test ee . evaluate ( url , Ġdocument Url )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval Ġdocument Url Ġ= Ġ" http :// example . com " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġobject ĠUrl Ġ{ ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠWH ITE LIST ED Ġ= Ġ" wh itelisted . com " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠBLOCK ED Ġ= Ġ" blocked . com " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠBLOCK ED _ AND _ WHITE LIST ED Ġ= Ġ" blocked And Wh itelisted . com " ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠUN LIST ED Ġ= Ġ" un listed . com " ĊĠĠĠ Ġ} Ċ } Ċ