Madan Jampani | 7a7ef6d | 2016-01-26 22:01:13 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Madan Jampani | 7a7ef6d | 2016-01-26 22:01:13 -0800 | [diff] [blame] | 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 | package org.onlab.util; |
| 17 | |
| 18 | import static org.junit.Assert.*; |
| 19 | |
| 20 | import java.util.concurrent.atomic.AtomicBoolean; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | |
| 24 | /** |
| 25 | * Unit tests for CountDownCompleter. |
| 26 | */ |
| 27 | public class CountDownCompleterTest { |
| 28 | |
| 29 | @Test |
| 30 | public void testCountDown() { |
| 31 | AtomicBoolean callbackInvoked = new AtomicBoolean(false); |
| 32 | CountDownCompleter<String> completer = new CountDownCompleter<>("foo", 2L, v -> callbackInvoked.set(true)); |
| 33 | completer.countDown(); |
| 34 | assertFalse(callbackInvoked.get()); |
| 35 | assertFalse(completer.isComplete()); |
| 36 | completer.countDown(); |
| 37 | assertTrue(callbackInvoked.get()); |
| 38 | assertTrue(completer.isComplete()); |
| 39 | } |
| 40 | } |