package Ġdk . cache t . car p . protocols . domain . configuration Ċ Ċ import Ġdk . cache t . car p . common . application . devices . Any Device Configuration Ċ import Ġdk . cache t . car p . common . infrastructure . test . Stub Device Configuration Ċ import Ġdk . cache t . car p . common . infrastructure . test . Stub Primary Device Configuration Ċ import Ġkotlin . test .* ĊĊ Ċ /** Ċ Ġ* ĠBase Ġclass Ġwith Ġtests Ġfor Ġ[ Protocol Device Configuration ] Ġwhich Ġcan Ġbe Ġused Ġto Ġtest Ġextending Ġtypes . Ċ Ġ*/ Ċ interface ĠProtocol Device Configuration Test Ċ { ĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠCalled Ġfor Ġeach Ġtest Ġto Ġcreate Ġa Ġdevice Ġconfiguration Ġto Ġrun Ġtests Ġon . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġfun Ġcreate Device Configuration (): ĠProtocol Device Configuration ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd Primary Device _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device Ġ= ĠStub Primary Device Configuration () ĊĊĠĠĠĠĠĠĠ Ġval Ġis Added Ġ= Ġconfiguration . add Primary Device ( Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġis Added Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġconfiguration . primary Devices . contains ( Ġprimary Device Ġ) Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġonly _ devices _ added _ as _ add Primary Device _ show _ up _ in _ primary devices () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device Ġ= ĠStub Primary Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġchained Primary Device Ġ= ĠStub Primary Device Configuration ( Ġ" Chain ed " Ġ) ĊĊĠĠĠĠĠĠĠ Ġconfiguration . add Primary Device ( Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ Ġconfiguration . add Connected Device ( Ġchained Primary Device , Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġconfiguration . primary Devices . count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd Connected Device _ suc ceeds () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device Ġ= ĠStub Primary Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġconnected Device Ġ= ĠStub Device Configuration () ĊĠĠĠĠĠĠĠ Ġconfiguration . add Primary Device ( Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 0 , Ġconfiguration . get Connected Devices ( Ġprimary Device Ġ). count () Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġis Added : ĠBoolean Ġ= Ġconfiguration . add Connected Device ( Ġconnected Device , Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġis Added Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġconnected Device , Ġconfiguration . get Connected Devices ( Ġprimary Device Ġ). single () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdevices _ lists _ the _ full _ list _ of _ devices _ without _ duplicates () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device 1 Ġ= ĠStub Primary Device Configuration ( Ġ" Device Ġ 1 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device 2 Ġ= ĠStub Primary Device Configuration ( Ġ" Device Ġ 2 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġconnected Device Ġ= ĠStub Device Configuration ( Ġ" Device Ġ 3 " Ġ) ĊĠĠĠĠĠĠĠ Ġwith Ġ( Ġconfiguration Ġ) ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Primary Device ( Ġprimary Device 1 Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Primary Device ( Ġprimary Device 2 Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Connected Device ( Ġconnected Device , Ġprimary Device 1 Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Connected Device ( Ġconnected Device , Ġprimary Device 2 Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 3 , Ġconfiguration . devices . count () Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġconfiguration . devices . contains ( Ġprimary Device 1 Ġ) Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġconfiguration . devices . contains ( Ġprimary Device 2 Ġ) Ġ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Ġconfiguration . devices . contains ( Ġconnected Device Ġ) Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd Primary Device _ multiple _ times _ only _ adds _ first _ time () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device Ġ= ĠStub Primary Device Configuration () ĊĠĠĠĠĠĠĠ Ġconfiguration . add Primary Device ( Ġprimary Device Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġis Added : ĠBoolean Ġ= Ġconfiguration . add Primary Device ( Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Ġis Added Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġconfiguration . primary Devices . count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd Connected Device _ multiple _ times _ only _ adds _ first _ time () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device Ġ= ĠStub Primary Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġconnected Device Ġ= ĠStub Device Configuration () ĊĠĠĠĠĠĠĠ Ġconfiguration . add Primary Device ( Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ Ġconfiguration . add Connected Device ( Ġconnected Device , Ġprimary Device Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġis Added : ĠBoolean Ġ= Ġconfiguration . add Connected Device ( Ġconnected Device , Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Ġis Added Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġ 1 , Ġconfiguration . get Connected Devices ( Ġprimary Device Ġ). count () Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdo _ not _ allow _ duplicate _ role _ names _ for _ devices () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary Device Ġ= ĠStub Primary Device Configuration ( Ġ" Unique Ġname " Ġ) ĊĠĠĠĠĠĠĠ Ġconfiguration . add Primary Device ( Ġprimary Device Ġ) ĊĠĠĠĠĠĠĠ Ġconfiguration . add Connected Device ( ĠStub Device Configuration ( Ġ" Duplicate Ġname " Ġ), Ġprimary Device Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAdding Ġan Ġadditional Ġprimary Ġdevice Ġwith Ġduplicate Ġname Ġshould Ġfail . ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . add Primary Device ( ĠStub Primary Device Configuration ( Ġ" Duplicate Ġname " Ġ) Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcant _ add Connected Device _ for _ non existing _ primary _ device () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . add Connected Device ( ĠStub Device Configuration (), ĠStub Primary Device Configuration () Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcant _ get Connected Devices _ for _ non existing _ primary _ device () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . get Connected Devices ( ĠStub Primary Device Configuration () Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Connected Devices _ with _ include Chain ed Devices _ returns _ all _ underlying _ devices () ĊĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Device Configuration () ĊĠĠĠĠĠĠĠ Ġval Ġprimary 1 Ġ= ĠStub Primary Device Configuration ( Ġ" Primary Ġ 1 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġprimary 2 Ġ= ĠStub Primary Device Configuration ( Ġ" Primary Ġ 2 " Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġconnected Ġ= ĠStub Device Configuration ( Ġ" Connected " Ġ) ĊĠĠĠĠĠĠĠ Ġwith Ġ( Ġconfiguration Ġ) ĊĠĠĠĠĠĠĠ Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Primary Device ( Ġprimary 1 Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Connected Device ( Ġprimary 2 , Ġprimary 1 Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Connected Device ( Ġconnected , Ġprimary 2 Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġunderlying Devices : ĠIterable < Any Device Configuration > Ġ= Ġconfiguration . get Connected Devices ( Ġprimary 1 , Ġtrue Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Devices Ġ= Ġset Of ( Ġprimary 2 , Ġconnected Ġ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Ġexpected Devices . count (), Ġunderlying Devices . intersect ( Ġexpected Devices Ġ). count () Ġ) ĊĠĠĠ Ġ} Ċ } Ċ