package Ġorg . opp ia . util . profile Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroid . content . Context Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġdagger . Bind s Instance Ċ import Ġdagger . Component Ċ import Ġdagger . Module Ċ import Ġdagger . Provides Ċ import Ġkotlinx . coroutines . Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . Obsolete Cor outines Api Ċ import Ġkotlinx . coroutines . new Single Thread Context Ċ import Ġkotlinx . coroutines . test . Test Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . test . reset Main Ċ import Ġkotlinx . coroutines . test . set Main Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . opp ia . util . logging . Enable Console Log Ċ import Ġorg . opp ia . util . logging . Enable File Log Ċ import Ġorg . opp ia . util . logging . Global LogLevel Ċ import Ġorg . opp ia . util . logging . LogLevel Ċ import Ġorg . opp ia . util . threading . Background Dispatcher Ċ import Ġorg . opp ia . util . threading . Blocking Dispatcher Ċ import Ġorg . ro bo lectric . annotation . Config Ċ import Ġjava . io . File Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Qualifier Ċ import Ġjavax . inject . Singleton Ċ Ċ /** ĠTests Ġfor Ġ[ Directory Management Util ]. Ġ*/ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ @ Config ( manifest Ġ= ĠConfig . NONE ) Ċ class ĠDirectory Management Util Test Ġ{ ĊĊĠ Ġ@ Inject Ġlateinit Ġvar Ġdirectory Management Util : ĠDirectory Management Util ĊĊĠ Ġ@ Inject Ġlateinit Ġvar Ġcontext : ĠContext ĊĊĠ Ġ// Ġhttps :// kotlin . github . io / kotlin x . coroutines / kotlin x - coroutines - test / ĊĠ Ġ@ Obsolete Cor outines Api ĊĠ Ġprivate Ġval Ġtest Thread Ġ= Ġnew Single Thread Context (" Test Main ") ĊĊĠ Ġ@ Before ĊĠ Ġ@ Experimental Cor outines Api ĊĠ Ġ@ Obsolete Cor outines Api ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ ĠDispatch ers . set Main ( test Thread ) ĊĠĠĠ ĠsetUp Test Application Component () ĊĠ Ġ} ĊĊĠ Ġ@ After ĊĠ Ġ@ Experimental Cor outines Api ĊĠ Ġ@ Obsolete Cor outines Api ĊĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠ ĠDispatch ers . reset Main () ĊĠĠĠ Ġtest Thread . close () ĊĠ Ġ} ĊĊĠ Ġprivate Ġval ĠTEST _ DIRECTORY _ 1 Ġ= Ġ" TEST _ DIRECTORY _ 1 " ĊĠ Ġprivate Ġval ĠTEST _ DIRECTORY _ 2 Ġ= Ġ" TEST _ DIRECTORY _ 2 " ĊĠ Ġprivate Ġval ĠTEST _ FILE _ 1 Ġ= Ġ" TEST _ FILE _ 1 " ĊĠ Ġprivate Ġval ĠTEST _ FILE _ 2 Ġ= Ġ" TEST _ FILE _ 2 " ĊĊĠ Ġprivate Ġfun ĠsetUp Test Application Component () Ġ{ ĊĠĠĠ ĠD agger Directory Management Util Test _ Test Application Component . builder () ĊĠĠĠĠĠ Ġ. set Application ( Application Provider . getApplicationContext ()) ĊĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠ Ġ. inject ( this ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet OrCreate Dir _ for Created Dir _ dir Is Created () Ġ{ ĊĠĠĠ Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ Ġval Ġdir Ġ= ĠFile ( get Absolute DirPath ( TEST _ DIRECTORY _ 1 )) ĊĊĠĠĠ ĠassertThat ( dir . exists ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet OrCreate Dir _ for Created Dir _ get Same Dir _ check Dirs AreEqual () Ġ{ ĊĠĠĠ Ġval Ġdir Ġ= Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ Ġval Ġsame Dir Ġ= Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ ĠassertThat ( dir ). isEqualTo ( same Dir ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet OrCreate Dir _ for Created Dir _ create Different Dir _ check Dirs Are NotEqual () Ġ{ ĊĠĠĠ Ġval Ġdir Ġ= Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ Ġval Ġdiff Dir Ġ= Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 2 ) ĊĊĠĠĠ ĠassertThat ( dir ). isNot EqualTo ( diff Dir ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet OrCreate Dir _ for Created Dir _ restart Application _ dir Is Created () Ġ{ ĊĠĠĠ Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ ĠsetUp Test Application Component () ĊĊĠĠĠ Ġval Ġdir Ġ= ĠFile ( get Absolute DirPath ( TEST _ DIRECTORY _ 1 )) ĊĠĠĠ ĠassertThat ( dir . exists ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Delete Dir _ for Created Dir _ delete Dir _ check Dir DoesNotExist () Ġ{ ĊĠĠĠ Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ Ġval Ġsuccess Ġ= Ġdirectory Management Util . delete Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ Ġval Ġdir Ġ= ĠFile ( get Absolute DirPath ( TEST _ DIRECTORY _ 1 )) ĊĠĠĠ ĠassertThat ( dir . exists ()). isFalse () ĊĠĠĠ ĠassertThat ( success ). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Delete Dir _ for Created Dir _ with Cont ained Files _ dir Is Deleted () Ġ{ ĊĠĠĠ Ġval Ġdir Ġ= Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĠĠĠ Ġval Ġfile 1 Ġ= ĠFile ( dir , ĠTEST _ FILE _ 1 ) ĊĠĠĠ Ġfile 1 . createNew File () ĊĠĠĠ Ġval Ġfile 2 Ġ= ĠFile ( dir , ĠTEST _ FILE _ 2 ) ĊĠĠĠ Ġfile 2 . createNew File () ĊĊĠĠĠ Ġval Ġsuccess Ġ= Ġdirectory Management Util . delete Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ ĠassertThat ( dir . exists ()). isFalse () ĊĠĠĠ ĠassertThat ( success ). isTrue () ĊĠĠĠ ĠassertThat ( File ( get Absolute DirPath ( TEST _ DIRECTORY _ 1 ) Ġ+ Ġ"/" Ġ+ ĠTEST _ FILE _ 1 ). exists ()). isFalse () ĊĠĠĠ ĠassertThat ( File ( get Absolute DirPath ( TEST _ DIRECTORY _ 1 ) Ġ+ Ġ"/" Ġ+ ĠTEST _ FILE _ 2 ). exists ()). isFalse () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Delete Dir _ for Created Dir _ with Cont ained Files _ delete Dir _ create Same Dir _ check Dir IsEmpty () Ġ{ ĊĠĠĠ Ġval Ġdir Ġ= Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĠĠĠ Ġval Ġfile 1 Ġ= ĠFile ( dir , ĠTEST _ FILE _ 1 ) ĊĠĠĠ Ġfile 1 . createNew File () ĊĠĠĠ Ġval Ġfile 2 Ġ= ĠFile ( dir , ĠTEST _ FILE _ 2 ) ĊĠĠĠ Ġfile 2 . createNew File () ĊĊĠĠĠ Ġval Ġsuccess Ġ= Ġdirectory Management Util . delete Dir ( TEST _ DIRECTORY _ 1 ) ĊĠĠĠ Ġdirectory Management Util . get OrCreate Dir ( TEST _ DIRECTORY _ 1 ) ĊĊĠĠĠ ĠassertThat ( success ). isTrue () ĊĠĠĠ ĠassertThat ( dir . exists ()). isTrue () ĊĠĠĠ ĠassertThat ( dir . list Files (). isEmpty ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Absolute DirPath ( path : ĠString ): ĠString Ġ{ ĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* Ġcontext . files Dir . toString () Ġlooks Ġlike Ġ/ tmp / ro bo lectric - Method _ test _ name / org . opp ia . util . test - data Dir / files ĊĠĠĠĠ Ġ* Ġdrop Last ( 5 ) Ġremoves Ġfiles Ġfrom Ġthe Ġpath Ġand Ġthen Ġit Ġapp ends Ġthe Ġreal Ġpath Ġwith Ġ" app _" Ġas Ġa Ġprefix ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġreturn Ġcontext . files Dir . toString (). drop Last ( 5 ) Ġ+ Ġ" app _" Ġ+ Ġpath ĊĠ Ġ} ĊĊĠ Ġ@ Qualifier ĊĠ Ġannotation Ġclass ĠTest Dispatcher ĊĊĠ Ġ// ĠTODO (# 8 9 ): ĠMove Ġthis Ġto Ġa Ġcommon Ġtest Ġapplication Ġcomponent . ĊĠ Ġ@ Module ĊĠ Ġclass ĠTest Module Ġ{ ĊĠĠĠ Ġ@ Provides ĊĠĠĠ Ġ@ Singleton ĊĠĠĠ Ġfun Ġprovide Context ( application : ĠApplication ): ĠContext Ġ{ ĊĠĠĠĠĠ Ġreturn Ġapplication ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġ@ Singleton ĊĠĠĠ Ġ@ Provides ĊĠĠĠ Ġ@ Test Dispatcher ĊĠĠĠ Ġfun Ġprovide Test Dispatcher (): ĠCor outine Dispatcher Ġ{ ĊĠĠĠĠĠ Ġreturn ĠTest Coroutine Dispatcher () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Singleton ĊĠĠĠ Ġ@ Provides ĊĠĠĠ Ġ@ Background Dispatcher ĊĠĠĠ Ġfun Ġprovide Background Dispatcher (@ Test Dispatcher Ġtest Dispatcher : ĠCor outine Dispatcher ): ĠCor outine Dispatcher Ġ{ ĊĠĠĠĠĠ Ġreturn Ġtest Dispatcher ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Singleton ĊĠĠĠ Ġ@ Provides ĊĠĠĠ Ġ@ Blocking Dispatcher ĊĠĠĠ Ġfun Ġprovide Blocking Dispatcher (@ Test Dispatcher Ġtest Dispatcher : ĠCor outine Dispatcher ): ĠCor outine Dispatcher Ġ{ ĊĠĠĠĠĠ Ġreturn Ġtest Dispatcher ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠTODO (# 5 9 ): ĠEither Ġisolate Ġthese Ġto Ġtheir Ġown Ġshared Ġtest Ġmodule , Ġor Ġuse Ġthe Ġreal Ġlogging ĊĠĠĠ Ġ// Ġmodule Ġin Ġtests Ġto Ġavoid Ġneeding Ġto Ġspecify Ġthese Ġsettings Ġfor Ġtests . ĊĠĠĠ Ġ@ Enable Console Log ĊĠĠĠ Ġ@ Provides ĊĠĠĠ Ġfun Ġprovide Enable Console Log (): ĠBoolean Ġ= Ġtrue ĊĊĠĠĠ Ġ@ Enable File Log ĊĠĠĠ Ġ@ Provides ĊĠĠĠ Ġfun Ġprovide Enable File Log (): ĠBoolean Ġ= Ġfalse ĊĊĠĠĠ Ġ@ Global LogLevel ĊĠĠĠ Ġ@ Provides ĊĠĠĠ Ġfun Ġprovide Global LogLevel (): ĠLogLevel Ġ= ĠLogLevel . VERBOSE ĊĠ Ġ} ĊĊĠ Ġ// ĠTODO (# 8 9 ): ĠMove Ġthis Ġto Ġa Ġcommon Ġtest Ġapplication Ġcomponent . ĊĠ Ġ@ Singleton ĊĠ Ġ@ Component ( modules Ġ= Ġ[ Test Module :: class ]) ĊĠ Ġinterface ĠTest Application Component Ġ{ ĊĠĠĠ Ġ@ Component . Builder ĊĠĠĠ Ġinterface ĠBuilder Ġ{ ĊĠĠĠĠĠ Ġ@ Bind s Instance ĊĠĠĠĠĠ Ġfun Ġset Application ( application : ĠApplication ): ĠBuilder ĊĊĠĠĠĠĠ Ġfun Ġbuild (): ĠTest Application Component ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġinject ( directory Management Util Test : ĠDirectory Management Util Test ) ĊĠ Ġ} Ċ } Ċ