Migrate common/util to JUnit5
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / EmptyDequeTest.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.util;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertNull;
13 import static org.junit.jupiter.api.Assertions.assertSame;
14 import static org.junit.jupiter.api.Assertions.assertThrows;
15
16 import java.util.NoSuchElementException;
17 import org.junit.jupiter.api.Test;
18
19 class EmptyDequeTest {
20     @Test
21     void testEmptyDeque() {
22         final var deque = EmptyDeque.instance();
23         assertFalse(deque.offer(null));
24         assertFalse(deque.offerFirst(null));
25         assertFalse(deque.offerLast(null));
26         assertNull(deque.peek());
27         assertNull(deque.peekFirst());
28         assertNull(deque.peekLast());
29         assertNull(deque.poll());
30         assertNull(deque.pollFirst());
31         assertNull(deque.pollLast());
32
33         assertEquals(0, deque.size());
34         assertFalse(deque.iterator().hasNext());
35         assertFalse(deque.descendingIterator().hasNext());
36         assertEquals(0L, deque.spliterator().estimateSize());
37
38         final var a = deque.toArray();
39         assertEquals(0, a.length);
40         assertSame(a, deque.toArray());
41         assertSame(a, deque.toArray(a));
42
43         assertFalse(deque.removeFirstOccurrence(null));
44         assertFalse(deque.removeLastOccurrence(null));
45
46         assertThrows(IllegalStateException.class, () -> deque.push(null));
47         assertThrows(IllegalStateException.class, () -> deque.addFirst(null));
48         assertThrows(IllegalStateException.class, () -> deque.addLast(null));
49         assertThrows(NoSuchElementException.class, () -> deque.getFirst());
50         assertThrows(NoSuchElementException.class, () -> deque.getLast());
51         assertThrows(NoSuchElementException.class, () -> deque.pop());
52         assertThrows(NoSuchElementException.class, () -> deque.remove());
53         assertThrows(NoSuchElementException.class, () -> deque.removeFirst());
54         assertThrows(NoSuchElementException.class, () -> deque.removeLast());
55     }
56 }