/* Ċ Ġ* ĠCopyright Ġ( C ) Ġ 2 0 2 0 ĠThe ĠAndroid ĠOpen ĠSource ĠProject Ċ Ġ* Ċ Ġ* Ġ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 . android . tools . adt ui . model Ċ Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . rules . Expected Exception Ċ import Ġjavax . swing . Row Sorter Ċ import Ġjavax . swing . SortOrder Ċ Ċ class ĠAbstract Pag inated TableModel Test Ġ{ ĊĠ Ġ@ get : Rule ĊĠ Ġval Ġthrown : ĠExpected Exception Ġ= ĠExpected Exception . none () ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġpage Count () Ġ{ ĊĠĠĠ ĠassertThat ( Pag inated ListModel ( 1 , Ġmutable ListOf ( 1 , Ġ 2 , Ġ 3 )). page Count ). isEqualTo ( 3 ) ĊĠĠĠ ĠassertThat ( Pag inated ListModel ( 2 , Ġmutable ListOf ( 1 , Ġ 2 , Ġ 3 )). page Count ). isEqualTo ( 2 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġrow Count () Ġ{ ĊĠĠĠ Ġval Ġdiv isible By Page Ġ= ĠPag inated ListModel ( 2 , Ġmutable ListOf ( 1 , Ġ 2 , Ġ 3 , Ġ 4 )) ĊĠĠĠ ĠassertThat ( div isible By Page . rowCount ). isEqualTo ( 2 ) ĊĠĠĠ Ġdiv isible By Page . goTo Last Page () ĊĠĠĠ ĠassertThat ( div isible By Page . rowCount ). isEqualTo ( 2 ) ĊĊĠĠĠ Ġval Ġin div isible By Page Ġ= ĠPag inated ListModel ( 3 , Ġmutable ListOf ( 1 , Ġ 2 , Ġ 3 , Ġ 4 )) ĊĠĠĠ ĠassertThat ( in div isible By Page . rowCount ). isEqualTo ( 3 ) ĊĠĠĠ Ġin div isible By Page . goTo Last Page () ĊĠĠĠ ĠassertThat ( in div isible By Page . rowCount ). isEqualTo ( 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġpage Navigation () Ġ{ ĊĠĠĠ Ġval Ġmodel Ġ= ĠPag inated ListModel ( 1 , Ġmutable ListOf ( 1 , Ġ 2 , Ġ 3 )) ĊĠĠĠ ĠassertThat ( model . is On First Page ). isTrue () ĊĠĠĠ ĠassertThat ( model . is On Last Page ). isFalse () ĊĊĠĠĠ Ġmodel . goTo Next Page () ĊĠĠĠ ĠassertThat ( model . is On First Page ). isFalse () ĊĠĠĠ ĠassertThat ( model . is On Last Page ). isFalse () ĊĊĠĠĠ Ġmodel . goTo Prev Page () ĊĠĠĠ ĠassertThat ( model . is On First Page ). isTrue () ĊĠĠĠ ĠassertThat ( model . is On Last Page ). isFalse () ĊĊĠĠĠ Ġmodel . goTo Last Page () ĊĠĠĠ ĠassertThat ( model . is On First Page ). isFalse () ĊĠĠĠ ĠassertThat ( model . is On Last Page ). isTrue () ĊĊĠĠĠ Ġmodel . goTo First Page () ĊĠĠĠ ĠassertThat ( model . is On First Page ). isTrue () ĊĠĠĠ ĠassertThat ( model . is On Last Page ). isFalse () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠpageSize Must Be Positive () Ġ{ ĊĠĠĠ Ġthrown . expect ( IllegalArgumentException :: class . java ) ĊĠĠĠ Ġthrown . expect Message (" Page Ġsize Ġmust Ġbe Ġpositive , Ġwas Ġ- 1 ") ĊĠĠĠ ĠPag inated ListModel (- 1 , Ġmutable ListOf ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtable With Empty Data Should Have Zero Rows () Ġ{ ĊĠĠĠ Ġval Ġmodel Ġ= ĠPag inated ListModel ( 1 0 , Ġmutable ListOf ()) ĊĠĠĠ ĠassertThat ( model . rowCount ). isEqualTo ( 0 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠpageSize Can Be Changed () Ġ{ ĊĠĠĠ Ġval Ġmodel Ġ= ĠPag inated ListModel ( 3 , Ġ( 1 .. 6 ). to Mutable List ()) ĊĊĠĠĠ Ġ// ĠChanging Ġpage Ġsize Ġshould Ġchange Ġvisible Ġrows . ĊĠĠĠ Ġmodel . update PageSize ( 4 ) ĊĠĠĠ ĠassertThat ( model . rowCount ). isEqualTo ( 4 ) ĊĊĠĠĠ Ġ// ĠChanging Ġpage Ġsize Ġshould Ġreset Ġthe Ġcurrent Ġpage Ġindex . ĊĠĠĠ Ġmodel . goTo Next Page () ĊĠĠĠ Ġmodel . update PageSize ( 3 ) ĊĠĠĠ ĠassertThat ( model . rowCount ). isEqualTo ( 3 ) ĊĠĠĠ ĠassertThat ( model . page Index ). isEqualTo ( 0 ) ĊĊĠĠĠ Ġ// ĠKeep ing Ġthe Ġsame Ġpage Ġsize Ġshould Ġnot Ġreset Ġthe Ġpage Ġindex . ĊĠĠĠ Ġmodel . goTo Last Page () ĊĠĠĠ Ġmodel . update PageSize ( 3 ) ĊĠĠĠ ĠassertThat ( model . rowCount ). isEqualTo ( 3 ) ĊĠĠĠ ĠassertThat ( model . page Index ). isEqualTo ( 1 ) ĊĠ Ġ} Ċ } Ċ Ċ class ĠPag inated ListModel ( pageSize : ĠInt , Ġval Ġdata : ĠMutable List < Int >) Ġ: ĠAbstract Pag inated TableModel ( pageSize ) Ġ{ ĊĠ Ġoverride Ġfun ĠgetData Size (): ĠInt Ġ{ ĊĠĠĠ Ġreturn Ġdata . size ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠgetData Value At ( data Index : ĠInt , ĠcolumnIndex : ĠInt ): ĠAny Ġ{ ĊĠĠĠ Ġreturn Ġdata [ data Index ] ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġsort Data ( sort Keys : ĠList < Row Sorter . Sort Key >) Ġ{ ĊĠĠĠ Ġif Ġ( sort Keys [ 0 ]. sort Order Ġ== ĠSort Order . ASC ENDING ) Ġ{ ĊĠĠĠĠĠ Ġdata . sort () ĊĠĠĠ Ġ} ĊĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠ Ġdata . sort Descending () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget Column Count (): ĠInt Ġ{ ĊĠĠĠ Ġreturn Ġ 1 ĊĠ Ġ} Ċ }