Merge branch 'master' of ../controller
[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.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertSame;
14 import static org.junit.Assert.fail;
15
16 import java.util.NoSuchElementException;
17 import org.junit.Test;
18
19 public class EmptyDequeTest {
20
21     @Test
22     public void testEmptyDeque() {
23         final EmptyDeque<?> deque = EmptyDeque.instance();
24         assertFalse(deque.offer(null));
25         assertFalse(deque.offerFirst(null));
26         assertFalse(deque.offerLast(null));
27         assertNull(deque.peek());
28         assertNull(deque.peekFirst());
29         assertNull(deque.peekLast());
30         assertNull(deque.poll());
31         assertNull(deque.pollFirst());
32         assertNull(deque.pollLast());
33
34         assertEquals(0, deque.size());
35         assertFalse(deque.iterator().hasNext());
36         assertFalse(deque.descendingIterator().hasNext());
37         assertEquals(0L, deque.spliterator().estimateSize());
38
39         final Object[] a = deque.toArray();
40         assertEquals(0, a.length);
41         assertSame(a, deque.toArray());
42         assertSame(a, deque.toArray(a));
43
44         assertFalse(deque.removeFirstOccurrence(null));
45         assertFalse(deque.removeLastOccurrence(null));
46
47         try {
48             deque.push(null);
49             fail();
50         } catch (IllegalStateException e) {
51             // expeced
52         }
53         try {
54             deque.addFirst(null);
55             fail();
56         } catch (IllegalStateException e) {
57             // expeced
58         }
59         try {
60             deque.addLast(null);
61             fail();
62         } catch (IllegalStateException e) {
63             // expeced
64         }
65
66         try {
67             deque.getFirst();
68             fail();
69         } catch (NoSuchElementException e) {
70             // expeced
71         }
72         try {
73             deque.getLast();
74             fail();
75         } catch (NoSuchElementException e) {
76             // expeced
77         }
78         try {
79             deque.pop();
80             fail();
81         } catch (NoSuchElementException e) {
82             // expeced
83         }
84         try {
85             deque.remove();
86             fail();
87         } catch (NoSuchElementException e) {
88             // expeced
89         }
90         try {
91             deque.removeFirst();
92             fail();
93         } catch (NoSuchElementException e) {
94             // expeced
95         }
96         try {
97             deque.removeLast();
98             fail();
99         } catch (NoSuchElementException e) {
100             // expeced
101         }
102     }
103 }