1/*
2 * Copyright (C) 2017 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
17package com.android.systemui.util.leak;
18
19import static org.junit.Assert.assertEquals;
20
21import android.support.test.filters.SmallTest;
22import android.support.test.runner.AndroidJUnit4;
23
24import com.android.systemui.SysuiTestCase;
25
26import org.junit.Test;
27import org.junit.runner.RunWith;
28
29@SmallTest
30@RunWith(AndroidJUnit4.class)
31public class ReferenceTestUtilsTest extends SysuiTestCase {
32
33    @Test
34    public void testCollectionWaiter_doesntBlockIndefinitely() {
35        ReferenceTestUtils.createCollectionWaiter(new Object()).waitForCollection();
36    }
37
38    @Test
39    public void testConditionWaiter_doesntBlockIndefinitely() {
40        ReferenceTestUtils.waitForCondition(() -> true);
41    }
42
43    @Test
44    public void testConditionWaiter_waitsUntilConditionIsTrue() {
45        int[] countHolder = new int[]{0};
46
47        ReferenceTestUtils.waitForCondition(() -> {
48            countHolder[0] += 1;
49            return countHolder[0] >= 5;
50        });
51
52        assertEquals(5, countHolder[0]);
53    }
54}
55