Skip to content
Permalink
Browse files

Changed uuid type to String

  • Loading branch information...
fercarcedo authored and pocmo committed Jun 14, 2018
1 parent b4d9e41 commit b9057672604a675f7d9edddc5d6707e07cef0b78
@@ -14,11 +14,11 @@ internal class DeviceUuidFactory(context: Context) {
val prefUuid = preferences.getString(PREF_UUID_KEY, null)

if (prefUuid != null) {
UUID.fromString(prefUuid)
UUID.fromString(prefUuid).toString()
} else {
val uuid = UUID.randomUUID()
preferences.edit().putString(PREF_UUID_KEY, uuid.toString()).apply()
uuid
uuid.toString()
}
}

@@ -53,7 +53,7 @@ internal class ExperimentEvaluator {
}

private fun getUserBucket(context: Context): Int {
val uuid = DeviceUuidFactory(context).uuid.toString()
val uuid = DeviceUuidFactory(context).uuid
val crc = CRC32()
crc.update(uuid.toByteArray())
val checksum = crc.value
@@ -7,7 +7,6 @@ package mozilla.components.service.fretboard
import android.content.Context
import android.content.SharedPreferences
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
@@ -19,7 +18,6 @@ import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.robolectric.RobolectricTestRunner
import java.util.UUID

@RunWith(RobolectricTestRunner::class)
class DeviceUuidFactoryTest {
@@ -33,8 +31,7 @@ class DeviceUuidFactoryTest {
`when`(sharedPreferences.getString(eq("device_uuid"), ArgumentMatchers.any())).thenReturn(null)
`when`(context.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPreferences)
val uuid = DeviceUuidFactory(context).uuid
assertTrue(uuid is UUID)
verify(editor).putString("device_uuid", uuid.toString())
verify(editor).putString("device_uuid", uuid)
}

@Test
@@ -44,6 +41,6 @@ class DeviceUuidFactoryTest {
val sharedPreferences = mock(SharedPreferences::class.java)
`when`(sharedPreferences.getString(eq("device_uuid"), any())).thenReturn(savedUuid)
`when`(context.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPreferences)
assertEquals(savedUuid, DeviceUuidFactory(context).uuid.toString())
assertEquals(savedUuid, DeviceUuidFactory(context).uuid)
}
}

0 comments on commit b905767

Please sign in to comment.
You can’t perform that action at this time.