package Ġcom . pre z . lib . tracing Ċ Ċ import Ġbr ave . Span Customizer Ċ import Ġcom . pre z . ws . Web ServiceException Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . jupiter . api . Assertions . assert Throws Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . junit . jupiter . Mockito Extension Ċ import Ġorg . springframework . http . HttpMethod . GET Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . HttpStatus . SERVICE _ UN AVAILABLE Ċ import Ġorg . springframework . web . reactive . function . client . Client Request Ċ import Ġorg . springframework . web . reactive . function . client . ClientResponse Ċ import Ġorg . springframework . web . reactive . function . client . Exchange Function Ċ import Ġreactor . core . publisher . Mono Ċ import Ġjava . net . URI ĊĊ Ċ @ Extend With ( Mockito Extension :: class ) Ċ internal Ġclass ĠSpan Custom ization Web Client Filter Test Ġ{ ĊĠ Ġ@ Mock ĊĠ Ġprivate Ġlateinit Ġvar Ġmock Span : ĠSpan Customizer ĊĊĠ Ġprivate Ġlateinit Ġvar Ġto Test : ĠSpan Custom ization Web Client Filter ĊĊĠ Ġ@ BeforeEach ĊĠ Ġfun Ġinit () Ġ{ ĊĠĠĠ Ġto Test Ġ= ĠSpan Custom ization Web Client Filter (" fancy Service ", Ġmock Span ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Exception :: class ) ĊĠ Ġfun Ġ` filter Ġshould Ġtag Ġspan Ġwith Ġhttp Ġstatus Ġcode Ġand Ġerror Ġinfo Ġwhen Ġpartner Ġexception Ġthrown `() Ġ{ ĊĠĠĠ Ġ// ĠGiven ĊĠĠĠ Ġval Ġpartner Fail Ġ= ĠExchange Function Ġ{ ĊĠĠĠĠĠ ĠMono . error ( ĊĠĠĠĠĠĠĠ ĠWeb ServiceException ( ĊĠĠĠĠĠĠĠĠĠ Ġweb ServiceName Ġ= Ġ" fancy Service ", Ġhttp StatusCode Ġ= ĠSERVICE _ UN AVAILABLE , ĊĠĠĠĠĠĠĠĠĠ Ġerror Description Ġ= Ġ" Yes , Ġas Ġsur prising Ġas Ġit Ġcan Ġbe Ġweb Ġservices Ġdo Ġfail !" ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġclient Request Ġ= ĠClient Request . create ( GET , ĠURI (" http :// url ")). build () ĊĊĠĠĠ Ġ// ĠWhen ĊĠĠĠ Ġval Ġpartner Exception Ġ= ĠassertThrows ( Web ServiceException :: class . java ) Ġ{ ĊĠĠĠĠĠ Ġto Test . filter ( client Request , Ġpartner Fail ). block () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠThen ĊĠĠĠ ĠassertThat ( partner Exception ). isNotNull ĊĠĠĠ ĠMockito . verify ( mock Span , ĠMockito . times ( 2 )). tag (" web Service ", Ġ" fancy Service ") ĊĠĠĠ ĠMockito . verify ( mock Span ). tag (" http . statusCode ", Ġ" 5 0 3 ") ĊĠĠĠ ĠMockito . verify ( mock Span ). tag (" error ", Ġ" 5 0 3 ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Exception :: class ) ĊĠ Ġfun Ġ` filter Ġshould Ġtag Ġspan Ġerror Ġinfo Ġwhen Ġrandom Ġexception Ġthrown `() Ġ{ ĊĠĠĠ Ġ// ĠGiven ĊĠĠĠ Ġval Ġfail Exchange Ġ= ĠExchange Function Ġ{ ĠMono . error ( NullPointerException (" Y et Ġanother Ġrandom Ġexception ")) Ġ} ĊĠĠĠ Ġval Ġclient Request Ġ= ĠClient Request . create ( GET , ĠURI (" http :// url ")). build () ĊĊĠĠĠ Ġ// ĠWhen ĊĠĠĠ Ġval Ġpartner Exception Ġ= ĠassertThrows ( NullPointerException :: class . java ) Ġ{ ĊĠĠĠĠĠ Ġto Test . filter ( client Request , Ġfail Exchange ). block () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠThen ĊĠĠĠ ĠassertThat ( partner Exception ). isNotNull ĊĠĠĠ ĠMockito . verify ( mock Span ). tag (" web Service ", Ġ" fancy Service ") ĊĠĠĠ ĠMockito . verify ( mock Span ). tag (" error ", Ġ" java . lang . NullPointerException ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ Throws ( Exception :: class ) ĊĠ Ġfun Ġ` filter Ġshould Ġtag Ġspan Ġwith Ġhttp Ġstatus Ġcode Ġwhen Ġno Ġerror `() Ġ{ ĊĠĠĠ Ġ// ĠGiven ĊĠĠĠ Ġval Ġsuccess Exchange Ġ= ĠExchange Function Ġ{ ĠMono . just ( ClientResponse . create ( HttpStatus . CREATED ). build ()) Ġ} ĊĠĠĠ Ġval Ġclient Request Ġ= ĠClient Request . create ( GET , ĠURI (" http :// url ")). build () ĊĊĠĠĠ Ġ// ĠWhen ĊĠĠĠ Ġto Test . filter ( client Request , Ġsuccess Exchange ). block () ĊĊĠĠĠ Ġ// ĠThen ĊĠĠĠ ĠMockito . verify ( mock Span ). tag (" web Service ", Ġ" fancy Service ") ĊĠĠĠ ĠMockito . verify ( mock Span ). tag (" http . statusCode ", Ġ" 2 0 1 ") ĊĠ Ġ} Ċ }