Search in sources :

Example 11 with EnumSet

use of java.util.EnumSet in project robovm by robovm.

the class ClassCastExceptionTest method testHugeEnumSetAddAll.

public void testHugeEnumSetAddAll() throws Exception {
    EnumSet m = EnumSet.noneOf(HugeE.class);
    EnumSet n = EnumSet.allOf(HugeF.class);
    try {
        m.addAll(n);
        fail();
    } catch (ClassCastException ex) {
        ex.printStackTrace();
        assertNotNull(ex.getMessage());
    }
}
Also used : EnumSet(java.util.EnumSet)

Example 12 with EnumSet

use of java.util.EnumSet in project robovm by robovm.

the class EnumSetTest method test_addAll_LCollection.

/**
     * java.util.EnumSet#addAll(Collection)
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_addAll_LCollection() {
    Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
    assertEquals("Size should be 0:", 0, set.size());
    try {
        set.addAll(null);
        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);
    assertTrue("addAll should be successful", result);
    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);
        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);
    assertTrue("addAll should be successful", result);
    assertEquals("Size of set should be 2", 2, set.size());
    try {
        fullSet.addAll(null);
        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);
        fail("Should throw ClassCastException");
    } catch (ClassCastException e) {
    // expected
    }
    Set<EnumWithInnerClass> setWithSubclass = fullSetWithSubclass;
    result = setWithSubclass.addAll(setWithSubclass);
    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);
    assertFalse("Should return false", result);
    anotherSetWithSubclass.remove(EnumWithInnerClass.a);
    result = setWithSubclass.addAll(anotherSetWithSubclass);
    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);
        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);
        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);
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Set hugeSetWithSubclass = EnumSet.allOf(HugeEnumWithInnerClass.class);
    try {
        hugeSet.addAll(hugeSetWithSubclass);
        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)

Example 13 with EnumSet

use of java.util.EnumSet in project robovm by robovm.

the class EnumSetTest method test_removeAll_LCollection.

/**
     * java.util.EnumSet#removeAll(Collection)
     */
@SuppressWarnings("unchecked")
public void test_removeAll_LCollection() {
    Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
    try {
        set.removeAll(null);
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    set = EnumSet.allOf(EnumFoo.class);
    assertEquals("Size of set should be 64:", 64, set.size());
    try {
        set.removeAll(null);
        fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
    collection.add(EnumFoo.a);
    boolean result = set.removeAll(collection);
    assertTrue("Should return true", result);
    assertEquals("Size of set should be 63", 63, set.size());
    collection = new ArrayList();
    result = set.removeAll(collection);
    assertFalse("Should return false", result);
    Set<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
    result = set.removeAll(emptySet);
    assertFalse("Should return false", result);
    EnumSet<EnumFoo> emptyFooSet = EnumSet.noneOf(EnumFoo.class);
    result = set.removeAll(emptyFooSet);
    assertFalse("Should return false", result);
    emptyFooSet.add(EnumFoo.a);
    result = set.removeAll(emptyFooSet);
    assertFalse("Should return false", result);
    Set<EnumWithInnerClass> setWithSubclass = EnumSet.noneOf(EnumWithInnerClass.class);
    result = set.removeAll(setWithSubclass);
    assertFalse("Should return false", result);
    setWithSubclass.add(EnumWithInnerClass.a);
    result = set.removeAll(setWithSubclass);
    assertFalse("Should return false", result);
    Set<EnumFoo> anotherSet = EnumSet.noneOf(EnumFoo.class);
    anotherSet.add(EnumFoo.a);
    set = EnumSet.allOf(EnumFoo.class);
    result = set.removeAll(anotherSet);
    assertTrue("Should return true", result);
    assertEquals("Size of set should be 63:", 63, set.size());
    Set<EnumWithInnerClass> setWithInnerClass = EnumSet.noneOf(EnumWithInnerClass.class);
    setWithInnerClass.add(EnumWithInnerClass.a);
    setWithInnerClass.add(EnumWithInnerClass.b);
    Set<EnumWithInnerClass> anotherSetWithInnerClass = EnumSet.noneOf(EnumWithInnerClass.class);
    anotherSetWithInnerClass.add(EnumWithInnerClass.c);
    anotherSetWithInnerClass.add(EnumWithInnerClass.d);
    result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
    assertFalse("Should return false", result);
    anotherSetWithInnerClass.add(EnumWithInnerClass.a);
    result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
    assertTrue("Should return true", result);
    assertEquals("Size of anotherSetWithInnerClass should remain 2", 2, anotherSetWithInnerClass.size());
    anotherSetWithInnerClass.remove(EnumWithInnerClass.c);
    anotherSetWithInnerClass.remove(EnumWithInnerClass.d);
    result = anotherSetWithInnerClass.remove(setWithInnerClass);
    assertFalse("Should return false", result);
    Set rawSet = EnumSet.allOf(EnumWithAllInnerClass.class);
    result = rawSet.removeAll(EnumSet.allOf(EnumFoo.class));
    assertFalse("Should return false", result);
    setWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
    anotherSetWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
    setWithInnerClass.remove(EnumWithInnerClass.a);
    anotherSetWithInnerClass.remove(EnumWithInnerClass.f);
    result = setWithInnerClass.removeAll(anotherSetWithInnerClass);
    assertTrue("Should return true", result);
    assertEquals("Size of setWithInnerClass should be 1", 1, setWithInnerClass.size());
    result = setWithInnerClass.contains(EnumWithInnerClass.f);
    assertTrue("Should return true", result);
    // test enum type with more than 64 elements
    Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
    Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
    hugeCollection.add(HugeEnum.a);
    result = hugeSet.removeAll(hugeCollection);
    assertTrue(result);
    assertEquals(64, hugeSet.size());
    collection = new ArrayList();
    result = hugeSet.removeAll(collection);
    assertFalse(result);
    Set<HugeEnum> emptyHugeSet = EnumSet.noneOf(HugeEnum.class);
    result = hugeSet.removeAll(emptyHugeSet);
    assertFalse(result);
    Set<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
    result = hugeSet.removeAll(hugeSetWithSubclass);
    assertFalse(result);
    hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
    result = hugeSet.removeAll(hugeSetWithSubclass);
    assertFalse(result);
    Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
    anotherHugeSet.add(HugeEnum.a);
    hugeSet = EnumSet.allOf(HugeEnum.class);
    result = hugeSet.removeAll(anotherHugeSet);
    assertTrue(result);
    assertEquals(63, set.size());
    Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
    hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
    hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
    Set<HugeEnumWithInnerClass> anotherHugeSetWithInnerClass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
    anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.c);
    anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.d);
    result = anotherHugeSetWithInnerClass.removeAll(setWithInnerClass);
    assertFalse("Should return false", result);
    anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
    result = anotherHugeSetWithInnerClass.removeAll(hugeSetWithInnerClass);
    assertTrue(result);
    assertEquals(2, anotherHugeSetWithInnerClass.size());
    anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.c);
    anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.d);
    result = anotherHugeSetWithInnerClass.remove(hugeSetWithInnerClass);
    assertFalse(result);
    rawSet = EnumSet.allOf(HugeEnumWithInnerClass.class);
    result = rawSet.removeAll(EnumSet.allOf(HugeEnum.class));
    assertFalse(result);
    hugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
    anotherHugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
    hugeSetWithInnerClass.remove(HugeEnumWithInnerClass.a);
    anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.f);
    result = hugeSetWithInnerClass.removeAll(anotherHugeSetWithInnerClass);
    assertTrue(result);
    assertEquals(1, hugeSetWithInnerClass.size());
    result = hugeSetWithInnerClass.contains(HugeEnumWithInnerClass.f);
    assertTrue(result);
}
Also used : Set(java.util.Set) EnumSet(java.util.EnumSet) ArrayList(java.util.ArrayList)

Example 14 with EnumSet

use of java.util.EnumSet in project spring-boot by spring-projects.

the class WebFilterHandlerTests method defaultFilterConfiguration.

@SuppressWarnings("unchecked")
@Test
public void defaultFilterConfiguration() throws IOException {
    ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(new SimpleMetadataReaderFactory().getMetadataReader(DefaultConfigurationFilter.class.getName()));
    this.handler.handle(scanned, this.registry);
    BeanDefinition filterRegistrationBean = this.registry.getBeanDefinition(DefaultConfigurationFilter.class.getName());
    MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
    assertThat(propertyValues.get("asyncSupported")).isEqualTo(false);
    assertThat((EnumSet<DispatcherType>) propertyValues.get("dispatcherTypes")).containsExactly(DispatcherType.REQUEST);
    assertThat(((Map<String, String>) propertyValues.get("initParameters"))).isEmpty();
    assertThat((String[]) propertyValues.get("servletNames")).isEmpty();
    assertThat((String[]) propertyValues.get("urlPatterns")).isEmpty();
    assertThat(propertyValues.get("name")).isEqualTo(DefaultConfigurationFilter.class.getName());
    assertThat(propertyValues.get("filter")).isEqualTo(scanned);
}
Also used : SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) ScannedGenericBeanDefinition(org.springframework.context.annotation.ScannedGenericBeanDefinition) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) EnumSet(java.util.EnumSet) ScannedGenericBeanDefinition(org.springframework.context.annotation.ScannedGenericBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 15 with EnumSet

use of java.util.EnumSet in project spring-boot by spring-projects.

the class SecurityAutoConfigurationTests method customFilterDispatcherTypes.

@Test
public void customFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.filter-dispatcher-types:INCLUDE,ERROR");
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked") EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils.getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).containsOnly(DispatcherType.INCLUDE, DispatcherType.ERROR);
}
Also used : DelegatingFilterProxyRegistrationBean(org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean) EnumSet(java.util.EnumSet) DispatcherType(javax.servlet.DispatcherType) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Aggregations

EnumSet (java.util.EnumSet)58 Set (java.util.Set)18 Map (java.util.Map)16 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 TreeSet (java.util.TreeSet)7 Test (org.junit.Test)7 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 List (java.util.List)5 TreeMap (java.util.TreeMap)5 StateStorage.toStringStringSetMap (org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap)5 PathAddress (org.jboss.as.controller.PathAddress)5 PathElement (org.jboss.as.controller.PathElement)5 ModelNode (org.jboss.dmr.ModelNode)5 FeatureState (org.apache.karaf.features.FeatureState)4 Nullable (com.android.annotations.Nullable)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2