Search in sources :

Example 16 with GwtIncompatible

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

the class PreconditionsTest method testAllOverloads_checkState.

@GwtIncompatible("Reflection")
public void testAllOverloads_checkState() throws Exception {
    for (ImmutableList<Class<?>> sig : allSignatures(boolean.class)) {
        Method checkArgumentMethod = Preconditions.class.getMethod("checkState", sig.toArray(new Class<?>[] {}));
        checkArgumentMethod.invoke(null, /* static method */
        getParametersForSignature(true, sig));
        Object[] failingParams = getParametersForSignature(false, sig);
        try {
            checkArgumentMethod.invoke(null, /* static method */
            failingParams);
            fail();
        } catch (InvocationTargetException ite) {
            assertFailureCause(ite.getCause(), IllegalStateException.class, failingParams);
        }
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 17 with GwtIncompatible

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

the class PreconditionsTest method testAllOverloads_checkArgument.

@GwtIncompatible("Reflection")
public void testAllOverloads_checkArgument() throws Exception {
    for (ImmutableList<Class<?>> sig : allSignatures(boolean.class)) {
        Method checkArgumentMethod = Preconditions.class.getMethod("checkArgument", sig.toArray(new Class<?>[] {}));
        checkArgumentMethod.invoke(null, /* static method */
        getParametersForSignature(true, sig));
        Object[] failingParams = getParametersForSignature(false, sig);
        try {
            checkArgumentMethod.invoke(null, /* static method */
            failingParams);
            fail();
        } catch (InvocationTargetException ite) {
            assertFailureCause(ite.getCause(), IllegalArgumentException.class, failingParams);
        }
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 18 with GwtIncompatible

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

the class PredicatesTest method testContainsPattern_nulls.

// NullPointerTester
@GwtIncompatible
public void testContainsPattern_nulls() throws Exception {
    NullPointerTester tester = new NullPointerTester();
    Predicate<CharSequence> isWooString = Predicates.containsPattern("Woo");
    tester.testAllPublicInstanceMethods(isWooString);
}
Also used : NullPointerTester(com.google.common.testing.NullPointerTester) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 19 with GwtIncompatible

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

the class SuppliersTest method testSupplierThreadSafe.

// Thread
@GwtIncompatible
public void testSupplierThreadSafe(Function<Supplier<Boolean>, Supplier<Boolean>> memoizer) throws Throwable {
    final AtomicInteger count = new AtomicInteger(0);
    final AtomicReference<Throwable> thrown = new AtomicReference<>(null);
    final int numThreads = 3;
    final Thread[] threads = new Thread[numThreads];
    final long timeout = TimeUnit.SECONDS.toNanos(60);
    final Supplier<Boolean> supplier = new Supplier<Boolean>() {

        boolean isWaiting(Thread thread) {
            switch(thread.getState()) {
                case BLOCKED:
                case WAITING:
                case TIMED_WAITING:
                    return true;
                default:
                    return false;
            }
        }

        int waitingThreads() {
            int waitingThreads = 0;
            for (Thread thread : threads) {
                if (isWaiting(thread)) {
                    waitingThreads++;
                }
            }
            return waitingThreads;
        }

        @Override
        public Boolean get() {
            // Check that this method is called exactly once, by the first
            // thread to synchronize.
            long t0 = System.nanoTime();
            while (waitingThreads() != numThreads - 1) {
                if (System.nanoTime() - t0 > timeout) {
                    thrown.set(new TimeoutException("timed out waiting for other threads to block" + " synchronizing on supplier"));
                    break;
                }
                Thread.yield();
            }
            count.getAndIncrement();
            return Boolean.TRUE;
        }
    };
    final Supplier<Boolean> memoizedSupplier = memoizer.apply(supplier);
    for (int i = 0; i < numThreads; i++) {
        threads[i] = new Thread() {

            @Override
            public void run() {
                assertSame(Boolean.TRUE, memoizedSupplier.get());
            }
        };
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    if (thrown.get() != null) {
        throw thrown.get();
    }
    assertEquals(1, count.get());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeoutException(java.util.concurrent.TimeoutException) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 20 with GwtIncompatible

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

the class FunctionsTest method testNullPointerExceptions.

// NullPointerTester
@GwtIncompatible
public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicStaticMethods(Functions.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