package Ġdev . j yl ha . station . ui . timetable Ċ Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġdev . j yl ha . station . data . stations . Station Name Mapper Ċ import Ġdev . j yl ha . station . model . Cause Categories Ċ import Ġdev . j yl ha . station . model . Cause Category Ċ import Ġdev . j yl ha . station . model . Station Ċ import Ġdev . j yl ha . station . model . Time table Row Ċ import Ġdev . j yl ha . station . model . Train Ċ import Ġorg . junit . Test ĊĊ Ċ class ĠTime table ViewState Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġhe ls ink i Ġ= ĠStation (" Hel sink i ", Ġ" HK I ", Ġ 1 , Ġ 1 . 0 , Ġ 1 . 0 ) ĊĠĠĠ Ġprivate Ġval Ġpas ila Ġ= ĠStation (" Pas ila ", Ġ" P SL ", Ġ 2 , Ġ 2 . 0 , Ġ 2 . 0 ) ĊĠĠĠ Ġprivate Ġval Ġtime table Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠ ĠTrain ( 1 , Ġ" S ", ĠTrain . Category . Long Distance ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` initial Ġstate `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState () ĊĠĠĠĠĠĠĠ ĠassertThat ( state ). isNotNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . station ). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . isLoading ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . isLoading Time table ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . is Re loading Time table ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . isLoading Station Names ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . station Name Mapper ). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . isLoading Cause Categories ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . cause Categories ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Time table _ Loading Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstation Ġ= Ġnull , ĠisLoading Time table Ġ= Ġfalse , Ġtime table Ġ= Ġtime table , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġloading Time table Failed Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Time table . Loading ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . station ). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Time table ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . loading Time table Failed ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . timetable ). isEmpty () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Time table _ Success Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstation Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠisLoading Time table Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġloading Time table Failed Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtime table Ġ= Ġempty List () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Time table . Success ( hel sink i , Ġtime table )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . station ). isEqualTo ( hel sink i ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Time table ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . loading Time table Failed ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . timetable ). isEqualTo ( timetable ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Time table _ Error Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstation Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠisLoading Time table Ġ= Ġtrue , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġloading Time table Failed Ġ= Ġfalse , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtime table Ġ= Ġtime table ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġ" O ops . ĠError Ġhappened ." ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Time table . Error ( message )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . station ). isEqualTo ( null ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . timetable ). isEmpty () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Time table ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . loading Time table Failed ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . errorMessage ). isEqualTo ( message ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠSettings Updated Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState () ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSettings Updated ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( Train . Category . Com mut er ), Ġset Of ( Time table Row . Type . Arrival ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . selected Time table Types ). contains Exactly ( Time table Row . Type . Arrival ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . selected Train Categories ). contains Exactly ( Train . Category . Com mut er ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠSettings Updated Ġresult Ġcontaining Ġonly Ġtrain Ġcategory `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġselected Train Categories Ġ= Ġset Of ( Train . Category . Com mut er ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġselected Time table Types Ġ= Ġset Of ( Time table Row . Type . Arrival ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSettings Updated ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( Train . Category . Long Distance ), Ġnull ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . selected Time table Types ). contains Exactly ( Time table Row . Type . Arrival ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . selected Train Categories ). contains Exactly ( Train . Category . Long Distance ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠRe load Time table _ Loading Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( isLoading Time table Ġ= Ġfalse , Ġis Re loading Time table Ġ= Ġfalse ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Reload Time table . Loading ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Time table ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . is Re loading Time table ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠRe load Time table _ Success Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Re loading Time table Ġ= Ġtrue , Ġstation Ġ= Ġpas ila , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtime table Ġ= ĠlistOf ( Train ( 1 , Ġ" A ", ĠTrain . Category . Long Distance )) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġtime table Ġ= ĠlistOf ( Train ( 2 , Ġ" B ", ĠTrain . Category . Com mut er )) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Reload Time table . Success ( timetable )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . is Re loading Time table ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . station ). isEqualTo ( pas ila ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . timetable ). isEqualTo ( timetable ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠRe load Time table _ Error Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Re loading Time table Ġ= Ġtrue , Ġstation Ġ= Ġpas ila , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtime table Ġ= ĠlistOf ( Train ( 1 , Ġ" A ", ĠTrain . Category . Long Distance )) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġ" Error !" ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Reload Time table . Error ( message )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . is Re loading Time table ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . errorMessage ). isEqualTo ( message ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Station Names _ Loading Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( isLoading Station Names Ġ= Ġfalse ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= Ġstate . copy ( isLoading Station Names Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Station Names . Loading ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result ). isEqualTo ( expected ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Station Names _ Success Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( isLoading Station Names Ġ= Ġtrue , Ġstation Name Mapper Ġ= Ġnull ) ĊĠĠĠĠĠĠĠ Ġval Ġmapper Ġ= ĠStation Name Mapper Ġ{ Ġstation Code Ġ-> Ġ" Station Ġ$ station Code " Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Station Names . Success ( mapper )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Station Names ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . station Name Mapper ). isEqualTo ( mapper ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Station Names _ Error Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( isLoading Station Names Ġ= Ġtrue , Ġstation Name Mapper Ġ= Ġnull ) ĊĠĠĠĠĠĠĠ Ġval ĠerrorMessage Ġ= Ġ" Something ." ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Station Names . Error ( errorMessage )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Station Names ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . station Name Mapper ). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . errorMessage ). isEqualTo ( errorMessage ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Cause Categories _ Loading Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( isLoading Cause Categories Ġ= Ġfalse ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Cause Categories . Loading ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Cause Categories ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Cause Categories _ Success Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( isLoading Cause Categories Ġ= Ġtrue , Ġcause Categories Ġ= Ġnull ) ĊĠĠĠĠĠĠĠ Ġval Ġcategories Ġ= ĠlistOf ( Cause Category ( 1 , Ġ" First ")) ĊĠĠĠĠĠĠĠ Ġval Ġdetailed Categories Ġ= ĠlistOf ( Cause Category ( 2 , Ġ" Second ")) ĊĠĠĠĠĠĠĠ Ġval Ġcause Categories Ġ= ĠCause Categories ( categories , Ġdetailed Categories ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Cause Categories . Success ( cause Categories )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Cause Categories ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . cause Categories ). isEqualTo ( cause Categories ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` reduce Ġstate Ġwith ĠLoad Cause Categories _ Error Ġresult `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= ĠTime table ViewState ( isLoading Cause Categories Ġ= Ġtrue , ĠerrorMessage Ġ= Ġnull ) ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġ" Something ." ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġstate . reduce ( Load Cause Categories . Error ( message )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . isLoading Cause Categories ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . errorMessage ). isEqualTo ( message ) ĊĠĠĠ Ġ} Ċ } Ċ