package Ġcom . minder a . s ke leto id . analytics Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Bundle Ċ import Ġcom . minder a . s ke leto id . analytics . append ers . interfaces . I Analytics Appender Ċ import Ġcom . minder a . s ke leto id . analytics . interfaces . I Analytics Manager Ċ import Ġcom . minder a . s ke leto id . logs . LOG . init Ċ import Ġcom . minder a . s ke leto id . utils . extensions . mock Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mockito Ċ import Ġjava . util . ArrayList Ċ import Ġjava . util . HashMap Ċ import Ġjava . util . HashSet Ċ Ċ class ĠAnalytics Manager UnitTest Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠpackageName Ġ= Ġ" my . package . name " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcontext : ĠContext ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġcontext Ġ= ĠMockito . mock ( Context :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Add Append ers Empty () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers Ids Ġ= Ġanalytics Manager . add Append ers ( context , ĠArrayList ()) ĊĠĠĠĠĠĠĠ ĠAssert . assertNotNull ( append ers Ids ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 0 , Ġappend ers Ids . size ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Add Append ers () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġval Ġappend ers Ids Ġ= Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )). enable Appender ( context ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )). enable Appender ( context ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )). enable Appender ( context ) ĊĠĠĠĠĠĠĠ ĠAssert . assertNotNull ( append ers Ids ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 3 , Ġappend ers Ids . size ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( append ers Ids . contains (" A ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( append ers Ids . contains (" B ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( append ers Ids . contains (" C ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Add Append ers Repeated () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B 1 Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B 2 Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B 1 ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B 2 ) ĊĊĠĠĠĠĠĠĠ Ġ// We Ġmust Ġinitialize Ġthe ĠLOG Ġsince Ġit Ġprints Ġan Ġerror ĊĠĠĠĠĠĠĠ Ġinit ( context , ĠpackageName ) ĊĠĠĠĠĠĠĠ Ġval Ġappend ers Ids Ġ= Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ ĠAssert . assertNotNull ( append ers Ids ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 2 , Ġappend ers Ids . size ) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( append ers Ids . contains (" A ")) ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue ( append ers Ids . contains (" B ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Disable Append ers Empty () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġanalytics Manager . remove Append ers ( context , ĠHashSet ()) ĊĠĠĠĠĠĠĠ ĠAssert . assertNotNull ( analytics Manager ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Disable Append ers () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġval Ġappend ers Ids Ġ= Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . remove Append ers ( context , Ġappend ers Ids ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )). disable Appender () ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )). disable Appender () ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )). disable Appender () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Disable All Append ers () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . removeAll Append ers () ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )). disable Appender () ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )). disable Appender () ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )). disable Appender () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Track Event () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Payload : ĠMutable Map < String , ĠAny > Ġ= ĠHashMap () ĊĠĠĠĠĠĠĠ Ġanalytics Payload [" A "] Ġ= Ġ" A 1 " ĊĠĠĠĠĠĠĠ Ġanalytics Payload [" B "] Ġ= Ġ" B 1 " ĊĠĠĠĠĠĠĠ Ġanalytics Payload [" C "] Ġ= Ġ" C 1 " ĊĠĠĠĠĠĠĠ Ġanalytics Manager . track Event (" test ", Ġanalytics Payload ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Event ( eventName Ġ= Ġ" test ", Ġanalytics Payload Ġ= Ġanalytics Payload ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Event ( eventName Ġ= Ġ" test ", Ġanalytics Payload Ġ= Ġanalytics Payload ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Event ( eventName Ġ= Ġ" test ", Ġanalytics Payload Ġ= Ġanalytics Payload ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Track Event With Bundle () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Payload Ġ= ĠBundle () ĊĠĠĠĠĠĠĠ Ġanalytics Payload . putString (" A ", Ġ" A 1 ") ĊĠĠĠĠĠĠĠ Ġanalytics Payload . putString (" B ", Ġ" B 1 ") ĊĠĠĠĠĠĠĠ Ġanalytics Payload . putString (" C ", Ġ" C 1 ") ĊĠĠĠĠĠĠĠ Ġanalytics Manager . track Event (" test ", Ġanalytics Payload ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Event ( eventName Ġ= Ġ" test ", Ġanalytics Payload Ġ= Ġanalytics Payload ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Event ( eventName Ġ= Ġ" test ", Ġanalytics Payload Ġ= Ġanalytics Payload ) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Event ( eventName Ġ= Ġ" test ", Ġanalytics Payload Ġ= Ġanalytics Payload ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Track Page Hit () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġactivity Ġ= ĠMockito . mock ( Activity :: class . java ) ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . track Page Hit ( activity Ġ= Ġactivity , Ġscreen Name Ġ= Ġ" test ", Ġscreen Class Override Ġ= Ġ" screen Ġclass ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Page Hit ( activity Ġ= Ġactivity , Ġscreen Name Ġ= Ġ" test ", Ġscreen Class Override Ġ= Ġ" screen Ġclass ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Page Hit ( activity Ġ= Ġactivity , Ġscreen Name Ġ= Ġ" test ", Ġscreen Class Override Ġ= Ġ" screen Ġclass ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Page Hit ( activity Ġ= Ġactivity , Ġscreen Name Ġ= Ġ" test ", Ġscreen Class Override Ġ= Ġ" screen Ġclass ") ĊĊĊĠĠĠĠĠĠĠ Ġanalytics Manager . track Page Hit ( screen Name Ġ= Ġ" test ", Ġscreen Class Ġ= Ġ" screen Ġclass ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Page Hit ( screen Name Ġ= Ġ" test ", Ġscreen Class Ġ= Ġ" screen Ġclass ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Page Hit ( screen Name Ġ= Ġ" test ", Ġscreen Class Ġ= Ġ" screen Ġclass ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. track Page Hit ( screen Name Ġ= Ġ" test ", Ġscreen Class Ġ= Ġ" screen Ġclass ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Set UserID () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . set UserID (" 1 2 3 4 ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )). set UserId (" 1 2 3 4 ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )). set UserId (" 1 2 3 4 ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )). set UserId (" 1 2 3 4 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Set User Property () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġanalytics Manager : ĠI Analytics Manager Ġ= ĠAnalytics Manager () ĊĠĠĠĠĠĠĠ Ġval Ġappend ers : ĠMutable List < I Analytics Appender > Ġ= ĠArrayList () ĊĠĠĠĠĠĠĠ Ġval Ġapp ender A Ġ= Ġmock Appender (" A ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender B Ġ= Ġmock Appender (" B ") ĊĠĠĠĠĠĠĠ Ġval Ġapp ender C Ġ= Ġmock Appender (" C ") ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender A ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender B ) ĊĠĠĠĠĠĠĠ Ġappend ers . add ( appender C ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . add Append ers ( context , Ġappend ers ) ĊĠĠĠĠĠĠĠ Ġanalytics Manager . setUser Property (" name ", Ġ" ban ana ") ĊĠĠĠĠĠĠĠ Ġanalytics Manager . setUser Property (" age ", Ġ" 3 0 ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setUser Property ( name Ġ= Ġ" name ", Ġvalue Ġ= Ġ" ban ana ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setUser Property ( name Ġ= Ġ" name ", Ġvalue Ġ= Ġ" ban ana ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setUser Property ( name Ġ= Ġ" name ", Ġvalue Ġ= Ġ" ban ana ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender A , ĠMockito . times ( 1 )). setUser Property (" age ", Ġ" 3 0 ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender B , ĠMockito . times ( 1 )). setUser Property (" age ", Ġ" 3 0 ") ĊĠĠĠĠĠĠĠ ĠMockito . verify ( appender C , ĠMockito . times ( 1 )). setUser Property (" age ", Ġ" 3 0 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġmock Appender ( analytics Id : ĠString ): ĠI Analytics Appender Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġapp ender : ĠI Analytics Appender Ġ= Ġmock () ĊĠĠĠĠĠĠĠ ĠMockito .` when `( appender . analytics Id ). thenReturn ( analytics Id ) ĊĠĠĠĠĠĠĠ Ġreturn Ġapp ender ĊĠĠĠ Ġ} Ċ }