1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.log.core
18 
19 import com.android.systemui.log.LogBuffer
20 import com.android.systemui.log.LogMessageImpl
21 import com.android.systemui.util.mockito.any
22 import com.android.systemui.util.mockito.mock
23 import com.android.systemui.util.mockito.nullable
24 import com.android.systemui.util.mockito.whenever
25 import org.mockito.Mockito.anyString
26 
27 /**
28  * A fake [LogBuffer] used for testing that obtains a real [LogMessage] to prevent a
29  * [NullPointerException].
30  */
31 class FakeLogBuffer private constructor() {
32     class Factory private constructor() {
33         companion object {
createnull34             fun create(): LogBuffer {
35                 val logBuffer = mock<LogBuffer>()
36                 whenever(
37                         logBuffer.obtain(
38                             tag = anyString(),
39                             level = any(),
40                             messagePrinter = any(),
41                             exception = nullable(),
42                         )
43                     )
44                     .thenReturn(LogMessageImpl.Factory.create())
45                 return logBuffer
46             }
47         }
48     }
49 }
50