package Ġall an le wis . positions Ċ Ċ import Ġall an le wis . api . RestApi Ċ import Ġall an le wis . coin base . Coin base Limit Order Ċ import Ġall an le wis . coin base . Coin base Order Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Argument Matchers . any String Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . junit . jupiter . Mockito Extension Ċ import Ġreactor . core . publisher . Mono Ċ import Ġreactor . test . Step Verifier Ċ Ċ @ Extend With ( Mockito Extension :: class ) Ċ @ Suppress (" Reactive Streams Unused Publisher ") Ċ class ĠPosition Execution Test (@ Mock Ġprivate Ġval Ġrest Api : ĠRest Api ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġorder Done Ġ= ĠOrder Done ( rest Api , Ġ 3 ) ĊĠĠĠ Ġprivate Ġval Ġlimit Order Ġ= ĠCoin base Limit Order (" sell ", Ġ" 5 0 0 0 0 ", Ġ". 0 0 1 ", Ġ" BTC - USD ", Ġ" pid ", Ġ" cid ", Ġtrue ) ĊĠĠĠ Ġprivate Ġval Ġlimit Order Pending Ġ= ĠCoin base Order (" 2 ", Ġ" pending ", Ġ"", Ġ"", Ġ" limit ", Ġ" buy ", Ġ" BTC - USD ") ĊĠĠĠ Ġprivate Ġval Ġlimit Order Done Ġ= ĠCoin base Order (" 2 ", Ġ" done ", Ġ"", Ġ"", Ġ" limit ", Ġ" buy ", Ġ" BTC - USD ") ĊĠĠĠ Ġprivate Ġvar Ġcount Ġ= Ġ 0 ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġcount Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ ĠMockito .` when `( rest Api . post Order ( limit Order )). thenReturn ( Mono . just ( limit Order Pending )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġorder Done Happy Path () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito .` when `( rest Api . getOrder (" 2 ")). thenReturn ( Mono . just ( limit Order Done )) ĊĊĠĠĠĠĠĠĠ ĠStep Verifier . create ( order Done . execute ( limit Order )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Next ( limit Order Done ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. verify Complete () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġorder Done Never Found () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito .` when `( rest Api . getOrder (" 2 ")). thenReturn ( Mono . empty ()) ĊĊĠĠĠĠĠĠĠ ĠStep Verifier . create ( order Done . execute ( limit Order )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Next Count ( 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. verify ErrorMessage (" Retries Ġex hausted : Ġ 3 / 3 ") ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( rest Api , ĠMockito . times ( 4 )). getOrder ( any String ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġorder Done Never Done () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito .` when `( rest Api . getOrder (" 2 ")). thenReturn ( Mono . just ( limit Order Pending )) ĊĊĠĠĠĠĠĠĠ ĠStep Verifier . create ( order Done . execute ( limit Order )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Next Count ( 0 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. verify ErrorMessage (" Retries Ġex hausted : Ġ 3 / 3 ") ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( rest Api , ĠMockito . times ( 4 )). getOrder ( any String ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġorder Done Event ually Done () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito .` when `( rest Api . getOrder (" 2 ")). then Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhen Ġ( count ++) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 0 Ġ-> ĠMono . empty () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 Ġ-> ĠMono . just ( limit Order Pending ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> ĠMono . just ( limit Order Done ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠStep Verifier . create ( order Done . execute ( limit Order )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. expect Next ( limit Order Done ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. verify Complete () ĊĊĠĠĠĠĠĠĠ ĠMockito . verify ( rest Api , ĠMockito . times ( 3 )). getOrder ( any String ()) ĊĠĠĠ Ġ} Ċ Ċ }