/* Ċ Ġ* ĠÂ© Ġ 2 0 1 8 ĠMatch ĠGroup , ĠLLC . Ċ Ġ*/ Ċ Ċ package Ġcom . t inder . sc ar let . internal . service method Ċ Ċ 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 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . never Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . only Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . then Ċ import Ġcom . t inder . sc ar let . Event Ċ import Ġcom . t inder . sc ar let . internal . connection . Connection Ċ import Ġcom . t inder . sc ar let . stream adapter . rx java 2 . Flow able Stream Adapter Ċ import Ġio . reactivex . Flow able Ċ import Ġio . reactivex . Maybe Ċ import Ġio . reactivex . processors . Replay Processor Ċ import Ġio . reactivex . schedul ers . Test Scheduler Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ internal Ġclass ĠReceive Service Method Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġweb Socket Client Ġ= Ġmock < Connection >() ĊĠĠĠ Ġprivate Ġval Ġscheduler Ġ= ĠTest Scheduler () ĊĠĠĠ Ġprivate Ġval Ġevent Mapper Ġ= Ġmock < Event Mapper < Any >>() ĊĠĠĠ Ġprivate Ġval Ġservice Method Ġ= ĠService Method . Receive ( ĊĠĠĠĠĠĠĠ Ġevent Mapper , Ġweb Socket Client , Ġscheduler , ĠFlow able Stream Adapter () ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġexecute _ shouldBe Lazy () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġservice Method . execute () ĊĠĠĠĠĠĠĠ Ġscheduler . trigger Actions () ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ Ġthen ( web Socket Client ). should ( never ()). observe Event () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġexecute _ should Only Ob serve And Transform WebSocket Client Events () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠGiven ĊĠĠĠĠĠĠĠ Ġval Ġevent 1 Ġ= Ġmock < Event >() ĊĠĠĠĠĠĠĠ Ġval Ġevent 2 Ġ= Ġmock < Event >() ĊĠĠĠĠĠĠĠ Ġval Ġreplay Processor Ġ= ĠRe play Processor . create < Event >() ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply Ġ{ Ġon Next ( event 1 ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. apply Ġ{ Ġon Next ( event 2 ) Ġ} ĊĠĠĠĠĠĠĠ Ġgiven ( web Socket Client . observe Event ()). willReturn ( replay Processor ) ĊĠĠĠĠĠĠĠ Ġgiven ( event Mapper . map To Data ( any ())). willReturn ( Maybe . empty ()) ĊĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġval Ġflow able Ġ= Ġservice Method . execute () Ġas ĠFlow able < *> ĊĠĠĠĠĠĠĠ Ġval Ġtest Subscriber Ġ= Ġflow able . test () ĊĠĠĠĠĠĠĠ Ġscheduler . trigger Actions () ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ Ġthen ( web Socket Client ). should ( only ()). observe Event () ĊĠĠĠĠĠĠĠ Ġthen ( event Mapper ). should (). map To Data ( event 1 ) ĊĠĠĠĠĠĠĠ Ġthen ( event Mapper ). should (). map To Data ( event 2 ) ĊĠĠĠĠĠĠĠ Ġtest Subscriber . assertNot Terminated () ĊĠĠĠ Ġ} Ċ } Ċ