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

Commit 17c37a98 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Cleanup displaylib tests" into main

parents 2acb85fa 8a542dc5
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