Browse Source

Addressing Code quality Warnings-I

- Addresses *UnsafeCallOnNullableType* warnings
  - Uses type safe '?.' operator in place of '!!' where applicable
- Addresses *unchecked cast any to T* warning
  - Uses [reified type parameters](https://kotlinlang.org/docs/reference/inline-functions.html#reified-type-parameters)
Subbramanian Lakshmanan 7 years ago
parent
commit
f116394038

+ 3 - 3
app/src/androidTest/java/com/sduduzog/slimlauncher/DBTest.kt

@@ -25,19 +25,19 @@ class DBTest {
     fun createDb() {
         val context = InstrumentationRegistry.getTargetContext()
         mDb = Room.inMemoryDatabaseBuilder(context, AppRoomDatabase::class.java).build()
-        mAppDao = mDb!!.appDao()
+        mAppDao = mDb?.appDao()
     }
 
     @After
     fun closeDb() {
-        mDb!!.close()
+        mDb?.close()
     }
 
     @Test
     @Throws(InterruptedException::class)
     fun testInsertLiveDataApps() {
         val app = TestUtil.createApp("TestApp", "com.test.test.app", "TestMainActivity")
-        mAppDao!!.insert(app)
+        mAppDao?.insert(app)
         val appsInstalled = LiveDataTestUtil.getValue(mAppDao!!.apps)
         assertThat(appsInstalled.size, equalTo(1))
     }

+ 1 - 1
app/src/androidTest/java/com/sduduzog/slimlauncher/LiveDataTestUtil.kt

@@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit
 object LiveDataTestUtil {
 
     @Throws(InterruptedException::class)
-    fun <T> getValue(liveData: LiveData<T>): T {
+    inline fun <reified T> getValue(liveData: LiveData<T>): T {
         val data = arrayOfNulls<Any>(1)
         val latch = CountDownLatch(1)
         val observer = object : Observer<T> {