2 * Copyright (c) 2015 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
8 package org.opendaylight.yangtools.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import com.google.common.collect.ImmutableList;
15 import com.google.common.collect.Iterables;
16 import java.util.Collection;
17 import java.util.Collections;
18 import org.junit.Test;
20 public class ConstantArrayCollectionTest {
21 private static final String[] ARRAY = new String[] { "a", "bb", "ccc" };
22 private static final Collection<String> REF = ImmutableList.copyOf(ARRAY);
24 private static Collection<String> create() {
25 return new ConstantArrayCollection<>(ARRAY.clone());
29 public void testToString() {
31 assertEquals(Collections.emptySet().toString(), new ConstantArrayCollection<>(new Object[0]).toString());
34 assertEquals(REF.toString(), create().toString());
38 public void testEquals() {
39 final Collection<?> c = create();
41 assertTrue(c.containsAll(REF));
42 assertTrue(REF.containsAll(c));
43 assertTrue(Iterables.elementsEqual(REF, c));
47 public void testSimpleOperations() {
48 final Collection<?> c = create();
50 assertEquals(ARRAY.length, c.size());
51 assertFalse(c.isEmpty());
52 assertTrue(c.contains("ccc"));
53 assertFalse(c.contains(""));
54 assertFalse(c.contains(1));
56 assertTrue(c.containsAll(Collections.<String>emptyList()));
57 assertFalse(c.containsAll(Collections.singleton("")));
58 assertFalse(c.containsAll(Collections.singleton(1)));
62 public void testProtection() {
63 final Collection<?> c = create();
68 } catch (UnsupportedOperationException e) {
74 } catch (UnsupportedOperationException e) {
80 } catch (UnsupportedOperationException e) {
86 } catch (UnsupportedOperationException e) {
92 } catch (UnsupportedOperationException e) {
98 } catch (UnsupportedOperationException e) {