package Ġkt . mob ius . extras Ċ Ċ import Ġkt . mob ius . Recording Consumer Ċ import Ġkotlin . test . Before Test Ċ import Ġkotlin . test . Test Ċ import Ġkotlin . test . assert Fails With Ċ Ċ class ĠQueue ing Event Subject Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġevent Subject : ĠQueue ing Event Subject < String > ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġreceiver : ĠRecord ing Consumer < String > ĊĊĠĠĠ Ġ@ Before Test ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġevent Subject Ġ= ĠQueue ing Event Subject ( 3 ) ĊĠĠĠĠĠĠĠ Ġreceiver Ġ= ĠRecord ing Consumer () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Forward Events When Sub scribed () Ġ{ ĊĠĠĠĠĠĠĠ Ġevent Subject . subscribe ( receiver ) ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" hey ") ĊĠĠĠĠĠĠĠ Ġreceiver . assert Values (" hey ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Queue Events When Not Sub scribed () Ġ{ ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" hi ") ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" ho ") ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" to Ġthe Ġmin es Ġwe Ġgo ") ĊĠĠĠĠĠĠĠ Ġevent Subject . subscribe ( receiver ) ĊĠĠĠĠĠĠĠ Ġreceiver . assert Values (" hi ", Ġ" ho ", Ġ" to Ġthe Ġmin es Ġwe Ġgo ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Stop Sending Events When Subscription Disposed () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsubscription Ġ= Ġevent Subject . subscribe ( receiver ) ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" a ") ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" b ") ĊĠĠĠĠĠĠĠ Ġsubscription . dispose () ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" don 't Ġwant Ġto Ġsee Ġthis ") ĊĠĠĠĠĠĠĠ Ġreceiver . assert Values (" a ", Ġ" b ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Only Support AS ingle Subscriber () Ġ{ ĊĠĠĠĠĠĠĠ Ġevent Subject . subscribe ( receiver ) ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġevent Subject . subscribe ( Recording Consumer ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Support Un subscribe And Res ub scribe () Ġ{ ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" a ") ĊĠĠĠĠĠĠĠ Ġval Ġsubscription Ġ= Ġevent Subject . subscribe ( receiver ) ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" b ") ĊĠĠĠĠĠĠĠ Ġsubscription . dispose () ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" c ") ĊĠĠĠĠĠĠĠ Ġevent Subject . subscribe ( receiver ) ĊĠĠĠĠĠĠĠ Ġreceiver . assert Values (" a ", Ġ" b ", Ġ" c ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Throw When Capacity Exceeded () Ġ{ ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" a ") ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" b ") ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" c ") ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalStateException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġevent Subject . accept (" n oo , Ġtoo Ġmany Ġthings ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġunsubscribe ShouldBe Ide mpot ent () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġgiven Ġa Ġsubscription Ġthat Ġhas Ġbeen Ġdisposed ĊĠĠĠĠĠĠĠ Ġval Ġsubscription 1 Ġ= Ġevent Subject . subscribe ( receiver ) ĊĠĠĠĠĠĠĠ Ġsubscription 1 . dispose () ĊĊĠĠĠĠĠĠĠ Ġ// Ġand Ġa Ġnew Ġsubscription Ġhas Ġbeen Ġcreated ĊĠĠĠĠĠĠĠ Ġval Ġsubscription 2 Ġ= Ġevent Subject . subscribe ( receiver ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġwhen Ġthe Ġfirst Ġsubscription Ġis Ġdisposed Ġagain ĊĠĠĠĠĠĠĠ Ġsubscription 1 . dispose () ĊĊĠĠĠĠĠĠĠ Ġ// Ġthen Ġthe Ġsecond Ġsubscription Ġis Ġnot Ġdisposed ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" a ") ĊĊĠĠĠĠĠĠĠ Ġ// Ġand Ġdisposing Ġthe Ġsecond Ġsubscription Ġworks ĊĠĠĠĠĠĠĠ Ġsubscription 2 . dispose () ĊĠĠĠĠĠĠĠ Ġevent Subject . accept (" b ") ĊĠĠĠĠĠĠĠ Ġreceiver . assert Values (" a ") ĊĠĠĠ Ġ} Ċ }