Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8a542dc5 authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Cleanup displaylib tests

- Moves fakes from systemui to displaylib
- Makes DisplayRepositoryTest use kosmos for deps
- Adds docs to the DisplayRepositoryTest in display lib referring to the systemui test class
- Makes the choice to duplicate pairwiseBy deliberate

Bug: 362719719
Bug: 401305290
Test: DisplayRepositoryTest
Flag: NONE - Just a cleanup of tests
Change-Id: I98be434639d2749646d6156a83094da039130e05
parent 94691748
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -489,8 +489,10 @@ private sealed interface DisplayEvent {
 * upstream Flow.
 *
 * Useful for code that needs to compare the current value to the previous value.
 *
 * Note this has been taken from com.android.systemui.util.kotlin. It was copied to keep deps of
 * displaylib minimal (and avoid creating a new shared lib for it).
 */
// TODO b/401305290 - This should be moved to a shared lib, as it's also used by SystemUI.
fun <T, R> Flow<T>.pairwiseBy(transform: suspend (old: T, new: T) -> R): Flow<R> = flow {
    val noVal = Any()
    var previousValue: Any? = noVal
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.app.displaylib.fakes

import com.android.app.displaylib.PerDisplayRepository
import java.util.function.Consumer

/** Fake version of [PerDisplayRepository], to be used in tests. */
class FakePerDisplayRepository<T> : PerDisplayRepository<T> {

    private val instances = mutableMapOf<Int, T>()

    fun add(displayId: Int, instance: T) {
        instances[displayId] = instance
    }

    fun remove(displayId: Int) {
        instances.remove(displayId)
    }

    override fun get(displayId: Int): T? {
        return instances[displayId]
    }

    override val debugName: String
        get() = "FakePerDisplayRepository"

    override fun forEach(createIfAbsent: Boolean, action: Consumer<T>) {
        instances.forEach { (_, t) -> action.accept(t) }
    }
}
+10 −6
Original line number Diff line number Diff line
@@ -19,9 +19,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class DisplayRepositoryTest {

    // TODO b/401305290 - Move tests from The SystemUI DisplayRepositoryImpl to here.
}
/**
 * Tests for display repository are in SystemUI:
 * frameworks/base/packages/SystemUI/multivalentTestsForDevice/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
 *
 * This is because the repository was initially there, and tests depend on kosmos for dependency
 * injection (which is sysui-specific).
 *
 * In case of changes, update tests in sysui.
 */
@SmallTest @RunWith(AndroidJUnit4::class) class DisplayRepositoryTest