Organize Imports to be Checkstyle compliant in utils
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / SingletonSetTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.assertTrue;
15
16 import java.util.Collections;
17 import java.util.Iterator;
18 import org.junit.Test;
19
20 public class SingletonSetTest {
21     private static final String ELEMENT = "element";
22
23     private static SingletonSet<?> nullSet() {
24         return SingletonSet.of(null);
25     }
26
27     @Test
28     public void testNullSingleton() {
29         final SingletonSet<?> s = nullSet();
30
31         assertFalse(s.isEmpty());
32         assertEquals(1, s.size());
33         assertFalse(s.contains(""));
34         assertTrue(s.contains(null));
35         assertNull(s.getElement());
36         assertEquals(0, s.hashCode());
37         assertTrue(s.equals(Collections.singleton(null)));
38         assertFalse(s.equals(Collections.singleton("")));
39         assertFalse(s.equals(""));
40         assertTrue(s.equals(s));
41         assertFalse(s.equals(null));
42         assertEquals(Collections.singleton(null).toString(), s.toString());
43     }
44
45     @Test
46     public void testRegularSingleton() {
47         final SingletonSet<?> s = SingletonSet.of(ELEMENT);
48
49         assertFalse(s.isEmpty());
50         assertEquals(1, s.size());
51         assertFalse(s.contains(""));
52         assertFalse(s.contains(null));
53         assertTrue(s.contains(ELEMENT));
54
55         assertSame(ELEMENT, s.getElement());
56         assertEquals(ELEMENT.hashCode(), s.hashCode());
57         assertTrue(s.equals(Collections.singleton(ELEMENT)));
58         assertFalse(s.equals(Collections.singleton("")));
59         assertFalse(s.equals(Collections.singleton(null)));
60         assertFalse(s.equals(""));
61         assertTrue(s.equals(s));
62         assertFalse(s.equals(null));
63         assertEquals(Collections.singleton(ELEMENT).toString(), s.toString());
64     }
65
66     @Test
67     public void testIterator() {
68         final SingletonSet<?> s = SingletonSet.of(ELEMENT);
69         final Iterator<?> it = s.iterator();
70
71         assertTrue(it.hasNext());
72         assertSame(ELEMENT, it.next());
73         assertFalse(it.hasNext());
74     }
75
76     @Test(expected=UnsupportedOperationException.class)
77     public void testRejectedAdd() {
78         final SingletonSet<?> s = nullSet();
79         s.add(null);
80     }
81
82     @Test(expected=UnsupportedOperationException.class)
83     public void testRejectedAddAll() {
84         final SingletonSet<?> s = nullSet();
85         s.addAll(null);
86     }
87
88     @Test(expected=UnsupportedOperationException.class)
89     public void testRejectedClear() {
90         final SingletonSet<?> s = nullSet();
91         s.clear();
92     }
93
94     @Test(expected=UnsupportedOperationException.class)
95     public void testRejectedRemove() {
96         final SingletonSet<?> s = nullSet();
97         s.remove(null);
98     }
99
100     @Test(expected=UnsupportedOperationException.class)
101     public void testRejectedRemoveAll() {
102         final SingletonSet<?> s = nullSet();
103         s.removeAll(null);
104     }
105
106     @Test(expected=UnsupportedOperationException.class)
107     public void testRejectedRetainAll() {
108         final SingletonSet<?> s = nullSet();
109         s.retainAll(null);
110     }
111 }