package Ġjp . t aku ji 3 1 . ko reference . observable Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . SharedPreferences Ċ import Ġandroid . support . test . Instrumentation Registry Ċ import Ġandroid . support . test . runner . Android JUnit 4 Ċ import Ġjp . t aku ji 3 1 . ko reference . test . Test Ko reference Model Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . Runtime Environment Ċ import Ġkotlin . properties . Deleg ates Ċ import Ġkotlin . test . assert Fails With Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ class ĠKo reference Model Observable Test Ġ{ ĊĊĠĠĠ Ġvar Ġpref : ĠSharedPreferences Ġby ĠDeleg ates . notNull () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġpref Ġ= ĠRuntime Environment . application . get SharedPreferences (" test ", ĠContext . MODE _ PRIVATE ) ĊĠĠĠĠĠĠĠ Ġpref . edit (). clear (). apply () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġteardown () Ġ{ ĊĠĠĠĠĠĠĠ Ġpref . edit (). clear (). apply () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠgetValue As Single () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmodel Ġ= ĠTest Ko reference Model ( pref ) ĊĠĠĠĠĠĠĠ Ġmodel . stringValue Ġ= Ġ" this Ġis Ġobserved Ġvalue " ĊĊĠĠĠĠĠĠĠ Ġval Ġtest Subscriber Ġ= Ġmodel . getValue As Single ( Test Ko reference Model :: stringValue ). test () ĊĊĠĠĠĠĠĠĠ Ġtest Subscriber . assert Value (" this Ġis Ġobserved Ġvalue ") ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . getValue As Single ( Test Ko reference Model :: no Ko reference Property ). test () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġobserve () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmodel Ġ= ĠTest Ko reference Model ( pref ) ĊĠĠĠĠĠĠĠ Ġmodel . stringValue Ġ= Ġ" first Value " ĊĊĠĠĠĠĠĠĠ Ġval Ġtest Subscriber Ġ= Ġmodel . observe ( Test Ko reference Model :: stringValue ). test () ĊĊĠĠĠĠĠĠĠ Ġmodel . stringValue Ġ= Ġ" second Value " ĊĊĠĠĠĠĠĠĠ Ġtest Subscriber . await Count ( 2 ) ĊĊĠĠĠĠĠĠĠ Ġmodel . stringValue Ġ= Ġ" third Value " ĊĊĠĠĠĠĠĠĠ Ġtest Subscriber . await Count ( 3 ) ĊĊĠĠĠĠĠĠĠ Ġtest Subscriber . assert Values (" first Value ", Ġ" second Value ", Ġ" third Value ") ĊĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmodel . observe ( Test Ko reference Model :: no Ko reference Property ). test () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġprivate Property () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmodel Ġ= ĠTest Ko reference Model ( pref ) ĊĠĠĠĠĠĠĠ Ġmodel . put Private StringValue ( value Ġ= Ġ" first Value ") ĊĊĠĠĠĠĠĠĠ Ġval Ġtest Subscriber Ġ= Ġmodel . private StringValue Observable . test () ĊĊĠĠĠĠĠĠĠ Ġtest Subscriber . assert Value (" first Value ") ĊĊĠĠĠĠĠĠĠ Ġmodel . put Private StringValue ( value Ġ= Ġ" second Value ") ĊĊĠĠĠĠĠĠĠ Ġtest Subscriber . assert Values (" first Value ", Ġ" second Value ") ĊĊĠĠĠĠĠĠĠ Ġval Ġtest Single Subscriber Ġ= Ġmodel . private StringValue Single . test () ĊĊĠĠĠĠĠĠĠ Ġtest Single Subscriber . assert Value (" second Value ") ĊĠĠĠ Ġ} Ċ } Ċ