1 /*
2  * Copyright 2020 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 androidx.paging
18 
19 import kotlin.test.assertEquals
20 
assertEventsnull21 fun <T> assertEvents(expected: List<T>, actual: List<T>) {
22     try {
23         assertEquals(expected, actual)
24     } catch (e: Throwable) {
25         val msg =
26             e.message!!
27                 .replace("),", "),\n")
28                 .replace("<[", "<[\n ")
29                 .replace("actual", "\nactual")
30                 .lines()
31                 .toMutableList()
32 
33         if (expected.count() != actual.count()) throw AssertionError(msg.joinToString("\n"))
34 
35         var index = 0
36         for (i in 0 until expected.count()) {
37             if (expected[i] != actual[i]) {
38                 index = i
39                 break
40             }
41         }
42         msg[index + 1] = msg[index + 1].prependIndent(" >")
43         msg[msg.count() / 2 + index + 1] = msg[msg.count() / 2 + index + 1].prependIndent(" >")
44         throw AssertionError(msg.joinToString("\n"))
45     }
46 }
47