blob: b8a3e39f665c3e7c4bca907c3b5b2d70fe9fa6f8 [file] [log] [blame]
Adrian Roose1e0b482017-02-02 16:00:59 -08001/*
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
Jason Monkfba8faf2017-05-23 10:42:59 -040024import com.android.systemui.SysuiTestCase;
25
Adrian Roose1e0b482017-02-02 16:00:59 -080026import org.junit.Test;
27import org.junit.runner.RunWith;
28
29@SmallTest
30@RunWith(AndroidJUnit4.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040031public class ReferenceTestUtilsTest extends SysuiTestCase {
Adrian Roose1e0b482017-02-02 16:00:59 -080032
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}