Search in sources :

Example 46 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class MapsTest method bucketsOf.

// reflection
@GwtIncompatible
private static int bucketsOf(HashMap<?, ?> hashMap) throws Exception {
    Field tableField = HashMap.class.getDeclaredField("table");
    tableField.setAccessible(true);
    Object[] table = (Object[]) tableField.get(hashMap);
    // In JDK8, table is set lazily, so it may be null.
    return table == null ? 0 : table.length;
}
Also used : Field(java.lang.reflect.Field) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 47 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class SetsTest method testsForFilterNoNulls.

// suite
@GwtIncompatible
private static Test testsForFilterNoNulls() {
    TestSuite suite = new TestSuite();
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        public Set<String> create(String[] elements) {
            Set<String> unfiltered = Sets.newLinkedHashSet();
            unfiltered.add("yyy");
            unfiltered.addAll(ImmutableList.copyOf(elements));
            unfiltered.add("zzz");
            return Sets.filter(unfiltered, Collections2Test.LENGTH_1);
        }
    }).named("Sets.filter, no nulls").withFeatures(CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        public NavigableSet<String> create(String[] elements) {
            NavigableSet<String> unfiltered = Sets.newTreeSet();
            unfiltered.add("yyy");
            unfiltered.addAll(ImmutableList.copyOf(elements));
            unfiltered.add("zzz");
            return Sets.filter(unfiltered, Collections2Test.LENGTH_1);
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return Ordering.natural().sortedCopy(insertionOrder);
        }
    }).named("Sets.filter[NavigableSet]").withFeatures(CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    return suite;
}
Also used : TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) NavigableSet(java.util.NavigableSet) SortedSet(java.util.SortedSet) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Sets.powerSet(com.google.common.collect.Sets.powerSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestSuite(junit.framework.TestSuite) List(java.util.List) ArrayList(java.util.ArrayList) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 48 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class SetsTest method suite.

// suite
@GwtIncompatible
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(SetsTest.class);
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            return Sets.newConcurrentHashSet(Arrays.asList(elements));
        }
    }).named("Sets.newConcurrentHashSet").withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            int size = elements.length;
            // Remove last element, if size > 1
            Set<String> set1 = (size > 1) ? Sets.newHashSet(Arrays.asList(elements).subList(0, size - 1)) : Sets.newHashSet(elements);
            // Remove first element, if size > 0
            Set<String> set2 = (size > 0) ? Sets.newHashSet(Arrays.asList(elements).subList(1, size)) : Sets.<String>newHashSet();
            return Sets.union(set1, set2);
        }
    }).named("Sets.union").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Set<String> set1 = Sets.newHashSet(elements);
            set1.add(samples().e3());
            Set<String> set2 = Sets.newHashSet(elements);
            set2.add(samples().e4());
            return Sets.intersection(set1, set2);
        }
    }).named("Sets.intersection").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Set<String> set1 = Sets.newHashSet(elements);
            set1.add(samples().e3());
            Set<String> set2 = Sets.newHashSet(samples().e3());
            return Sets.difference(set1, set2);
        }
    }).named("Sets.difference").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestEnumSetGenerator() {

        @Override
        protected Set<AnEnum> create(AnEnum[] elements) {
            AnEnum[] otherElements = new AnEnum[elements.length - 1];
            System.arraycopy(elements, 1, otherElements, 0, otherElements.length);
            return Sets.immutableEnumSet(elements[0], otherElements);
        }
    }).named("Sets.immutableEnumSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            SafeTreeSet<String> set = new SafeTreeSet<>(Arrays.asList(elements));
            return Sets.unmodifiableNavigableSet(set);
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return Ordering.natural().sortedCopy(insertionOrder);
        }
    }).named("Sets.unmodifiableNavigableSet[TreeSet]").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE).createTestSuite());
    suite.addTest(testsForFilter());
    suite.addTest(testsForFilterNoNulls());
    suite.addTest(testsForFilterFiltered());
    return suite;
}
Also used : SortedSet(java.util.SortedSet) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Sets.powerSet(com.google.common.collect.Sets.powerSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) TestSuite(junit.framework.TestSuite) AnEnum(com.google.common.collect.testing.AnEnum) List(java.util.List) ArrayList(java.util.ArrayList) TestEnumSetGenerator(com.google.common.collect.testing.TestEnumSetGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 49 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class SetsTest method testImmutableEnumSet_deserializationMakesDefensiveCopy.

// java serialization not supported in GWT.
@GwtIncompatible
public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exception {
    ImmutableSet<SomeEnum> original = Sets.immutableEnumSet(SomeEnum.A, SomeEnum.B);
    int handleOffset = 6;
    byte[] serializedForm = serializeWithBackReference(original, handleOffset);
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedForm));
    ImmutableSet<?> deserialized = (ImmutableSet<?>) in.readObject();
    EnumSet<?> delegate = (EnumSet<?>) in.readObject();
    assertEquals(original, deserialized);
    assertTrue(delegate.remove(SomeEnum.A));
    assertTrue(deserialized.contains(SomeEnum.A));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) ObjectInputStream(java.io.ObjectInputStream) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 50 with GwtIncompatible

use of com.google.common.annotations.GwtIncompatible in project guava by google.

the class IterablesTest method testNullPointerExceptions.

// NullPointerTester
@GwtIncompatible
public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicStaticMethods(Iterables.class);
}
Also used : NullPointerTester(com.google.common.testing.NullPointerTester) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

GwtIncompatible (com.google.common.annotations.GwtIncompatible)361 NullPointerTester (com.google.common.testing.NullPointerTester)105 TestSuite (junit.framework.TestSuite)54 BigInteger (java.math.BigInteger)40 RoundingMode (java.math.RoundingMode)39 CountDownLatch (java.util.concurrent.CountDownLatch)25 ExecutorService (java.util.concurrent.ExecutorService)18 CancellationException (java.util.concurrent.CancellationException)17 Random (java.util.Random)16 ListTestSuiteBuilder (com.google.common.collect.testing.ListTestSuiteBuilder)15 ExecutionException (java.util.concurrent.ExecutionException)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 IOException (java.io.IOException)14 BigDecimal (java.math.BigDecimal)14 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)11 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)11 TimeoutException (java.util.concurrent.TimeoutException)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 EqualsTester (com.google.common.testing.EqualsTester)10 List (java.util.List)10