Search in sources :

Example 61 with Collection

use of java.util.Collection in project grails-core by grails.

the class BeanBuilder method bean.

/**
     * Defines an inner bean definition.
     *
     * @param type The bean type
     * @param args The constructors arguments and closure configurer
     * @return The bean definition
     */
@SuppressWarnings("rawtypes")
public AbstractBeanDefinition bean(Class type, Object... args) {
    BeanConfiguration current = currentBeanConfig;
    try {
        Closure callable = null;
        Collection constructorArgs = null;
        if (args != null && args.length > 0) {
            int index = args.length;
            Object lastArg = args[index - 1];
            if (lastArg instanceof Closure) {
                callable = (Closure) lastArg;
                index--;
            }
            if (index > -1) {
                constructorArgs = resolveConstructorArguments(args, 0, index);
            }
        }
        currentBeanConfig = constructorArgs == null ? springConfig.createSingletonBean(type) : springConfig.createSingletonBean(type, constructorArgs);
        if (callable != null) {
            callable.call(new Object[] { currentBeanConfig });
        }
        return currentBeanConfig.getBeanDefinition();
    } finally {
        currentBeanConfig = current;
    }
}
Also used : Closure(groovy.lang.Closure) Collection(java.util.Collection) GroovyObject(groovy.lang.GroovyObject) DefaultBeanConfiguration(org.grails.spring.DefaultBeanConfiguration) BeanConfiguration(org.grails.spring.BeanConfiguration)

Example 62 with Collection

use of java.util.Collection in project j2objc by google.

the class CollectionsTest method test_asLifoQueue.

/**
     * @tests {@link java.util.Collections#asLifoQueue(Deque)
     */
public void test_asLifoQueue() throws Exception {
    Integer[] testInt = new Integer[100];
    Integer test101 = new Integer(101);
    for (int i = 0; i < testInt.length; i++) {
        testInt[i] = new Integer(i);
    }
    Deque deque = new ArrayDeque<Integer>();
    Queue<Integer> que = Collections.asLifoQueue(deque);
    for (int i = 0; i < testInt.length; i++) {
        que.add(testInt[i]);
    }
    assertEquals(100, deque.size());
    assertEquals(100, que.size());
    for (int i = testInt.length - 1; i >= 0; i--) {
        assertEquals(testInt[i], deque.pop());
    }
    assertEquals(0, deque.size());
    assertEquals(0, que.size());
    for (int i = 0; i < testInt.length; i++) {
        deque.push(testInt[i]);
    }
    assertEquals(100, deque.size());
    assertEquals(100, que.size());
    Collection col = new LinkedList<Integer>();
    col.add(test101);
    que.addAll(col);
    assertEquals(test101, que.remove());
    for (int i = testInt.length - 1; i >= 0; i--) {
        assertEquals(testInt[i], que.remove());
    }
    assertEquals(0, deque.size());
    assertEquals(0, que.size());
}
Also used : Collection(java.util.Collection) Deque(java.util.Deque) ArrayDeque(java.util.ArrayDeque) ArrayDeque(java.util.ArrayDeque) LinkedList(java.util.LinkedList)

Example 63 with Collection

use of java.util.Collection in project j2objc by google.

the class EnumMapTest method test_entrySet.

/**
     * @tests java.util.EnumMap#entrySet()
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_entrySet() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    MockEntry mockEntry = new MockEntry(Size.Middle, 1);
    Set set = enumSizeMap.entrySet();
    Set set1 = enumSizeMap.entrySet();
    //$NON-NLS-1$
    assertSame("Should be same", set1, set);
    try {
        set.add(mockEntry);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    mockEntry = new MockEntry(Size.Middle, null);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Small));
    mockEntry = new MockEntry(new Integer(1), 1);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(new Integer(1)));
    mockEntry = new MockEntry(Size.Big, null);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    mockEntry = new MockEntry(new Integer(1), 1);
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(new Integer(1)));
    // The set is backed by the map so changes to one are reflected by the
    // other.
    enumSizeMap.put(Size.Big, 3);
    mockEntry = new MockEntry(Size.Big, 3);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Collection c = new ArrayList();
    c.add(new MockEntry(Size.Middle, 1));
    //$NON-NLS-1$
    assertTrue("Return wrong value", set.containsAll(c));
    //$NON-NLS-1$
    assertTrue("Remove does not success", set.removeAll(c));
    enumSizeMap.put(Size.Middle, 1);
    c.add(new MockEntry(Size.Big, 3));
    //$NON-NLS-1$
    assertTrue("Remove does not success", set.removeAll(c));
    //$NON-NLS-1$
    assertFalse("Should return false", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    c = new ArrayList();
    c.add(new MockEntry(Size.Middle, 1));
    c.add(new MockEntry(Size.Big, 3));
    //$NON-NLS-1$
    assertTrue("Retain does not success", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.retainAll(c));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Object[] array = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 2, array.length);
    Map.Entry entry = (Map.Entry) array[0];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertEquals("Wrong value", 1, entry.getValue());
    Object[] array1 = new Object[10];
    array1 = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 2, array1.length);
    entry = (Map.Entry) array[0];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertEquals("Wrong value", 1, entry.getValue());
    array1 = new Object[10];
    array1 = set.toArray(array1);
    //$NON-NLS-1$
    assertEquals("Wrong length", 10, array1.length);
    entry = (Map.Entry) array[1];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, entry.getKey());
    //$NON-NLS-1$
    assertNull("Should be null", array1[2]);
    set = enumSizeMap.entrySet();
    //$NON-NLS-1$
    Integer integer = new Integer("1");
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(integer));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(entry));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Iterator iter = set.iterator();
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    mockEntry = new MockEntry(Size.Middle, 2);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    mockEntry = new MockEntry(new Integer(2), 2);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.remove(Size.Big);
    mockEntry = new MockEntry(Size.Big, null);
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Returned true for uncontained object", set.contains(mockEntry));
    enumSizeMap.put(Size.Big, 2);
    mockEntry = new MockEntry(Size.Big, 2);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    iter.remove();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        entry.setValue(2);
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        set.contains(entry);
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    iter = set.iterator();
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    enumSizeMap.put(Size.Middle, 3);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    entry.setValue(2);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.remove(new Integer(1)));
    iter.next();
    //The following test case fails on RI.
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    iter = set.iterator();
    mockEntry = new MockEntry(Size.Middle, 1);
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertTrue("Should return true", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Should be equal", mockEntry.hashCode(), entry.hashCode());
    mockEntry = new MockEntry(Size.Big, 1);
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, entry.getKey());
    iter.remove();
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        iter.next();
        //$NON-NLS-1$
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Expected
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map) HashMap(java.util.HashMap) NoSuchElementException(java.util.NoSuchElementException)

Example 64 with Collection

use of java.util.Collection in project j2objc by google.

the class EnumMapTest method test_keySet.

/**
     * @tests java.util.EnumMap#keySet()
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_keySet() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 2);
    enumSizeMap.put(Size.Big, null);
    Set set = enumSizeMap.keySet();
    Set set1 = enumSizeMap.keySet();
    //$NON-NLS-1$
    assertSame("Should be same", set1, set);
    try {
        set.add(Size.Big);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Middle));
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Big));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Small));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(new Integer(1)));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(Size.Big));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Big));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(Size.Big));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(new Integer(1)));
    // The set is backed by the map so changes to one are reflected by the
    // other.
    enumSizeMap.put(Size.Big, 3);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Big));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Big));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    Collection c = new ArrayList();
    c.add(Size.Big);
    //$NON-NLS-1$
    assertTrue("Should return true", set.containsAll(c));
    c.add(Size.Small);
    //$NON-NLS-1$
    assertFalse("Should return false", set.containsAll(c));
    //$NON-NLS-1$
    assertTrue("Should return true", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    try {
        set.addAll(c);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    enumSizeMap.put(Size.Big, null);
    //$NON-NLS-1$
    assertEquals("Wrong size", 2, set.size());
    //$NON-NLS-1$
    assertTrue("Should return true", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.retainAll(c));
    assertEquals(1, set.size());
    Object[] array = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 1, array.length);
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, array[0]);
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    c = new ArrayList();
    c.add(Color.Blue);
    //$NON-NLS-1$
    assertFalse("Should return false", set.remove(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 2, set.size());
    //$NON-NLS-1$
    assertTrue("Should return true", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    Iterator iter = set.iterator();
    Enum enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    iter.remove();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    iter = set.iterator();
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap.put(Size.Middle, 3);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    iter = set.iterator();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, enumKey);
    //$NON-NLS-1$
    assertSame("Wrong key", Size.Middle, enumKey);
    //$NON-NLS-1$
    assertFalse("Returned true for unequal object", iter.equals(enumKey));
    iter.remove();
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, enumKey);
    iter.remove();
    try {
        iter.next();
        //$NON-NLS-1$
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Expected
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) EnumMap(java.util.EnumMap) NoSuchElementException(java.util.NoSuchElementException)

Example 65 with Collection

use of java.util.Collection in project j2objc by google.

the class EnumSetTest method test_addAll_LCollection.

/**
     * @tests java.util.EnumSet#addAll(Collection)
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_addAll_LCollection() {
    Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
    //$NON-NLS-1$
    assertEquals("Size should be 0:", 0, set.size());
    try {
        set.addAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Set emptySet = EnumSet.noneOf(EmptyEnum.class);
    Enum[] elements = EmptyEnum.class.getEnumConstants();
    for (int i = 0; i < elements.length; i++) {
        emptySet.add(elements[i]);
    }
    boolean result = set.addAll(emptySet);
    assertFalse(result);
    Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
    collection.add(EnumFoo.a);
    collection.add(EnumFoo.b);
    result = set.addAll(collection);
    //$NON-NLS-1$
    assertTrue("addAll should be successful", result);
    //$NON-NLS-1$
    assertEquals("Size should be 2:", 2, set.size());
    set = EnumSet.noneOf(EnumFoo.class);
    Collection rawCollection = new ArrayList<Integer>();
    result = set.addAll(rawCollection);
    assertFalse(result);
    rawCollection.add(1);
    try {
        set.addAll(rawCollection);
        //$NON-NLS-1$
        fail("Should throw ClassCastException");
    } catch (ClassCastException e) {
    // expected
    }
    Set<EnumFoo> fullSet = EnumSet.noneOf(EnumFoo.class);
    fullSet.add(EnumFoo.a);
    fullSet.add(EnumFoo.b);
    result = set.addAll(fullSet);
    //$NON-NLS-1$
    assertTrue("addAll should be successful", result);
    //$NON-NLS-1$
    assertEquals("Size of set should be 2", 2, set.size());
    try {
        fullSet.addAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Set fullSetWithSubclass = EnumSet.noneOf(EnumWithInnerClass.class);
    elements = EnumWithInnerClass.class.getEnumConstants();
    for (int i = 0; i < elements.length; i++) {
        fullSetWithSubclass.add(elements[i]);
    }
    try {
        set.addAll(fullSetWithSubclass);
        //$NON-NLS-1$
        fail("Should throw ClassCastException");
    } catch (ClassCastException e) {
    // expected
    }
    Set<EnumWithInnerClass> setWithSubclass = fullSetWithSubclass;
    result = setWithSubclass.addAll(setWithSubclass);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    Set<EnumWithInnerClass> anotherSetWithSubclass = EnumSet.noneOf(EnumWithInnerClass.class);
    elements = EnumWithInnerClass.class.getEnumConstants();
    for (int i = 0; i < elements.length; i++) {
        anotherSetWithSubclass.add((EnumWithInnerClass) elements[i]);
    }
    result = setWithSubclass.addAll(anotherSetWithSubclass);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    anotherSetWithSubclass.remove(EnumWithInnerClass.a);
    result = setWithSubclass.addAll(anotherSetWithSubclass);
    //$NON-NLS-1$
    assertFalse("Should return false", result);
    // test enum type with more than 64 elements
    Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
    assertEquals(0, hugeSet.size());
    try {
        hugeSet.addAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    hugeSet = EnumSet.allOf(HugeEnum.class);
    result = hugeSet.addAll(hugeSet);
    assertFalse(result);
    hugeSet = EnumSet.noneOf(HugeEnum.class);
    Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
    hugeCollection.add(HugeEnum.a);
    hugeCollection.add(HugeEnum.b);
    result = hugeSet.addAll(hugeCollection);
    assertTrue(result);
    assertEquals(2, set.size());
    hugeSet = EnumSet.noneOf(HugeEnum.class);
    rawCollection = new ArrayList<Integer>();
    result = hugeSet.addAll(rawCollection);
    assertFalse(result);
    rawCollection.add(1);
    try {
        hugeSet.addAll(rawCollection);
        //$NON-NLS-1$
        fail("Should throw ClassCastException");
    } catch (ClassCastException e) {
    // expected
    }
    EnumSet<HugeEnum> aHugeSet = EnumSet.noneOf(HugeEnum.class);
    aHugeSet.add(HugeEnum.a);
    aHugeSet.add(HugeEnum.b);
    result = hugeSet.addAll(aHugeSet);
    assertTrue(result);
    assertEquals(2, hugeSet.size());
    try {
        aHugeSet.addAll(null);
        //$NON-NLS-1$
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Set hugeSetWithSubclass = EnumSet.allOf(HugeEnumWithInnerClass.class);
    try {
        hugeSet.addAll(hugeSetWithSubclass);
        //$NON-NLS-1$
        fail("Should throw ClassCastException");
    } catch (ClassCastException e) {
    // expected
    }
    Set<HugeEnumWithInnerClass> hugeSetWithInnerSubclass = hugeSetWithSubclass;
    result = hugeSetWithInnerSubclass.addAll(hugeSetWithInnerSubclass);
    assertFalse(result);
    Set<HugeEnumWithInnerClass> anotherHugeSetWithSubclass = EnumSet.allOf(HugeEnumWithInnerClass.class);
    result = hugeSetWithSubclass.addAll(anotherHugeSetWithSubclass);
    assertFalse(result);
    anotherHugeSetWithSubclass.remove(HugeEnumWithInnerClass.a);
    result = setWithSubclass.addAll(anotherSetWithSubclass);
    assertFalse(result);
}
Also used : Set(java.util.Set) EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Aggregations

Collection (java.util.Collection)3392 ArrayList (java.util.ArrayList)983 Map (java.util.Map)732 Test (org.junit.Test)669 HashMap (java.util.HashMap)570 List (java.util.List)521 Iterator (java.util.Iterator)386 HashSet (java.util.HashSet)333 Set (java.util.Set)314 IOException (java.io.IOException)308 Collectors (java.util.stream.Collectors)155 File (java.io.File)135 LinkedHashMap (java.util.LinkedHashMap)112 Collections (java.util.Collections)100 LinkedList (java.util.LinkedList)96 Arrays (java.util.Arrays)84 UUID (java.util.UUID)80 Test (org.testng.annotations.Test)79 NotNull (org.jetbrains.annotations.NotNull)78 Field (java.lang.reflect.Field)77