package Ġcom . br . mar cus mart ins . twitter analyze . features . tweets . repositories Ċ Ċ import Ġcom . br . mar cus mart ins . twitter analyze . UnitTest Ċ import Ġcom . br . mar cus mart ins . twitter analyze . core . exception . Failure . Network Connection Ċ import Ġcom . br . mar cus mart ins . twitter analyze . core . exception . Failure . ServerError Ċ import Ġcom . br . mar cus mart ins . twitter analyze . core . functional . Either Ċ import Ġcom . br . mar cus mart ins . twitter analyze . core . functional . Either . Right Ċ import Ġcom . br . mar cus mart ins . twitter analyze . core . platform . Network Handler Ċ import Ġcom . br . mar cus mart ins . twitter analyze . features . tweets . entities .* Ċ import Ġcom . br . mar cus mart ins . twitter analyze . features . tweets . services . Google Service Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . given Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Zero Interactions Ċ import Ġorg . am sh ove . k lu ent . shouldBe InstanceOf Ċ import Ġorg . am sh ove . k lu ent . should Equal Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mock Ċ import Ġretrofit 2 . Call Ċ import Ġretrofit 2 . Response Ċ Ċ class ĠGoogle Repository Test Ġ: ĠUnit Test () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġanalyze Ġ= Ġ" test e " ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġnetwork Repository : ĠGoogle Repository . Network ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġnetwork Handler : ĠNetwork Handler ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġservice : ĠGoogle Service ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġgoogle Call : ĠCall < Sent iment Response > ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġgoogle Response : ĠResponse < Sent iment Response > ĊĊĠĠĠ Ġ@ Before Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġnetwork Repository Ġ= ĠGoogle Repository . Network ( network Handler , Ġservice ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` should Ġreturn Ġneutral Ġsentiment Ġby Ġdefault `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġnetwork Handler . isConnected Ġ}. willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Response . body () Ġ}. willReturn ( null ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Response . is Successful Ġ}. willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Call . execute () Ġ}. willReturn ( google Response ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġservice . post Analysis ( any ()) Ġ}. willReturn ( google Call ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsentiment Ġ= Ġnetwork Repository . analyze ( analyze ) ĊĊĠĠĠĠĠĠĠ Ġsentiment Ġshould Equal ĠRight ( Sent iment Type . NE UT R AL ) ĊĠĠĠĠĠĠĠ Ġverify ( service ). post Analysis ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` should Ġget Ġsentiment Ġpositive Ġfrom Ġservice `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġnetwork Handler . isConnected Ġ}. willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Response . body () Ġ}. willReturn ( Sent iment Response ( Sent iment ( score Ġ= Ġ 0 . 1 ))) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Response . is Successful Ġ}. willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Call . execute () Ġ}. willReturn ( google Response ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġservice . post Analysis ( any ()) Ġ}. willReturn ( google Call ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsentiment Ġ= Ġnetwork Repository . analyze ( analyze ) ĊĊĠĠĠĠĠĠĠ Ġsentiment Ġshould Equal ĠRight ( Sent iment Type . POSITIVE ) ĊĠĠĠĠĠĠĠ Ġverify ( service ). post Analysis ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` should Ġget Ġsentiment Ġnegative Ġfrom Ġservice `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġnetwork Handler . isConnected Ġ}. willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Response . body () Ġ}. willReturn ( Sent iment Response ( Sent iment ( score Ġ= Ġ- 0 . 1 ))) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Response . is Successful Ġ}. willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġgoogle Call . execute () Ġ}. willReturn ( google Response ) ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġservice . post Analysis ( any ()) Ġ}. willReturn ( google Call ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsentiment Ġ= Ġnetwork Repository . analyze ( analyze ) ĊĊĠĠĠĠĠĠĠ Ġsentiment Ġshould Equal ĠRight ( Sent iment Type . NEGATIVE ) ĊĠĠĠĠĠĠĠ Ġverify ( service ). post Analysis ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` sentiment Ġservice Ġshould Ġreturn Ġnetwork Ġfailure Ġwhen Ġno Ġconnection `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġnetwork Handler . isConnected Ġ}. willReturn ( false ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsentiment Ġ= Ġnetwork Repository . analyze ( analyze ) ĊĊĠĠĠĠĠĠĠ Ġsentiment ĠshouldBe InstanceOf ĠEither :: class . java ĊĠĠĠĠĠĠĠ Ġsentiment . is Left Ġshould Equal Ġtrue ĊĠĠĠĠĠĠĠ Ġsentiment . either ({ Ġfailure Ġ-> Ġfailure ĠshouldBe InstanceOf ĠNetwork Connection :: class . java Ġ}, Ġ{}) ĊĠĠĠĠĠĠĠ Ġverify Zero Interactions ( service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` sentiment Ġservice Ġshould Ġreturn Ġnetwork Ġfailure Ġwhen Ġundefined Ġconnection `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġnetwork Handler . isConnected Ġ}. willReturn ( null ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsentiment Ġ= Ġnetwork Repository . analyze ( analyze ) ĊĊĠĠĠĠĠĠĠ Ġsentiment ĠshouldBe InstanceOf ĠEither :: class . java ĊĠĠĠĠĠĠĠ Ġsentiment . is Left Ġshould Equal Ġtrue ĊĠĠĠĠĠĠĠ Ġsentiment . either ({ Ġfailure Ġ-> Ġfailure ĠshouldBe InstanceOf ĠNetwork Connection :: class . java Ġ}, Ġ{}) ĊĠĠĠĠĠĠĠ Ġverify Zero Interactions ( service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` sentiment Ġservice Ġshould Ġreturn Ġserver Ġerror Ġif Ġno Ġsuccessful Ġresponse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġnetwork Handler . isConnected Ġ}. willReturn ( true ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsentiment Ġ= Ġnetwork Repository . analyze ( analyze ) ĊĊĠĠĠĠĠĠĠ Ġsentiment ĠshouldBe InstanceOf ĠEither :: class . java ĊĠĠĠĠĠĠĠ Ġsentiment . is Left Ġshould Equal Ġtrue ĊĠĠĠĠĠĠĠ Ġsentiment . either ({ Ġfailure Ġ-> Ġfailure ĠshouldBe InstanceOf ĠServer Error :: class . java Ġ}, Ġ{}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` sentiment Ġrequest Ġshould Ġcatch Ġexceptions `() Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven Ġ{ Ġnetwork Handler . isConnected Ġ}. willReturn ( true ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsentiment Ġ= Ġnetwork Repository . analyze ( analyze ) ĊĊĠĠĠĠĠĠĠ Ġsentiment ĠshouldBe InstanceOf ĠEither :: class . java ĊĠĠĠĠĠĠĠ Ġsentiment . is Left Ġshould Equal Ġtrue ĊĠĠĠĠĠĠĠ Ġsentiment . either ({ Ġfailure Ġ-> Ġfailure ĠshouldBe InstanceOf ĠServer Error :: class . java Ġ}, Ġ{}) ĊĠĠĠ Ġ} Ċ }