Skip to content

Commit

Permalink
Fix kotlin weak warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
abelgardep committed Dec 12, 2019
1 parent 35089bf commit f70fb18
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ class OCSettingsCameraUploadsTest {

private val context = InstrumentationRegistry.getInstrumentation().targetContext

private val CAMERA_PICTURE_UPLOADS = "camera_picture_uploads"
private val CAMERA_VIDEO_UPLOADS = "camera_video_uploads"
private val cameraPictureUploads = "camera_picture_uploads"
private val cameraVideoUploads = "camera_video_uploads"

private lateinit var mPrefCameraPictureUploads: CheckBoxPreference
private lateinit var mPrefCameraVideoUploads: CheckBoxPreference

@Before
fun setUp() {

mPrefCameraPictureUploads = activityRule.activity.findPreference(CAMERA_PICTURE_UPLOADS) as CheckBoxPreference
mPrefCameraVideoUploads = activityRule.activity.findPreference(CAMERA_VIDEO_UPLOADS) as CheckBoxPreference
mPrefCameraPictureUploads = activityRule.activity.findPreference(cameraPictureUploads) as CheckBoxPreference
mPrefCameraVideoUploads = activityRule.activity.findPreference(cameraVideoUploads) as CheckBoxPreference

//Only interested in "Camera Uploads" section, so we can get rid of the other categories.
val preferenceScreen = activityRule.activity.getPreferenceScreen() as PreferenceScreen
val preferenceScreen = activityRule.activity.preferenceScreen as PreferenceScreen
val securityCategory =
activityRule.activity.findPreference("security_category") as PreferenceCategory
val moreCategory =
Expand Down Expand Up @@ -226,7 +226,7 @@ class OCSettingsCameraUploadsTest {
@Test
fun switchOriginalFileWillBe() {
enableCameraPictureUploads()
onData(PreferenceMatchers.withTitle(R.string.prefs_camera_upload_behaviour_title)).perform(click());
onData(PreferenceMatchers.withTitle(R.string.prefs_camera_upload_behaviour_title)).perform(click())
onView(withText(R.string.pref_behaviour_entries_move)).perform(click())
//Asserts
onView(withText(R.string.pref_behaviour_entries_move)).check(matches(isDisplayed()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ class OCSettingsPasscodeTest {

private val intent = Intent()
private val errorMessage = "PassCode Activity error"
private val KEY_PASSCODE = "KEY_PASSCODE"
private val keyPassCode = "KEY_PASSCODE"
private val context = InstrumentationRegistry.getInstrumentation().targetContext

private val DEFAULT_PASSCODE = arrayOf('1', '1', '1', '1')
private val WRONG_PASSCODE = arrayOf('1', '1', '1', '2')
private val PASSCODE_TOSAVE = "1111"
private val defaultPassCode = arrayOf('1', '1', '1', '1')
private val wrongPassCode = arrayOf('1', '1', '1', '2')
private val passCodeToSave = "1111"

@After
fun tearDown() {
Expand Down Expand Up @@ -87,7 +87,7 @@ class OCSettingsPasscodeTest {
openPasscodeActivity(PassCodeActivity.ACTION_REQUEST_WITH_RESULT)

//First typing
typePasscode(DEFAULT_PASSCODE)
typePasscode(defaultPassCode)

onView(withText(R.string.pass_code_reenter_your_pass_code)).check(matches(isDisplayed()))
onView(withText(R.string.pass_code_configure_your_pass_code)).check(doesNotExist())
Expand All @@ -99,13 +99,13 @@ class OCSettingsPasscodeTest {
openPasscodeActivity(PassCodeActivity.ACTION_REQUEST_WITH_RESULT)

//First typing
typePasscode(DEFAULT_PASSCODE)
typePasscode(defaultPassCode)
//Second typing
typePasscode(DEFAULT_PASSCODE)
typePasscode(defaultPassCode)

//Checking that the setResult returns the typed passcode
assertThat(activityRule.activityResult, hasResultCode(Activity.RESULT_OK))
assertThat(activityRule.activityResult, hasResultData(hasExtra(KEY_PASSCODE, PASSCODE_TOSAVE)))
assertThat(activityRule.activityResult, hasResultData(hasExtra(keyPassCode, passCodeToSave)))

assertTrue(errorMessage, activityRule.activity.isFinishing)
}
Expand All @@ -117,9 +117,9 @@ class OCSettingsPasscodeTest {
openPasscodeActivity(PassCodeActivity.ACTION_REQUEST_WITH_RESULT)

//First typing
typePasscode(DEFAULT_PASSCODE)
typePasscode(defaultPassCode)
//Second typing
typePasscode(WRONG_PASSCODE)
typePasscode(wrongPassCode)

onView(withText(R.string.pass_code_reenter_your_pass_code)).check(doesNotExist())
onView(withText(R.string.pass_code_configure_your_pass_code)).check(matches(isDisplayed()))
Expand All @@ -146,7 +146,7 @@ class OCSettingsPasscodeTest {
openPasscodeActivity(PassCodeActivity.ACTION_REQUEST_WITH_RESULT)

//First typing
typePasscode(DEFAULT_PASSCODE)
typePasscode(defaultPassCode)

onView(withId(R.id.txt0)).perform(replaceText("1"))
onView(withId(R.id.txt1)).perform(replaceText("1"))
Expand All @@ -169,27 +169,27 @@ class OCSettingsPasscodeTest {
@Test
fun deletePasscodeCorrect() {
//Save a passcode in Preferences
storePasscode(PASSCODE_TOSAVE)
storePasscode(passCodeToSave)

//Open Activity in passcode deletion mode
openPasscodeActivity(PassCodeActivity.ACTION_CHECK_WITH_RESULT)

//Type correct passcode
typePasscode(DEFAULT_PASSCODE)
typePasscode(defaultPassCode)

assertTrue(errorMessage, activityRule.activity.isFinishing)
}

@Test
fun deletePasscodeIncorrect() {
//Save a passcode in Preferences
storePasscode(PASSCODE_TOSAVE)
storePasscode(passCodeToSave)

//Open Activity in passcode deletion mode
openPasscodeActivity(PassCodeActivity.ACTION_CHECK_WITH_RESULT)

//Type incorrect passcode
typePasscode(WRONG_PASSCODE)
typePasscode(wrongPassCode)

onView(withText(R.string.pass_code_enter_pass_code)).check(matches(isDisplayed()))
}
Expand All @@ -206,7 +206,7 @@ class OCSettingsPasscodeTest {
onView(withId(R.id.txt3)).perform(replaceText(digits[3].toString()))
}

private fun storePasscode(passcode: String = PASSCODE_TOSAVE) {
private fun storePasscode(passcode: String = passCodeToSave) {
val appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit()
for (i in 1..4) {
appPrefs.putString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ class OCSettingsPatternLockTest {
@Rule
@JvmField
val activityRule = ActivityTestRule(PatternLockActivity::class.java, true, false)
private val errorMessage = "PatternLock Activity error"
private val intent = Intent()
private val context = InstrumentationRegistry.getInstrumentation().targetContext

private val PATTERN_TOSAVE = "1234"
private val patternToSave = "1234"

@After
fun tearDown() {
Expand Down Expand Up @@ -76,7 +75,7 @@ class OCSettingsPatternLockTest {

private fun storePattern() {
val appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit()
appPrefs.putString(PatternLockActivity.KEY_PATTERN, PATTERN_TOSAVE)
appPrefs.putString(PatternLockActivity.KEY_PATTERN, patternToSave)
appPrefs.putBoolean(PatternLockActivity.PREFERENCE_SET_PATTERN, true)
appPrefs.apply()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class OCSettingsSecurityTest {

private val context = InstrumentationRegistry.getInstrumentation().targetContext

private val KEY_CHECK_RESULT = "KEY_CHECK_RESULT"
private val KEY_PASSCODE = "KEY_PASSCODE"
private val KEY_PATTERN = "KEY_PATTERN"
private val KEY_CHECK_PATTERN_RESULT = "KEY_CHECK_PATTERN_RESULT"
private val keyCheckResult = "KEY_CHECK_RESULT"
private val keyPassCode = "KEY_PASSCODE"
private val keyPattern = "KEY_PATTERN"
private val keyCheckPatternResult = "KEY_CHECK_PATTERN_RESULT"

private val PASSCODE_VALUE = "1111"
private val PATTERN_VALUE = "1234"
private val passCodeValue = "1111"
private val patternValue = "1234"

@Before
fun setUp() {
Expand Down Expand Up @@ -124,7 +124,7 @@ class OCSettingsSecurityTest {
@Test
fun passcodeLockEnabled() {
val result = Intent()
result.putExtra(KEY_PASSCODE, PASSCODE_VALUE)
result.putExtra(keyPassCode, passCodeValue)
val intentResult = Instrumentation.ActivityResult(Activity.RESULT_OK, result)
intending(hasAction(PassCodeActivity.ACTION_REQUEST_WITH_RESULT)).respondWith(intentResult)
onView(withText(R.string.prefs_passcode)).perform(click())
Expand All @@ -135,7 +135,7 @@ class OCSettingsSecurityTest {
@Test
fun patternLockEnabled() {
val result = Intent()
result.putExtra(KEY_PATTERN, PATTERN_VALUE)
result.putExtra(keyPattern, patternValue)
val intentResult = Instrumentation.ActivityResult(Activity.RESULT_OK, result)
intending(hasAction(PatternLockActivity.ACTION_REQUEST_WITH_RESULT)).respondWith(intentResult)
onView(withText(R.string.prefs_pattern)).perform(click())
Expand Down Expand Up @@ -173,7 +173,7 @@ class OCSettingsSecurityTest {
fun disablePasscode() {
firstEnablePasscode()
val result = Intent()
result.putExtra(KEY_CHECK_RESULT, true)
result.putExtra(keyCheckResult, true)
val intentResult = Instrumentation.ActivityResult(Activity.RESULT_OK, result)
intending(hasAction(PatternLockActivity.ACTION_CHECK_WITH_RESULT)).respondWith(intentResult)
onView(withText(R.string.prefs_passcode)).perform(click())
Expand All @@ -186,7 +186,7 @@ class OCSettingsSecurityTest {
fun disablePattern() {
firstEnablePattern()
val result = Intent()
result.putExtra(KEY_CHECK_PATTERN_RESULT, true)
result.putExtra(keyCheckPatternResult, true)
val intentResult = Instrumentation.ActivityResult(Activity.RESULT_OK, result)
intending(hasAction(PatternLockActivity.ACTION_CHECK_WITH_RESULT)).respondWith(intentResult)
onView(withText(R.string.prefs_pattern)).perform(click())
Expand Down Expand Up @@ -228,15 +228,15 @@ class OCSettingsSecurityTest {

private fun firstEnablePasscode() {
val result = Intent()
result.putExtra(KEY_PASSCODE, PASSCODE_VALUE)
result.putExtra(keyPassCode, passCodeValue)
val intentResult = Instrumentation.ActivityResult(Activity.RESULT_OK, result)
intending(hasAction(PassCodeActivity.ACTION_REQUEST_WITH_RESULT)).respondWith(intentResult)
onView(withText(R.string.prefs_passcode)).perform(click())
}

private fun firstEnablePattern() {
val result = Intent()
result.putExtra(KEY_PATTERN, PATTERN_VALUE)
result.putExtra(keyPattern, patternValue)
val intentResult = Instrumentation.ActivityResult(Activity.RESULT_OK, result)
intending(hasAction(PatternLockActivity.ACTION_REQUEST_WITH_RESULT)).respondWith(intentResult)
onView(withText(R.string.prefs_pattern)).perform(click())
Expand Down

0 comments on commit f70fb18

Please sign in to comment.