package Ġpl . edu . z ut . mad . schedule Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġcom . t ng tech . java . junit . dat apro vider . DataProvider Runner Ċ import Ġcom . t ng tech . java . junit . dat apro vider . Use DataProvider Ċ import Ġio . reactivex . Observable Ċ import Ġorg . joda . time . LocalDate Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Inject Mocks Ċ import Ġorg . mockito . junit . Mockito JUnit Ċ import Ġorg . mockito . junit . Mockito Rule Ċ import Ġpl . edu . z ut . mad . schedule . data . Schedule Repository Ċ import Ġpl . edu . z ut . mad . schedule . data . model . ui . Day Ċ import Ġpl . edu . z ut . mad . schedule . data . model . ui . Empty Day Ċ import Ġpl . edu . z ut . mad . schedule . data . model . ui . Optional Day Ċ import Ġpl . edu . z ut . mad . schedule . util . Dates Provider Ċ import Ġpl . edu . z ut . mad . schedule . util . Model Mapper Ċ import Ġpl . edu . z ut . mad . schedule . util . Network Connection Ċ Ċ @ Suppress (" Illegal Identifier ") Ċ @ RunWith ( DataProvider Runner :: class ) Ċ internal Ġclass ĠSchedule Presenter Test Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠDATE Ġ= ĠLocalDate . now () ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠMIN _ DATE Ġ= ĠLocalDate . now () ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠMAX _ DATE Ġ= ĠMIN _ DATE . plus Months ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġmock ito Rule : ĠMockito Rule Ġ= ĠMockito JUnit . rule () ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġtest Scheduler Rule Ġ= ĠRx Immediate Scheduler Rule () ĊĊĠĠĠ Ġval Ġuser Ġ= Ġmock < User >() ĊĠĠĠ Ġval Ġmapper Ġ= Ġmock < Model Mapper >() ĊĠĠĠ Ġval Ġview Ġ= Ġmock < Schedule M vp . View >() ĊĠĠĠ Ġval Ġdates Provider Ġ= Ġmock < Dates Provider >() ĊĠĠĠ Ġval Ġconnection Ġ= Ġmock < Network Connection >() ĊĠĠĠ Ġval Ġrepository Ġ= Ġmock < Schedule Repository >() ĊĊĠĠĠ Ġ@ Inject Mocks ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġschedule Presenter : ĠSchedule Presenter ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` show Ġloading Ġview Ġshould Ġbe Ġcalled Ġwhen Ġview Ġis Ġcreated `() Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider () ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). show Loading View () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġmin Ġdate Ġshould Ġbe Ġcalled Ġwhen Ġuser Ġis Ġsaved Ġand Ġview Ġis Ġcreated `() Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider () ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( repository ). get Schedule Min Date () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġmax Ġdate Ġshould Ġbe Ġcalled Ġwhen Ġuser Ġis Ġsaved Ġand Ġview Ġis Ġcreated `() Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider () ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( repository ). get Schedule Max Date () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġby Ġdate Ġshould Ġbe Ġcalled Ġwhen Ġuser Ġis Ġsaved Ġand Ġview Ġis Ġcreated `() Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider () ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( repository ). get Day By Date ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Use DataProvider (" day Ui ", Ġlocation Ġ= Ġ[( Mock Data :: class )]) ĊĠĠĠ Ġfun Ġ` mapping Ġto Ġless ons Ġevents Ġshould Ġbe Ġcalled Ġwhen Ġuser Ġis Ġsaved Ġand Ġview Ġis Ġcreated `( day : ĠDay ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider And Day ( day ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( mapper ). to Less ons Events ( day ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Use DataProvider (" day Ui ", Ġlocation Ġ= Ġ[( Mock Data :: class )]) ĊĠĠĠ Ġfun Ġ` set Ġdata Ġshould Ġbe Ġcalled Ġwhen Ġrepository Ġreturn Ġdata `( day : ĠDay ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider And Day ( day ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). setData ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Use DataProvider (" empty Day ", Ġlocation Ġ= Ġ[( Mock Data :: class )]) ĊĠĠĠ Ġfun Ġ` set Ġdata Ġevents Ġshould Ġbe Ġbe Ġcalled Ġwhen Ġrepository Ġreturn Ġempty Ġday `( empty Day : ĠEmpty Day ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider And Day ( empty Day ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). setData ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Use DataProvider (" day Ui ", Ġlocation Ġ= Ġ[( Mock Data :: class )]) ĊĠĠĠ Ġfun Ġ` hide Ġloading Ġshould Ġbe Ġbe Ġcalled Ġwhen Ġrepository Ġreturn Ġdata `( day : ĠDay ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider And Day ( day ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). hide Loading View () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` on Ġdate Ġinterval Ġcalculated Ġis Ġcalled Ġon Ġview Ġis Ġcreated `() Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider () ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). on Date Interval Calculated ( MIN _ DATE , ĠMAX _ DATE ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` show Ġlogin Ġview Ġshould Ġbe Ġcalled Ġwhen Ġuser Ġis Ġnot Ġsaved `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( user . is Saved ()). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . on View Is Created () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). show Login View () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` refresh Ġschedule Ġshould Ġbe Ġcalled Ġwhen Ġconnection Ġis Ġavailable `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( connection . is Available ()). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . refresh () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). refresh Schedule ( any ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Ġalbum Ġnumber Ġshould Ġbe Ġcalled Ġwhen Ġconnection Ġis Ġavailable `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( connection . is Available ()). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . refresh () ĊĊĠĠĠĠĠĠĠ Ġverify ( user ). get Album Number () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` show Ġinternet Ġerror Ġshould Ġbe Ġcalled Ġwhen Ġconnection Ġis Ġnot Ġavailable `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( connection . is Available ()). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠ Ġschedule Presenter . refresh () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). show Internet Error () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` user Ġdelete Ġshould Ġbe Ġcalled Ġon Ġlogout `() Ġ{ ĊĠĠĠĠĠĠĠ Ġschedule Presenter . logout () ĊĊĠĠĠĠĠĠĠ Ġverify ( user ). delete () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` repository Ġdelete Ġshould Ġbe Ġcalled Ġon Ġlogout `() Ġ{ ĊĠĠĠĠĠĠĠ Ġschedule Presenter . logout () ĊĊĠĠĠĠĠĠĠ Ġverify ( repository ). delete () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` show Ġlogin Ġview Ġshould Ġbe Ġcalled Ġon Ġlogout `() Ġ{ ĊĠĠĠĠĠĠĠ Ġschedule Presenter . logout () ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). show Login View () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġprepare Mock sTo Return Dates From Repository And Dates Provider () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( user . is Saved ()). thenReturn ( true ) ĊĠĠĠĠĠĠĠ Ġwhenever ( repository . get Schedule Min Date ()). thenReturn ( Observable . just ( MIN _ DATE )) ĊĠĠĠĠĠĠĠ Ġwhenever ( repository . get Schedule Max Date ()). thenReturn ( Observable . just ( MAX _ DATE )) ĊĠĠĠĠĠĠĠ Ġwhenever ( dates Provider . getBy Interval ( MIN _ DATE , ĠMAX _ DATE )). thenReturn ( mutable ListOf ( DATE )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġprepare Mock sTo Return Dates From Repository And Dates Provider And Day ( day : ĠOptional Day ) Ġ{ ĊĠĠĠĠĠĠĠ Ġprepare Mock sTo Return Dates From Repository And Dates Provider () ĊĠĠĠĠĠĠĠ Ġwhenever ( repository . get Day By Date ( DATE )). thenReturn ( Observable . just ( day )) ĊĠĠĠ Ġ} Ċ } Ċ