当前位置: 首页>>代码示例>>Java>>正文


Java GwtIncompatible类代码示例

本文整理汇总了Java中com.google.common.annotations.GwtIncompatible的典型用法代码示例。如果您正苦于以下问题:Java GwtIncompatible类的具体用法?Java GwtIncompatible怎么用?Java GwtIncompatible使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GwtIncompatible类属于com.google.common.annotations包,在下文中一共展示了GwtIncompatible类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPropagate_NoneDeclared_ErrorThrown

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // propagate
public void testPropagate_NoneDeclared_ErrorThrown() {
  Sample sample = new Sample() {
    @Override public void noneDeclared() {
      try {
        methodThatThrowsError();
      } catch (Throwable t) {
        throw Throwables.propagate(t);
      }
    }
  };

  // Expect the error to propagate as-is
  try {
    sample.noneDeclared();
    fail();
  } catch (SomeError expected) {
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:20,代码来源:ThrowablesTest.java

示例2: testToString_ToStringTwice

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // Class names are obfuscated in GWT
public void testToString_ToStringTwice() {
  MoreObjects.ToStringHelper helper =
      MoreObjects.toStringHelper(new TestClass())
          .add("field1", 1)
          .addValue("value1")
          .add("field2", "value2");
  final String expected = "TestClass{field1=1, value1, field2=value2}";

  assertEquals(expected, helper.toString());
  // Call toString again
  assertEquals(expected, helper.toString());

  // Make sure the cached value is reset when we modify the helper at all
  final String expected2 = "TestClass{field1=1, value1, field2=value2, 2}";
  helper.addValue(2);
  assertEquals(expected2, helper.toString());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:ToStringHelperTest.java

示例3: testMakeChecked_listenersRunOnFailure

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // makeChecked

  public void testMakeChecked_listenersRunOnFailure() throws Exception {
    SettableFuture<String> future = SettableFuture.create();

    CheckedFuture<String, TestException> checked = makeChecked(
        future, new Function<Exception, TestException>() {
          @Override
          public TestException apply(Exception from) {
            throw new NullPointerException();
          }
        });

    ListenableFutureTester tester = new ListenableFutureTester(checked);
    tester.setUp();
    future.setException(new Exception("failed"));
    tester.testFailedFuture("failed");
    tester.tearDown();
  }
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:FuturesTest.java

示例4: propagateIfPossible

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // propagateIfPossible(Throwable, Class)
public void testPropagateIfPossible_OneDeclared_UncheckedThrown()
    throws SomeCheckedException {
  Sample sample = new Sample() {
    @Override public void oneDeclared() throws SomeCheckedException {
      try {
        methodThatThrowsUnchecked();
      } catch (Throwable t) {
        Throwables.propagateIfPossible(t, SomeCheckedException.class);
        throw new SomeChainingException(t);
      }
    }
  };

  // Expect the unchecked exception to propagate as-is
  try {
    sample.oneDeclared();
    fail();
  } catch (SomeUncheckedException expected) {
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:22,代码来源:ThrowablesTest.java

示例5: takeUninterruptibly

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
/**
 * Invokes {@code queue.}{@link BlockingQueue#take() take()} uninterruptibly.
 */
@GwtIncompatible // concurrency
public static <E> E takeUninterruptibly(BlockingQueue<E> queue) {
  boolean interrupted = false;
  try {
    while (true) {
      try {
        return queue.take();
      } catch (InterruptedException e) {
        interrupted = true;
      }
    }
  } finally {
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:21,代码来源:Uninterruptibles.java

示例6: testImmutableEnumSet_deserializationMakesDefensiveCopy

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // java serialization not supported in GWT.
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));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:17,代码来源:SetsTest.java

示例7: testCancellingADelegateDoesNotPropagate

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // inCompletionOrder
public void testCancellingADelegateDoesNotPropagate() throws Exception {
  SettableFuture<Long> future1 = SettableFuture.create();
  SettableFuture<Long> future2 = SettableFuture.create();

  ImmutableList<ListenableFuture<Long>> delegates = inCompletionOrder(
      ImmutableList.<ListenableFuture<Long>>of(future1, future2));

  future1.set(1L);
  // Cannot cancel a complete delegate
  assertFalse(delegates.get(0).cancel(true));
  // Cancel the delegate before the input future is done
  assertTrue(delegates.get(1).cancel(true));
  // Setting the future still works since cancellation didn't propagate
  assertTrue(future2.set(2L));
  // Second check to ensure the input future was not cancelled
  assertEquals((Long) 2L, getDone(future2));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:19,代码来源:FuturesTest.java

示例8: testsForFilterFiltered

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // suite
private static Test testsForFilterFiltered() {
  return CollectionTestSuiteBuilder.using(
      new TestStringCollectionGenerator() {
        @Override public Collection<String> create(String[] elements) {
          List<String> unfiltered = newArrayList();
          unfiltered.add("yyy");
          unfiltered.addAll(ImmutableList.copyOf(elements));
          unfiltered.add("zzz");
          unfiltered.add("abc");
          return Collections2.filter(
              Collections2.filter(unfiltered, LENGTH_1), NOT_YYY_ZZZ);
        }
      })
      .named("Collections2.filter, filtered input")
      .withFeatures(
          CollectionFeature.SUPPORTS_ADD,
          CollectionFeature.SUPPORTS_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.ALLOWS_NULL_QUERIES,
          CollectionSize.ANY)
      .createTestSuite();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:24,代码来源:Collections2Test.java

示例9: lazyStackTrace

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // lazyStackTrace(Throwable)
public void testLazyStackTrace() {
  Exception e = new Exception();
  StackTraceElement[] originalStackTrace = e.getStackTrace();

  assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder();

  try {
    lazyStackTrace(e).set(0, null);
    fail();
  } catch (UnsupportedOperationException expected) {
  }

  // Now we test a property that holds only for the lazy implementation.

  if (!lazyStackTraceIsLazy()) {
    return;
  }

  e.setStackTrace(new StackTraceElement[0]);
  assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:23,代码来源:ThrowablesTest.java

示例10: testOnSuccessThrowsError

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // Mockito
public void testOnSuccessThrowsError() throws Exception {
  class TestError extends Error {}
  TestError error = new TestError();
  String result = "result";
  SettableFuture<String> future = SettableFuture.create();
  @SuppressWarnings("unchecked") // Safe for a mock
  FutureCallback<String> callback = Mockito.mock(FutureCallback.class);
  addCallback(future, callback, directExecutor());
  Mockito.doThrow(error).when(callback).onSuccess(result);
  try {
    future.set(result);
    fail("Should have thrown");
  } catch (TestError e) {
    assertSame(error, e);
  }
  assertEquals(result, future.get());
  Mockito.verify(callback).onSuccess(result);
  Mockito.verifyNoMoreInteractions(callback);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:FutureCallbackTest.java

示例11: binomial

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
/**
 * Returns {@code n} choose {@code k}, also known as the binomial coefficient of {@code n} and
 * {@code k}, or {@link Integer#MAX_VALUE} if the result does not fit in an {@code int}.
 *
 * @throws IllegalArgumentException if {@code n < 0}, {@code k < 0} or {@code k > n}
 */
@GwtIncompatible // need BigIntegerMath to adequately test
public static int binomial(int n, int k) {
  checkNonNegative("n", n);
  checkNonNegative("k", k);
  checkArgument(k <= n, "k (%s) > n (%s)", k, n);
  if (k > (n >> 1)) {
    k = n - k;
  }
  if (k >= biggestBinomials.length || n > biggestBinomials[k]) {
    return Integer.MAX_VALUE;
  }
  switch (k) {
    case 0:
      return 1;
    case 1:
      return n;
    default:
      long result = 1;
      for (int i = 0; i < k; i++) {
        result *= n - i;
        result /= i + 1;
      }
      return (int) result;
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:32,代码来源:IntMath.java

示例12: testCatchingAsync_resultCancelledAfterFallback

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // mocks
// TODO(cpovirk): eliminate use of mocks
@SuppressWarnings("unchecked")
public void testCatchingAsync_resultCancelledAfterFallback() throws Exception {
  final SettableFuture<Integer> secondary = SettableFuture.create();
  final RuntimeException raisedException = new RuntimeException();
  AsyncFunctionSpy<Throwable, Integer> fallback = spy(new AsyncFunction<Throwable, Integer>() {
    @Override
    public ListenableFuture<Integer> apply(Throwable t) throws Exception {
      assertThat(t).isSameAs(raisedException);
      return secondary;
    }
  });

  ListenableFuture<Integer> failingFuture = immediateFailedFuture(raisedException);

  ListenableFuture<Integer> derived =
      catchingAsync(failingFuture, Throwable.class, fallback, directExecutor());
  derived.cancel(false);
  assertTrue(secondary.isCancelled());
  assertFalse(secondary.wasInterrupted());
  fallback.verifyCallCount(1);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:24,代码来源:FuturesTest.java

示例13: testPropagateIfPossible_NoneDeclared_UncheckedThrown

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // propagateIfPossible
public void testPropagateIfPossible_NoneDeclared_UncheckedThrown() {
  Sample sample = new Sample() {
    @Override public void noneDeclared() {
      try {
        methodThatThrowsUnchecked();
      } catch (Throwable t) {
        Throwables.propagateIfPossible(t);
        throw new SomeChainingException(t);
      }
    }
  };

  // Expect the unchecked exception to propagate as-is
  try {
    sample.noneDeclared();
    fail();
  } catch (SomeUncheckedException expected) {
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:21,代码来源:ThrowablesTest.java

示例14: testAsAsyncCallable

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible
public void testAsAsyncCallable() throws Exception {
  final String expected = "MyCallableString";
  Callable<String> callable = new Callable<String>() {
    @Override
    public String call() throws Exception {
      return expected;
    }
  };

  AsyncCallable<String> asyncCallable =
      Callables.asAsyncCallable(callable, MoreExecutors.newDirectExecutorService());

  ListenableFuture<String> future = asyncCallable.call();
  assertSame(expected, future.get());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:17,代码来源:CallablesTest.java

示例15: readObject

import com.google.common.annotations.GwtIncompatible; //导入依赖的package包/类
@GwtIncompatible // java.io.ObjectInputStream
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  @SuppressWarnings("unchecked")
  // reading data stored by writeObject
  Comparator<? super E> comparator = (Comparator<? super E>) stream.readObject();
  Serialization.getFieldSetter(AbstractSortedMultiset.class, "comparator").set(this, comparator);
  Serialization.getFieldSetter(TreeMultiset.class, "range")
      .set(this, GeneralRange.all(comparator));
  Serialization.getFieldSetter(TreeMultiset.class, "rootReference")
      .set(this, new Reference<AvlNode<E>>());
  AvlNode<E> header = new AvlNode<E>(null, 1);
  Serialization.getFieldSetter(TreeMultiset.class, "header").set(this, header);
  successor(header, header);
  Serialization.populateMultiset(this, stream);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:TreeMultiset.java


注:本文中的com.google.common.annotations.GwtIncompatible类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。