Adrian Roos | e1e0b48 | 2017-02-02 16:00:59 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.util.leak; |
| 18 | |
| 19 | import static org.junit.Assert.assertEquals; |
| 20 | |
| 21 | import android.support.test.filters.SmallTest; |
| 22 | import android.support.test.runner.AndroidJUnit4; |
| 23 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 24 | import com.android.systemui.SysuiTestCase; |
| 25 | |
Adrian Roos | e1e0b48 | 2017-02-02 16:00:59 -0800 | [diff] [blame] | 26 | import org.junit.Test; |
| 27 | import org.junit.runner.RunWith; |
| 28 | |
| 29 | @SmallTest |
| 30 | @RunWith(AndroidJUnit4.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 31 | public class ReferenceTestUtilsTest extends SysuiTestCase { |
Adrian Roos | e1e0b48 | 2017-02-02 16:00:59 -0800 | [diff] [blame] | 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 | } |