Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Treat kotlin warnings as errors (#555)
Browse files Browse the repository at this point in the history
* Treat warnings as errors

* Eliminate simple warnings

* Add further explanation and also suppress warning

* Eliminate warning, but this may change expected behaviour

* Replace deprecated RuntimeEnvironment

* Add ExperimentalCoroutinesApi annotation

* Resolve issues found in review of @eliserichards

* Remove unused variable

* DO NOT MERGE - temporarly supress deprecation warning of FingerprintManager

* Suppressing unused parameter for fingerprint onclick method. Upgrading gradle version.

* Updating kotlin-reflect version.

* Suppressing java deprecation in base robot, adding coroutines marking on other robot test classes

* Testing out coroutines annotation in Item detail robot.
  • Loading branch information
beatbrot authored and eliserichards committed Apr 2, 2019
1 parent 73c7d95 commit f9c318d
Show file tree
Hide file tree
Showing 43 changed files with 134 additions and 96 deletions.
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ dependencies {
implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version"
implementation 'com.adjust.sdk:adjust-android:4.17.0'
implementation 'com.android.installreferrer:installreferrer:1.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.22.0'
testImplementation 'org.robolectric:robolectric:4.0.2'
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
androidTestImplementation "androidx.test:core:$androidxTest_version"
testImplementation "androidx.test:core:$androidxTest_version"
androidTestImplementation "androidx.test.ext:junit:$androidxTest_version"
androidTestImplementation "androidx.test:runner:$androidxTest_version"
androidTestImplementation "androidx.test:rules:$androidxTest_version"
Expand Down Expand Up @@ -235,3 +236,7 @@ if (project.hasProperty("coverage")) {
}
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions.allWarningsAsErrors = true
}
2 changes: 2 additions & 0 deletions app/src/androidTest/java/mozilla/lockbox/ItemDetailsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package mozilla.lockbox

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.lockbox.robots.itemDetail
import mozilla.lockbox.robots.itemList
import mozilla.lockbox.view.RootActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@ExperimentalCoroutinesApi
@RunWith(AndroidJUnit4::class)
open class ItemDetailsTest {
private val navigator = Navigator()
Expand Down
2 changes: 2 additions & 0 deletions app/src/androidTest/java/mozilla/lockbox/ItemListTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package mozilla.lockbox

import androidx.test.rule.ActivityTestRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.lockbox.robots.itemList
import mozilla.lockbox.view.RootActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@ExperimentalCoroutinesApi
@RunWith(AndroidJUnit4::class)
open class ItemListTest {
private val navigator = Navigator()
Expand Down
2 changes: 2 additions & 0 deletions app/src/androidTest/java/mozilla/lockbox/OnboardingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mozilla.lockbox

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.lockbox.robots.autofillOnboardingScreen
import mozilla.lockbox.robots.fingerprintOnboardingScreen
import mozilla.lockbox.robots.fxaLogin
Expand All @@ -13,6 +14,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@ExperimentalCoroutinesApi
@RunWith(AndroidJUnit4::class)
open class OnboardingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

@file:Suppress("DEPRECATION")

package mozilla.lockbox.robots

import androidx.test.espresso.Espresso
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import mozilla.lockbox.view.RootActivity
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not

// ItemDetail
@Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_API_USAGE_ERROR", "EXPERIMENTAL_IS_NOT_ENABLED")
class ItemDetailRobot : BaseTestRobot {
override fun exists() = displayed {
id(R.id.inputHostname)
Expand Down
4 changes: 2 additions & 2 deletions app/src/debug/java/mozilla/lockbox/view/UITestActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

package mozilla.lockbox.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import mozilla.lockbox.R
import mozilla.lockbox.log

Expand All @@ -18,7 +18,7 @@ class UITestActivity : AppCompatActivity() {
setContentView(R.layout.activity_test)
}

fun launchFingerprint(view: View) {
fun launchFingerprint(@Suppress("UNUSED_PARAMETER") view: View) {
val dialogFragment = FingerprintAuthDialogFragment()
val fragmentManager = this.supportFragmentManager
try {
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/mozilla/lockbox/extensions/ViewNode+.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ fun AssistStructure.ViewNode.dump(): String {

@TargetApi(Build.VERSION_CODES.O)
private fun AssistStructure.ViewNode.dumpNode(sb: StringBuilder = StringBuilder()): StringBuilder {
val name = if (htmlInfo != null) {
htmlInfo.tag
} else {
className.split('.').last()
}
val name = htmlInfo?.tag ?: className.split('.').last()

var attrs = listOf(
Pair("idEntry", idEntry ?: ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ data class ItemDetailViewModel(
val username: String?,
val password: String
) {
var hasUsername: Boolean = false
val hasUsername: Boolean
get() = !username.isNullOrBlank()
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FxALoginPresenter(

override fun onViewReady() {
view.webViewRedirect = { url ->
val urlStr = url?.toString() ?: null
val urlStr = url?.toString()
val result = isRedirectUri(urlStr)
if (result) {
dispatcher.dispatch(OnboardingStatusAction(true))
Expand Down
27 changes: 14 additions & 13 deletions app/src/main/java/mozilla/lockbox/store/ClipboardStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ open class ClipboardStore(
val dispatcher: Dispatcher = Dispatcher.shared
) : ContextStore {
internal val compositeDisposable = CompositeDisposable()

companion object {
val shared = ClipboardStore()
}
Expand All @@ -29,19 +30,19 @@ open class ClipboardStore(

init {
dispatcher.register
.filterByType(ClipboardAction::class.java)
.subscribe {
// unpack the action, including adding new Clips to the Clipboard.
when (it) {
is ClipboardAction.CopyUsername -> {
addToClipboard("username", it.username)
}
is ClipboardAction.CopyPassword -> {
addToClipboard("password", it.password)
}
.filterByType(ClipboardAction::class.java)
.subscribe {
// unpack the action, including adding new Clips to the Clipboard.
when (it) {
is ClipboardAction.CopyUsername -> {
addToClipboard("username", it.username)
}
is ClipboardAction.CopyPassword -> {
addToClipboard("password", it.password)
}
}
.addTo(compositeDisposable)
}
.addTo(compositeDisposable)
}

override fun injectContext(context: Context) {
Expand All @@ -61,8 +62,8 @@ open class ClipboardStore(
}

fun replaceDirty(dirty: String, clean: String = "") {
val clipData = clipboardManager.primaryClip.getItemAt(0)
if (clipData.text == dirty) {
val clipData = clipboardManager.primaryClip?.getItemAt(0)
if (clipData?.text == dirty) {
clipboardManager.primaryClip = ClipData.newPlainText("", clean)
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/mozilla/lockbox/store/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ open class DataStore(
this.listSubject.accept(emptyList())
}

// Parameter x is needed to ensure that the function is indeed a Consumer so that it can be used in a suscribe-call
// there's probably a slicker way to do this `Unit` thing...
@Suppress("UNUSED_PARAMETER")
private fun updateList(x: Unit) {
val backend = this.backend ?: return notReady()
if (!backend.isLocked()) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/mozilla/lockbox/store/NetworkStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import android.content.Context
import android.net.ConnectivityManager
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.subjects.ReplaySubject
import mozilla.lockbox.action.NetworkAction
import mozilla.lockbox.extensions.filterByType
import mozilla.lockbox.flux.Dispatcher
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.ReplaySubject

open class NetworkStore(
val dispatcher: Dispatcher = Dispatcher.shared
Expand All @@ -22,7 +22,7 @@ open class NetworkStore(
val isConnected: Observable<Boolean>

val isConnectedState: Boolean
get() = connectivityManager.activeNetworkInfo?.isConnectedOrConnecting == true
get() = connectivityManager.activeNetworkInfo?.isConnected == true

companion object {
val shared = NetworkStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FixedDataStoreSupport(
) : DataStoreSupport {
var size = getRandomInRange(40, 50)
private val logins = MemoryLoginsStorage(
values ?: List(size) { createDummyItem(it) } + listOf(createDummyIPItem())
values ?: List(size) { createDummyItem() } + listOf(createDummyIPItem())
)

override var encryptionKey: String = "shh-keep-it-secret"
Expand All @@ -45,7 +45,7 @@ class FixedDataStoreSupport(
* Some functionality inspired by FxA 'upload_fake_passwords.py'
* https://gist.github.com/rfk/916d9ca684f862b1c1030c685a5a4d19
*/
internal fun createDummyItem(idx: Int): ServerPassword {
internal fun createDummyItem(): ServerPassword {
val random = Random()
val id = UUID.randomUUID().toString()
val pwd = createRandomPassword()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/mozilla/lockbox/support/LockingSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package mozilla.lockbox.support
import android.os.SystemClock

interface LockingSupport {
var systemTimeElapsed: Long
val systemTimeElapsed: Long
}

class SystemLockingSupport : LockingSupport {
override var systemTimeElapsed: Long = 0L
override val systemTimeElapsed: Long
get() = SystemClock.elapsedRealtime()
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ data class PublicSuffix(
this.topDomain.equals(expected.topDomain, true)
}

@ExperimentalCoroutinesApi
private fun asyncDomain(pslSupport: PublicSuffixSupport, webDomain: String?, packageName: String) =
// resolve the (webDomain || packageName) to a 1+publicsuffix =
when (webDomain) {
Expand All @@ -95,6 +96,7 @@ private data class FillablePassword(
val entry: ServerPassword
)

@ExperimentalCoroutinesApi
fun Observable<List<ServerPassword>>.filter(pslSupport: PublicSuffixSupport, webDomain: String?, packageName: String): Observable<List<ServerPassword>> {
val passwords = this.switchMap { serverPasswords ->
val parsedPasswords = serverPasswords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import android.view.inputmethod.InputMethodManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.jakewharton.rxbinding2.view.clicks
import com.jakewharton.rxbinding2.view.visibility
import com.jakewharton.rxbinding2.widget.text
import com.jakewharton.rxbinding2.widget.textChanges
import io.reactivex.Observable
import io.reactivex.functions.Consumer
Expand Down Expand Up @@ -69,7 +68,7 @@ class AutofillFilterFragment : DialogFragment(), AutofillFilterView {
get() = view!!.filterField.textChanges()

override val filterText: Consumer<in CharSequence>
get() = view!!.filterField.text()
get() = Consumer { newText -> view!!.filterField.setText(newText) }
override val cancelButtonClicks: Observable<Unit>
get() = view!!.cancelButton.clicks()
override val cancelButtonVisibility: Consumer<in Boolean>
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/mozilla/lockbox/view/FilterFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ package mozilla.lockbox.view

import android.content.Context
import android.os.Bundle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.jakewharton.rxbinding2.view.clicks
import com.jakewharton.rxbinding2.view.visibility
import com.jakewharton.rxbinding2.widget.text
import com.jakewharton.rxbinding2.widget.textChanges
import io.reactivex.Observable
import io.reactivex.functions.Consumer
Expand Down Expand Up @@ -72,7 +71,7 @@ class FilterFragment : BackableFragment(), FilterView {
override val filterTextEntered: Observable<CharSequence>
get() = view!!.filterField.textChanges()
override val filterText: Consumer<in CharSequence>
get() = view!!.filterField.text()
get() = Consumer { newText -> view!!.filterField.setText(newText) }
override val cancelButtonClicks: Observable<Unit>
get() = view!!.cancelButton.clicks()
override val cancelButtonVisibility: Consumer<in Boolean>
Expand Down
8 changes: 4 additions & 4 deletions app/src/test/java/mozilla/lockbox/DispatcherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

package mozilla.lockbox

import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import mozilla.lockbox.flux.Dispatcher
import mozilla.lockbox.flux.Action
import mozilla.lockbox.flux.Dispatcher
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.concurrent.atomic.AtomicBoolean

Expand All @@ -24,7 +24,7 @@ class DispatcherTest {
val dispatcher = Dispatcher()
val onNextExecuted = AtomicBoolean(false)

val subscription = dispatcher.register.subscribe { _ -> onNextExecuted.set(true) }
val subscription = dispatcher.register.subscribe { onNextExecuted.set(true) }
assertFalse(onNextExecuted.get())
dispatcher.dispatch(TestAction.UNIT)
assertTrue(onNextExecuted.get())
Expand Down
3 changes: 1 addition & 2 deletions app/src/test/java/mozilla/lockbox/StackReplaySubjectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
package mozilla.lockbox

import io.reactivex.observers.TestObserver
import junit.framework.Assert.assertEquals
import mozilla.lockbox.extensions.assertLastValue

import mozilla.lockbox.flux.StackReplaySubject
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.concurrent.atomic.AtomicInteger

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package mozilla.lockbox.adapter
import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ApplicationProvider
import io.reactivex.observers.TestObserver
import kotlinx.android.synthetic.main.list_cell_item.*
import kotlinx.android.synthetic.main.list_cell_no_entries.view.*
Expand All @@ -22,7 +23,6 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
Expand All @@ -46,7 +46,7 @@ class ItemListAdapterTest {

@Before
fun setUp() {
context = RuntimeEnvironment.application
context = ApplicationProvider.getApplicationContext()
parent = RecyclerView(context)
parent.layoutManager = LinearLayoutManager(context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ListAdapterTestHelper {
private val toggleObserverFake = TestObserver<Boolean>()
private val toggleConsumerFake = TestConsumer(toggleObserverFake) as Consumer<Boolean>
private val textClicksObserverFake = TestObserver<Unit>()
private val textClicksConsumerFake = TestConsumer(toggleObserverFake) as Consumer<Unit>
private val textClicksConsumerFake = TestConsumer(textClicksObserverFake)
private val expectedVersionNumber = BuildConfig.VERSION_NAME

fun createListOfSettings(): List<SettingCellConfiguration> {
Expand Down
Loading

0 comments on commit f9c318d

Please sign in to comment.