package Ġcom . m ct ech . stock trade tracking . domain . stock _ share . interaction Ċ Ċ import Ġcom . m ct ech . library . logger . Logger Ċ import Ġcom . m ct ech . stock trade tracking . domain . stock _ share . service . Stock Share Service Ċ import Ġcom . m ct ech . stock trade tracking . testing . data _ factory . factories . Stock Share Data Factory Ċ import Ġcom . m ct ech . stock trade tracking . testing . data _ factory . test Scenario Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . any Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . times Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ class ĠSplit Stock Share Case Test Ġ{ ĊĠ Ġprivate Ġlateinit Ġvar Ġuse Case : ĠSplit Stock Share Case ĊĊĠ Ġprivate Ġval Ġservice Ġ= Ġmock < Stock Share Service >() ĊĠ Ġprivate Ġval Ġlogger Ġ= Ġmock < Logger >() ĊĊĠ Ġprivate Ġval Ġexpected Items Ġ= ĠStock Share Data Factory . split List () ĊĠ Ġprivate Ġval Ġexpected Error Ġ= ĠRuntimeException () ĊĠ Ġprivate Ġval Ġstock Input Ġ= ĠStock Share Data Factory . single ( code Ġ= Ġ" MGL U 3 ") ĊĊĊĠ Ġ@ Before ĊĠ Ġfun Ġ` before Ġeach Ġtest `() Ġ{ ĊĠĠĠ Ġuse Case Ġ= ĠSplit Stock Share Case ( service , Ġlogger ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` should Ġlog Ġerror Ġwhile Ġloading `() Ġ= Ġtest Scenario ( ĊĠĠĠ Ġscenario Ġ= Ġ{ ĊĠĠĠĠĠ Ġwhenever ( service . getAll By Code ( any ())). then Throw ( expected Error ) ĊĠĠĠ Ġ}, ĊĠĠĠ Ġaction Ġ= Ġ{ ĊĠĠĠĠĠ Ġuse Case . execute ( share Ġ= Ġstock Input , Ġsplit Ratio Ġ= Ġ 4 ) ĊĠĠĠ Ġ}, ĊĠĠĠ Ġassertions Ġ= Ġ{ ĊĠĠĠĠĠ Ġverify ( logger ). e ( e Ġ= Ġexpected Error ) ĊĠĠĠ Ġ} ĊĠ Ġ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` should Ġlog Ġerror Ġwhile Ġsaving `() Ġ= Ġtest Scenario ( ĊĠĠĠ Ġscenario Ġ= Ġ{ ĊĠĠĠĠĠ Ġwhenever ( service . save Stock Share ( any ())). then Throw ( expected Error ) ĊĠĠĠĠĠ Ġwhenever ( service . getAll By Code ( any ())). thenReturn ( Stock Share Data Factory . listOf ( 3 )) ĊĠĠĠ Ġ}, ĊĠĠĠ Ġaction Ġ= Ġ{ ĊĠĠĠĠĠ Ġuse Case . execute ( share Ġ= Ġstock Input , Ġsplit Ratio Ġ= Ġ 4 ) ĊĠĠĠ Ġ}, ĊĠĠĠ Ġassertions Ġ= Ġ{ ĊĠĠĠĠĠ Ġverify ( logger ). e ( e Ġ= Ġexpected Error ) ĊĠĠĠ Ġ} ĊĠ Ġ) ĊĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` should Ġupdate Ġitems `() Ġ= Ġtest Scenario ( ĊĠĠĠ Ġscenario Ġ= Ġ{ ĊĠĠĠĠĠ Ġwhenever ( service . getAll By Code ( any ())). thenReturn ( expected Items ) ĊĠĠĠ Ġ}, ĊĠĠĠ Ġaction Ġ= Ġ{ ĊĠĠĠĠĠ Ġuse Case . execute ( share Ġ= Ġstock Input , Ġsplit Ratio Ġ= Ġ 4 ) ĊĠĠĠ Ġ}, ĊĠĠĠ Ġassertions Ġ= Ġ{ ĊĠĠĠĠĠ Ġverify ( service ). getAll By Code (" MGL U 3 ") ĊĠĠĠĠĠ Ġverify ( service , Ġtimes ( 2 )). save Stock Share ( any ()) ĊĊĠĠĠĠĠ Ġ// ĠLoad Ġfresh Ġlist Ġagain ĊĠĠĠĠĠ Ġval Ġvalidation List Ġ= ĠStock Share Data Factory . split List () ĊĊĠĠĠĠĠ Ġ// ĠAssert Ġfirst Ġitem ĊĠĠĠĠĠ Ġval Ġfirst Expected Ġ= Ġexpected Items [ 0 ] ĊĠĠĠĠĠ Ġval Ġfirst Fresh Ġ= Ġvalidation List [ 0 ] ĊĠĠĠĠĠ ĠassertThat ( first Expected . share Amount ). isEqualTo ( first Fresh . share Amount Ġ* Ġ 4 ) ĊĠĠĠĠĠ ĠassertThat ( first Expected . purchase Price ). isEqualTo ( ĊĠĠĠĠĠĠĠ Ġfirst Fresh . get Invest ment Value () Ġ/ Ġfirst Expected . share Amount ĊĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠ Ġ// ĠAssert Ġsecond Ġitem ĊĠĠĠĠĠ Ġval Ġsecond Expected Ġ= Ġexpected Items [ 1 ] ĊĠĠĠĠĠ Ġval Ġsecond Fresh Ġ= Ġvalidation List [ 1 ] ĊĠĠĠĠĠ ĠassertThat ( second Expected . share Amount ). isEqualTo ( second Fresh . share Amount Ġ* Ġ 4 ) ĊĠĠĠĠĠ ĠassertThat ( second Expected . purchase Price ). isEqualTo ( ĊĠĠĠĠĠĠĠ Ġsecond Fresh . get Invest ment Value () Ġ/ Ġsecond Expected . share Amount ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠ Ġ) Ċ }