package Ġcom . el pass ion . android . commons . shared preferences Ċ Ċ import Ġandroidx . test . runner . Android JUnit 4 Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mockito . verify Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠAs Property WithDefault Extension TestCase Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġrepository Ġ= Ġmock < Shared Preference Repository < String >>() ĊĠĠĠ Ġ// Ġtag :: shared preferences - as - property - with - default - declaration [] ĊĠĠĠ Ġprivate Ġvar Ġsecret Key WithDefault Ġby Ġrepository . as Property WithDefault (" secret - key ", Ġ" 1 2 3 4 5 6 7 8 ") ĊĠĠĠ Ġ// Ġend :: shared preferences - as - property - with - default - declaration [] ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Read DefaultValue When Repository IsEmpty () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 1 2 3 4 5 6 7 8 ", Ġsecret Key WithDefault ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Read Value From Repository () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( repository . read ( any ())). thenReturn (" 1 2 3 4 5 6 7 8 ") ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" 1 2 3 4 5 6 7 8 ", Ġsecret Key WithDefault ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Write Value To Repository () Ġ{ ĊĠĠĠĠĠĠĠ Ġsecret Key WithDefault Ġ= Ġ" new - key " ĊĠĠĠĠĠĠĠ Ġverify ( repository ). write (" secret - key ", Ġ" new - key ") ĊĠĠĠ Ġ} Ċ }