2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.util;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
16 import com.google.common.collect.ImmutableList;
17 import com.google.common.collect.Lists;
18 import com.google.common.collect.UnmodifiableIterator;
19 import java.util.Collection;
20 import java.util.Iterator;
21 import java.util.List;
22 import org.junit.Test;
24 public class UnmodifiableCollectionTest {
27 public void testUnmodifiableCollection() {
28 final List<Integer> immutableTestList = ImmutableList.<Integer>builder()
35 final Collection<Integer> testUnmodifiableCollection = UnmodifiableCollection.create(immutableTestList);
36 assertNotNull(testUnmodifiableCollection);
38 final List<Integer> testList = Lists.newArrayList();
45 final Collection<Integer> testUnmodifiableCollection2 = UnmodifiableCollection.create(testList);
47 final Iterator<Integer> iterator = testUnmodifiableCollection2.iterator();
48 assertNotNull(iterator);
49 assertTrue(iterator instanceof UnmodifiableIterator);
51 assertEquals(5, testUnmodifiableCollection2.size());
53 assertFalse(testUnmodifiableCollection2.isEmpty());
55 assertTrue(testUnmodifiableCollection2.contains(1));
57 final Object[] objectArray = testUnmodifiableCollection2.toArray();
58 assertNotNull(objectArray);
59 assertEquals(5, objectArray.length);
61 final Integer[] integerArray = testUnmodifiableCollection2.toArray(
62 new Integer[testUnmodifiableCollection2.size()]);
63 assertNotNull(integerArray);
64 assertEquals(5, integerArray.length);
66 assertTrue(testUnmodifiableCollection2.containsAll(testUnmodifiableCollection));
68 assertEquals("UnmodifiableCollection{" + testList + "}", testUnmodifiableCollection2.toString());