package Ġcom . back base . test . inst anti ator Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertFalse Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mock Ċ Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ import Ġjava . util . Arrays Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠBack base ĠR & D ĠB . V . Ġon Ġ 1 8 / 0 2 / 2 0 1 9 . Ċ Ġ*/ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠComposite Instanti ator Test Ġ{ ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġinstanti ator 1 : ĠInstanti ator ĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġinstanti ator 2 : ĠInstanti ator ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġinstanti ator : ĠComposite Instanti ator ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġinstanti ator Ġ= ĠComposite Instanti ator ( inst anti ator 1 , Ġinstanti ator 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` supports Ġwith Ġany Ġsupporting ĠInstanti ator Ġreturns Ġtrue `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Class Ġ= ĠString :: class . java ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . supports ( test Class )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . supports ( test Class )). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( inst anti ator . supports ( test Class )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` supports Ġwith Ġno Ġsupporting ĠInstanti ator Ġreturns Ġfalse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Class Ġ= ĠString :: class . java ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . supports ( test Class )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . supports ( test Class )). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠ ĠassertFalse ( inst anti ator . supports ( test Class )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` supports Ġwith Ġlist Ġconstructor Ġand Ġsupporting ĠInstanti ator Ġreturns Ġtrue `() Ġ{ ĊĠĠĠĠĠĠĠ Ġinstanti ator Ġ= ĠComposite Instanti ator ( Arrays . asList ( inst anti ator 1 , Ġinstanti ator 2 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġtest Class Ġ= ĠString :: class . java ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . supports ( test Class )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . supports ( test Class )). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( inst anti ator . supports ( test Class )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` instantiate Supported Type Ġwith Ġmultiple Ġsupporting ĠInstanti ators Ġreturns Ġfirst Ġinstance `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Class Ġ= ĠString :: class . java ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . supports ( test Class )). thenReturn ( true ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . instantiate ( test Class )). thenReturn (" 1 ") ĊĊĠĠĠĠĠĠĠ ĠassertEquals (" 1 ", Ġinstanti ator . instantiate ( test Class )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` instantiate Supported Type Ġwith Ġ 1 Ġsupporting ĠInstanti ator Ġreturns Ġinstance `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Class Ġ= ĠString :: class . java ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . supports ( test Class )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . supports ( test Class )). thenReturn ( true ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . instantiate ( test Class )). thenReturn (" 2 ") ĊĊĠĠĠĠĠĠĠ ĠassertEquals (" 2 ", Ġinstanti ator . instantiate ( test Class )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠUnsupportedOperationException :: class ) ĊĠĠĠ Ġfun Ġ` instantiate Supported Type Ġwith Ġno Ġsupporting ĠInstanti ator Ġthrows ĠUnsupportedOperationException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Class Ġ= ĠString :: class . java ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . supports ( test Class )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . supports ( test Class )). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠ Ġinstanti ator . instantiate ( test Class ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` instantiate Supported Type Ġwith Ġlist Ġconstructor Ġand Ġ 1 Ġsupporting ĠInstanti ator Ġreturns Ġinstance `() Ġ{ ĊĠĠĠĠĠĠĠ Ġinstanti ator Ġ= ĠComposite Instanti ator ( Arrays . asList ( inst anti ator 1 , Ġinstanti ator 2 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġtest Class Ġ= ĠString :: class . java ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 1 . supports ( test Class )). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . supports ( test Class )). thenReturn ( true ) ĊĠĠĠĠĠĠĠ Ġwhenever ( inst anti ator 2 . instantiate ( test Class )). thenReturn (" 2 ") ĊĊĠĠĠĠĠĠĠ ĠassertEquals (" 2 ", Ġinstanti ator . instantiate ( test Class )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠIllegalStateException :: class ) ĊĠĠĠ Ġfun Ġ` instantiate Supported Type Ġwith Ġunsupported Ġtype Ġthrows ĠIllegalArgumentException `() Ġ{ ĊĠĠĠĠĠĠĠ Ġinstanti ator . instantiate Supported Type ( Composite Instanti ator Test :: class . java ) ĊĠĠĠ Ġ} Ċ } Ċ