Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): Update kotlin to 1.9 #587

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ indent_style=space
indent_size=4
continuation_indent_size=4
insert_final_newline=true
disabled_rules=import-ordering
import_ordering=disabled
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ repositories {
}

android {
compileSdk 33
compileSdk 34
ndkVersion '21.3.6528147'

defaultConfig {
applicationId "tech.relaycorp.courier"
minSdk 23
targetSdk 33
targetSdk 34
versionCode 1
versionName project.findProperty("versionName") ?: "0.1"

Expand Down Expand Up @@ -128,8 +128,8 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'

// Dependency Injection
api 'com.google.dagger:dagger:2.43.2'
kapt 'com.google.dagger:dagger-compiler:2.43.2'
api 'com.google.dagger:dagger:2.48.1'
kapt 'com.google.dagger:dagger-compiler:2.48.1'

// Awala
implementation 'tech.relaycorp:awala:1.66.4'
Expand Down Expand Up @@ -198,7 +198,7 @@ configurations.all {

spotless {
kotlin {
ktlint('0.43.2').userData(['disabled_rules': 'import-ordering'])
ktlint '1.0.1'
target '**/*.kt'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import javax.inject.Singleton
@Component(
modules = [
AppModule::class,
DataModule::class
]
DataModule::class,
],
)
interface TestAppComponent : AppComponent {
fun inject(app: TestApp)
Expand All @@ -27,6 +27,8 @@ interface TestAppComponent : AppComponent {
// Tests

fun inject(test: MainActivityTest)

fun inject(test: PrivateSyncTest)

fun inject(test: SettingsActivityTest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import java.util.Date

@RunWith(AndroidJUnit4::class)
class StoredMessageDaoTest {

private lateinit var storedMessageDao: StoredMessageDao

@Before
Expand All @@ -24,47 +23,52 @@ class StoredMessageDaoTest {
}

@Test
fun insertAndGet() = runTest(testDispatcher) {
val messages = StoredMessageFactory.build()
storedMessageDao.insert(messages)
assertEquals(
listOf(messages),
storedMessageDao.observeAll().first()
)
}
fun insertAndGet() =
runTest(testDispatcher) {
val messages = StoredMessageFactory.build()
storedMessageDao.insert(messages)
assertEquals(
listOf(messages),
storedMessageDao.observeAll().first(),
)
}

@Test
fun observeTotalSize() = runTest(testDispatcher) {
assertEquals(
StorageSize.ZERO,
storedMessageDao.observeTotalSize().first()
)
fun observeTotalSize() =
runTest(testDispatcher) {
assertEquals(
StorageSize.ZERO,
storedMessageDao.observeTotalSize().first(),
)

val messages =
(1..3)
.map { StoredMessageFactory.build() }
.also { it.map { c -> storedMessageDao.insert(c) } }
val messages =
(1..3)
.map { StoredMessageFactory.build() }
.also { it.map { c -> storedMessageDao.insert(c) } }

assertEquals(
messages.map { it.size.bytes }.sum(),
storedMessageDao.observeTotalSize().first().bytes
)
}
assertEquals(
messages.map { it.size.bytes }.sum(),
storedMessageDao.observeTotalSize().first().bytes,
)
}

@Test
fun getExpiredBy() = runTest(testDispatcher) {
val date = Date()
val expiredMessage = StoredMessageFactory.build()
.copy(expirationTimeUtc = Date(date.time - 1))
val unexpiredMessage = StoredMessageFactory.build()
.copy(expirationTimeUtc = Date(date.time + 1))
fun getExpiredBy() =
runTest(testDispatcher) {
val date = Date()
val expiredMessage =
StoredMessageFactory.build()
.copy(expirationTimeUtc = Date(date.time - 1))
val unexpiredMessage =
StoredMessageFactory.build()
.copy(expirationTimeUtc = Date(date.time + 1))

storedMessageDao.insert(expiredMessage)
storedMessageDao.insert(unexpiredMessage)
storedMessageDao.insert(expiredMessage)
storedMessageDao.insert(unexpiredMessage)

assertEquals(
listOf(expiredMessage),
storedMessageDao.getExpiredBy(date)
)
}
assertEquals(
listOf(expiredMessage),
storedMessageDao.getExpiredBy(date),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import org.junit.Test
import tech.relaycorp.courier.data.model.StorageSize

internal class DiskStatsTest {

private val diskStats = DiskStats()

@Test
internal fun basicCheck() = runBlocking {
assertTrue(diskStats.getTotalStorage() > StorageSize.ZERO)
assertTrue(diskStats.getAvailableStorage() > StorageSize.ZERO)
assertTrue(diskStats.getAvailableStorage() < diskStats.getTotalStorage())
}
internal fun basicCheck() =
runBlocking {
assertTrue(diskStats.getTotalStorage() > StorageSize.ZERO)
assertTrue(diskStats.getAvailableStorage() > StorageSize.ZERO)
assertTrue(diskStats.getAvailableStorage() < diskStats.getTotalStorage())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import tech.relaycorp.courier.test.AppTestProvider.flowSharedPreferences
import tech.relaycorp.courier.test.AppTestProvider.testDispatcher

class StoragePreferencesTest {

private val preferences = StoragePreferences { flowSharedPreferences }

@Before
Expand All @@ -25,18 +24,19 @@ class StoragePreferencesTest {
}

@Test
fun maxStorage() = runTest(testDispatcher) {
assertEquals(
StoragePreferences.DEFAULT_MAX_STORAGE_SIZE,
preferences.getMaxStorageSize().first()
)

val newSize = StorageSize(100)
preferences.setMaxStorageSize(newSize)

assertEquals(
newSize,
preferences.getMaxStorageSize().first()
)
}
fun maxStorage() =
runTest(testDispatcher) {
assertEquals(
StoragePreferences.DEFAULT_MAX_STORAGE_SIZE,
preferences.getMaxStorageSize().first(),
)

val newSize = StorageSize(100)
preferences.setMaxStorageSize(newSize)

assertEquals(
newSize,
preferences.getMaxStorageSize().first(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject

class PrivateSyncTest {

@Inject
lateinit var privateSync: PrivateSync

Expand All @@ -35,7 +34,7 @@ class PrivateSyncTest {
// Related issue: https://github.com/relaycorp/relaynet-courier-android/issues/584
assumeTrue(
"Test is currently failing on API 23 and lower due to a grpc internal issue",
Build.VERSION.SDK_INT >= 24
Build.VERSION.SDK_INT >= 24,
)

Networking.androidGatewaySubnetPrefix = null
Expand All @@ -57,7 +56,7 @@ class PrivateSyncTest {
OkHTTPChannelBuilderProvider
.makeBuilder(
InetSocketAddress(gatewayIpAddress, 21473),
PrivateSubnetTrustManager.INSTANCE
PrivateSubnetTrustManager.INSTANCE,
)
.hostnameVerifier { _, _ -> true }
.build()
Expand All @@ -66,8 +65,8 @@ class PrivateSyncTest {
private val client by lazy {
CargoRelayGrpc.newStub(clientChannel).withInterceptors(
MetadataUtils.newAttachHeadersInterceptor(
AuthorizationMetadata.makeMetadata("CCA".toByteArray())
)
AuthorizationMetadata.makeMetadata("CCA".toByteArray()),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@ import kotlin.reflect.KClass

class BaseActivityTestRule<T : Activity>(
activityClass: KClass<T>,
launchActivity: Boolean = true
launchActivity: Boolean = true,
) : TestRule {

private val clearPreferencesRule: ClearPreferencesRule = ClearPreferencesRule()
private val clearDatabaseRule: ClearTestDatabaseRule = ClearTestDatabaseRule()
private val clearFilesRule: ClearFilesRule = ClearFilesRule()
private val flakyTestRule: FlakyTestRule = FlakyTestRule().apply {
allowFlakyAttemptsByDefault(5)
}
private val activityTestRule: ActivityTestRule<T> = ActivityTestRule(
activityClass.java,
true,
launchActivity
)
private val flakyTestRule: FlakyTestRule =
FlakyTestRule().apply {
allowFlakyAttemptsByDefault(5)
}
private val activityTestRule: ActivityTestRule<T> =
ActivityTestRule(
activityClass.java,
true,
launchActivity,
)

override fun apply(base: Statement, description: Description): Statement {
override fun apply(
base: Statement,
description: Description,
): Statement {
return RuleChain
.outerRule(flakyTestRule)
.around(activityTestRule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import tech.relaycorp.courier.data.database.AppDatabase
import javax.inject.Inject

class ClearTestDatabaseRule : TestRule {

@Inject
lateinit var database: AppDatabase

override fun apply(base: Statement, description: Description?) =
object : Statement() {
override fun evaluate() {
appComponent.inject(this@ClearTestDatabaseRule)
database.clearAllTables()
base.evaluate()
database.clearAllTables()
}
override fun apply(
base: Statement,
description: Description?,
) = object : Statement() {
override fun evaluate() {
appComponent.inject(this@ClearTestDatabaseRule)
database.clearAllTables()
base.evaluate()
database.clearAllTables()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.content.Context
import androidx.test.runner.AndroidJUnitRunner

class TestAndroidJUnitRunner : AndroidJUnitRunner() {
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?) =
super.newApplication(cl, TestApp::class.java.name, context)!!
override fun newApplication(
cl: ClassLoader?,
className: String?,
context: Context?,
) = super.newApplication(cl, TestApp::class.java.name, context)!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import tech.relaycorp.courier.ui.common.format
import javax.inject.Inject

class MainActivityTest {

@JvmField
@Rule
val activityTestRule = BaseActivityTestRule(MainActivity::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tech.relaycorp.courier.ui.settings

import androidx.test.espresso.Espresso.onIdle
import com.google.android.material.slider.Slider
import com.adevinta.android.barista.assertion.BaristaEnabledAssertions.assertDisabled
import com.adevinta.android.barista.assertion.BaristaEnabledAssertions.assertEnabled
import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions.assertContains
import com.google.android.material.slider.Slider
import junit.framework.TestCase.assertEquals
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
Expand All @@ -25,7 +25,6 @@ import tech.relaycorp.courier.test.factory.StoredMessageFactory
import javax.inject.Inject

class SettingsActivityTest {

@Rule
@JvmField
val testRule = BaseActivityTestRule(SettingsActivity::class, false)
Expand Down Expand Up @@ -55,13 +54,14 @@ class SettingsActivityTest {
}

@Test
fun clearButtonDisabledWithData() = runTest(StandardTestDispatcher()) {
storedMessageDao.insert(StoredMessageFactory.build())
advanceUntilIdle()
testRule.start()
onIdle()
assertEnabled(R.id.deleteData)
}
fun clearButtonDisabledWithData() =
runTest(StandardTestDispatcher()) {
storedMessageDao.insert(StoredMessageFactory.build())
advanceUntilIdle()
testRule.start()
onIdle()
assertEnabled(R.id.deleteData)
}

@Test
fun setMaxStorageToMinimum() {
Expand All @@ -72,7 +72,7 @@ class SettingsActivityTest {
slider.value = slider.valueFrom
assertEquals(
SettingsViewModel.MIN_STORAGE_SIZE,
storagePreferences.getMaxStorageSize().first()
storagePreferences.getMaxStorageSize().first(),
)
}
}
Expand Down
Loading
Loading