package Ġcom . flight mode . app . service Ċ Ċ import Ġcom . flight mode . app . model . Air port Ċ import Ġcom . flight mode . app . model . City Ċ import Ġcom . flight mode . app . model . Flight Schedule Ċ import Ġcom . google . gson . JsonObject Ċ import Ġokhttp 3 . MediaType Ċ import Ġokhttp 3 . ResponseBody Ċ import Ġorg . junit . Assert . assertFalse Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġretrofit 2 . Call Ċ import Ġretrofit 2 . Response Ċ import Ġretrofit 2 . Ret rofit Ċ import Ġretrofit 2 . converter . gson . Gson Converter Factory Ċ import Ġretrofit 2 . mock . Behavior Delegate Ċ import Ġretrofit 2 . mock . Calls Ċ import Ġretrofit 2 . mock . Mock Ret rofit Ċ import Ġretrofit 2 . mock . Network Behavior Ċ Ċ class ĠA viation Edge Service Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġretrofit : ĠRet rofit ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġdelegate Av iation Edge Service : ĠBehavior Delegate < Av iation Edge Service > ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Ret rofit : ĠMock Ret rofit ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Error Service Call : ĠMock Error Service Call ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Success Service Call : ĠMock Success Service Call ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġretrofit Ġ= ĠRet rofit . Builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. baseUrl ( Av iation Edge Service . BASE _ URL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. add Converter Factory ( Gson Converter Factory . create ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ Ġval Ġbehavior Ġ= ĠNetwork Behavior . create () ĊĊĠĠĠĠĠĠĠ Ġmock Ret rofit Ġ= ĠMock Ret rofit . Builder ( ret rofit ). network Behavior ( behavior ). build () ĊĠĠĠĠĠĠĠ Ġdelegate Av iation Edge Service Ġ= Ġmock Ret rofit . create ( Av iation Edge Service :: class . java ) ĊĠĠĠĠĠĠĠ Ġmock Error Service Call Ġ= ĠMock Error Service Call ( delegate Av iation Edge Service ) ĊĠĠĠĠĠĠĠ Ġmock Success Service Call Ġ= ĠMock Success Service Call ( delegate Av iation Edge Service ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetInstance _ should _ return _ an _ instant _ of _ the _ Av iation Edges Service () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertTrue ( Av iation Edge Service :: class . java . is Instance ( Av iation Edge Service . getInstance ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Near by Air ports _ should _ return _ an _ error _ response _ when _ the _ api _ returns _ an _ error _ response () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcall Ġ= Ġmock Error Service Call . get Near by Air ports ( lat Ġ= Ġ"- 5 . 4 6 6 6 6 7 ", Ġlng Ġ= Ġ" 1 2 2 . 6 3 3 3 3 ", Ġdistance Ġ= Ġ" 1 0 0 ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcall . execute () ĊĊĠĠĠĠĠĠĠ ĠassertFalse ( response . is Successful ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Near by Air ports _ should _ return _ a _ success _ response _ when _ the _ api _ returns _ a _ success _ response () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcall Ġ= Ġmock Success Service Call . get Near by Air ports ( lat Ġ= Ġ"- 5 . 4 6 6 6 6 7 ", Ġlng Ġ= Ġ" 1 2 2 . 6 3 3 3 3 ", Ġdistance Ġ= Ġ" 1 0 0 ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcall . execute () ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( response . is Successful ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Air ports Schedule _ should _ return _ an _ error _ response _ when _ the _ api _ returns _ an _ error _ response () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcall Ġ= Ġmock Error Service Call . get Air ports Schedule ( i ata Code Ġ= Ġ" J FK ", Ġtype Ġ= Ġ" depart ure ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcall . execute () ĊĊĠĠĠĠĠĠĠ ĠassertFalse ( response . is Successful ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Air ports Schedule _ should _ return _ a _ success _ response _ when _ the _ api _ returns _ a _ success _ response () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcall Ġ= Ġmock Success Service Call . get Air ports Schedule ( i ata Code Ġ= Ġ" J FK ", Ġtype Ġ= Ġ" depart ure ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcall . execute () ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( response . is Successful ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget City _ should _ return _ an _ error _ response _ when _ the _ api _ returns _ an _ error _ response () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcall Ġ= Ġmock Error Service Call . get City ( i ata Code Ġ= Ġ" J FK ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcall . execute () ĊĊĠĠĠĠĠĠĠ ĠassertFalse ( response . is Successful ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget City _ should _ return _ a _ success _ response _ when _ the _ api _ returns _ a _ success _ response () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcall Ġ= Ġmock Success Service Call . get City ( i ata Code Ġ= Ġ" J FK ") ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġcall . execute () ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( response . is Successful ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġclass ĠMock Error Service Call ( private Ġval Ġservice : ĠBehavior Delegate < Av iation Edge Service >) Ġ: ĠA viation Edge Service Ġ{ ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Near by Air ports ( incorrect ApiKey : ĠString , Ġlat : ĠString , Ġlng : ĠString , Ġdistance : ĠString ): ĠCall < List < Air port >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġservice . return ing ( Calls . response ( error Response )). get Near by Air ports ( lat Ġ= Ġlat , Ġlng Ġ= Ġlng , Ġdistance Ġ= Ġdistance ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Air ports Schedule ( incorrect ApiKey : ĠString , Ġi ata Code : ĠString , Ġtype : ĠString ): ĠCall < List < Flight Schedule >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġservice . return ing ( Calls . response ( error Response )). get Air ports Schedule ( i ata Code Ġ= Ġi ata Code , Ġtype Ġ= Ġtype ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget City ( incorrect ApiKey : ĠString , Ġi ata Code : ĠString ): ĠCall < List < City >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġservice . return ing ( Calls . response ( error Response )). get City ( i ata Code Ġ= Ġi ata Code ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġclass ĠMock Success Service Call ( private Ġval Ġservice : ĠBehavior Delegate < Av iation Edge Service >) Ġ: ĠA viation Edge Service Ġ{ ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Near by Air ports ( key : ĠString , Ġlat : ĠString , Ġlng : ĠString , Ġdistance : ĠString ): ĠCall < List < Air port >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġservice . return ing Response ( Response . success ( listOf < Air port >() )). get Near by Air ports ( key , Ġlat , Ġlng , Ġdistance ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Air ports Schedule ( apiKey : ĠString , Ġi ata Code : ĠString , Ġtype : ĠString ): ĠCall < List < Flight Schedule >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġservice . return ing Response ( Response . success ( listOf < Flight Schedule >() )). get Air ports Schedule ( apiKey , Ġi ata Code , Ġtype ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget City ( apiKey : ĠString , Ġi ata Code : ĠString ): ĠCall < List < City >> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġservice . return ing Response ( Response . success ( listOf < City >() )). get City ( apiKey , Ġi ata Code ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġerror Response Ġ= ĠResponse . error < JsonObject >( ĊĠĠĠĠĠĠĠĠ 4 0 4 , ĠResponse Body . create ( MediaType . parse (" application / json "), ĠMock ErrorResponse . DATA ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ Ċ }