<lambda>null1 package leakcanary
2 
3 import org.assertj.core.api.Assertions.assertThat
4 import org.junit.Test
5 import kotlin.reflect.full.memberFunctions
6 import kotlin.reflect.full.memberProperties
7 
8 class AppWatcherTest {
9 
10   @Test fun appWatcherLoads_notInstalled() {
11     assertThat(AppWatcher.isInstalled)
12       .describedAs("Ensure AppWatcher doesn't crash in JUnit tests")
13       .isFalse()
14   }
15 
16   /**
17    * Validates that each field in [AppWatcher.Config] has a matching builder function
18    * in [AppWatcher.Config.Builder]
19    */
20   @Test fun `AppWatcher Config Builder matches AppWatcher Config`() {
21     assertThat(configProperties())
22       .containsExactlyInAnyOrderElementsOf(configBuilderFunctions())
23   }
24 
25   private fun configBuilderFunctions() = AppWatcher.Config.Builder::class.memberFunctions
26     .filter { member ->
27       member.annotations.none { it is Deprecated }
28     }
29     .map { it.name }
30     .subtract(setOf("build", "equals", "hashCode", "toString"))
31 
32   private fun configProperties() = AppWatcher.Config::class.memberProperties
33     .filter { member ->
34       // Ignore deprecated fields, we don't need builders for those
35       member.annotations.none { it is Deprecated }
36     }
37     .map { it.name }
38 }
39