/* Ċ Ġ* ĠCopyright Ġ 2 0 0 2 - 2 0 1 9 Ġthe Ġoriginal Ġauthor Ġor Ġauthors . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttps :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġorg . springframework . core Ċ Ċ import Ġkotlinx . coroutines . Deferred Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . Global Scope Ċ import Ġkotlinx . coroutines . async Ċ import Ġkotlinx . coroutines . flow . Flow Ċ import Ġkotlinx . coroutines . flow . flow Ċ import Ġkotlinx . coroutines . flow . toList Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . jupiter . api . Assertions . assertEquals Ċ import Ġorg . junit . jupiter . api . Assertions . assertTrue Ċ import Ġorg . junit . jupiter . api . Assertions . fail Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . reactiv est ream s . Publisher Ċ import Ġreactor . core . publisher . Flux Ċ import Ġreactor . core . publisher . Mono Ċ import Ġreactor . test . Step Verifier Ċ import Ġjava . time . Duration Ċ import Ġkotlin . reflect . K Class Ċ Ċ @ Experimental Cor outines Api Ċ class ĠKotlin Reactive Adapter Registry Tests Ġ{ ĊĊ ĉ private Ġval Ġregistry Ġ= ĠReactive Adapter Registry . get Shared Instance () ĊĊ ĉ @ Test Ċ ĉ fun Ġdeferred To Publisher () Ġ{ Ċĉ ĉ val Ġsource Ġ= ĠGlobal Scope . async Ġ{ Ġ 1 Ġ} Ċĉ ĉ val Ġtarget : ĠPublisher < Int > Ġ= Ġget Adapter ( Deferred :: class ). to Publisher ( source ) Ċĉ ĉ assertTrue ( target Ġis ĠMono <* >, Ġ" Expected ĠMono ĠPublisher : Ġ" Ġ+ Ġtarget . java Class . name ) Ċĉ ĉ assertEquals ( 1 , Ġ( target Ġas ĠMono < Int >). block ( Duration . of Millis ( 1 0 0 0 ))) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġpublisher To Deferred () Ġ{ Ċĉ ĉ val Ġsource Ġ= ĠMono . just ( 1 ) Ċĉ ĉ val Ġtarget Ġ= Ġget Adapter ( Deferred :: class ). from Publisher ( source ) Ċĉ ĉ assertTrue ( target Ġis ĠDeferred <* >) Ċĉ ĉ assertEquals ( 1 , Ġrun Blocking Ġ{ Ġ( target Ġas ĠDeferred < *> ). await () Ġ}) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġflow To Publisher () Ġ{ Ċĉ ĉ val Ġsource Ġ= Ġflow Ġ{ Ċĉĉ ĉ emit ( 1 ) Ċĉĉ ĉ emit ( 2 ) Ċĉĉ ĉ emit ( 3 ) Ċĉ ĉ } Ċĉ ĉ val Ġtarget : ĠPublisher < Int > Ġ= Ġget Adapter ( Flow :: class ). to Publisher ( source ) Ċĉ ĉ assertTrue ( target Ġis ĠFlux <* >, Ġ" Expected ĠFlux ĠPublisher : Ġ" Ġ+ Ġtarget . java Class . name ) Ċĉ ĉ Step Verifier . create ( target ) Ċĉĉĉ ĉ . expect Next ( 1 ) Ċĉĉĉ ĉ . expect Next ( 2 ) Ċĉĉĉ ĉ . expect Next ( 3 ) Ċĉĉĉ ĉ . verify Complete () Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġpublisher To Flow () Ġ{ Ċĉ ĉ val Ġsource Ġ= ĠFlux . just ( 1 , Ġ 2 , Ġ 3 ) Ċĉ ĉ val Ġtarget Ġ= Ġget Adapter ( Flow :: class ). from Publisher ( source ) Ċĉ ĉ if Ġ( target Ġis ĠFlow <* >) Ġ{ Ċĉĉ ĉ assertEquals ( listOf ( 1 , Ġ 2 , Ġ 3 ), Ġ Ġrun Blocking Ġ{ Ġtarget . toList () Ġ}) Ċĉ ĉ } Ċĉ ĉ else Ġ{ Ċĉĉ ĉ fail () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġget Adapter ( reactive Type : ĠK Class < *> ): ĠReactive Adapter Ġ{ Ċĉ ĉ return Ġthis . registry . get Adapter ( reactive Type . java ) !! Ċ ĉ } Ċ } Ċ