@Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { assertThat(command).isInstanceOf(WrappedRunnable.class); lastMethodCalled = "scheduleRunnable"; lastDelay = delay; lastUnit = unit; return null; }
@Override public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { assertThat(callable).isInstanceOf(WrappedCallable.class); lastMethodCalled = "scheduleCallable"; lastDelay = delay; lastUnit = unit; return null; }
@Override public void execute(Runnable runnable) { assertThat(runnable).isInstanceOf(TrustedListenableFutureTask.class); runnable.run(); }
@Override public <T> Future<T> submit(Runnable task, T result) { lastMethodCalled = "submit"; assertThat(task).isInstanceOf(WrappedRunnable.class); return inline.submit(task, result); }
@Override public <T> Future<T> submit(Callable<T> task) { lastMethodCalled = "submit"; assertThat(task).isInstanceOf(WrappedCallable.class); return inline.submit(task); }
@Override public Future<?> submit(Runnable task) { lastMethodCalled = "submit"; assertThat(task).isInstanceOf(WrappedRunnable.class); return inline.submit(task); }
@Override public void execute(Runnable command) { lastMethodCalled = "execute"; assertThat(command).isInstanceOf(WrappedRunnable.class); inline.execute(command); }
public void testMultiDimensionalGenericArrayType() { TypeToken<List<Long>[][][]> token = new TypeToken<List<Long>[][][]>() {}; assertEquals(List[][][].class, token.getRawType()); assertThat(token.getType()).isInstanceOf(GenericArrayType.class); }
public void testGenericArrayType() { TypeToken<List<String>[]> token = new TypeToken<List<String>[]>() {}; assertEquals(List[].class, token.getRawType()); assertThat(token.getType()).isInstanceOf(GenericArrayType.class); }
public void testGetSubtype_genericSubtypeOfGenericTypeWithFewerParameters() { TypeToken<List<String>> supertype = new TypeToken<List<String>>() {}; TypeToken<MySpecialList<String, ?>> subtype = new TypeToken<MySpecialList<String, ?>>() {}; assertTrue(subtype.isSubtypeOf(supertype)); ParameterizedType actualSubtype = (ParameterizedType) supertype.getSubtype(subtype.getRawType()).getType(); assertEquals(MySpecialList.class, actualSubtype.getRawType()); assertThat(actualSubtype.getActualTypeArguments()[0]).isEqualTo(String.class); assertThat(actualSubtype.getActualTypeArguments()[1]).isInstanceOf(TypeVariable.class); assertTrue(TypeToken.of(actualSubtype).isSubtypeOf(supertype)); }
public void testGetSubtype_genericSubtypeOfNonGenericType() { TypeToken<Serializable> supertype = new TypeToken<Serializable>() {}; TypeToken<ArrayList<String>> subtype = new TypeToken<ArrayList<String>>() {}; assertTrue(subtype.isSubtypeOf(supertype)); ParameterizedType actualSubtype = (ParameterizedType) supertype.getSubtype(subtype.getRawType()).getType(); assertEquals(ArrayList.class, actualSubtype.getRawType()); assertThat(actualSubtype.getActualTypeArguments()[0]).isInstanceOf(TypeVariable.class); assertTrue(TypeToken.of(actualSubtype).isSubtypeOf(supertype)); }
public void testCreate() { Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod")); assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class); // a thread-safe method should not create a synchronized subscriber Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod")); assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class); }
public void testSetWeakKeys() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().weakKeys()); checkStrength(map, Strength.WEAK, Strength.STRONG); assertThat(map.entryHelper) .isInstanceOf(MapMakerInternalMap.WeakKeyStrongValueEntry.Helper.class); }
public void testCatchingAsync_getThrowsError() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingError(new MyError()); // We'd catch only MyError.class here, but then the test won't compile under GWT. ListenableFuture<Object> output = catchingAsync(input, Throwable.class, asyncIdentity(), directExecutor()); assertThat(getDone(output)).isInstanceOf(MyError.class); }
public void testCatching_getThrowsError() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingError(new MyError()); // We'd catch only MyError.class here, but then the test won't compile under GWT. ListenableFuture<Object> output = catching(input, Throwable.class, identity(), directExecutor()); assertThat(getDone(output)).isInstanceOf(MyError.class); }
public void testSetWeakValues() { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(createMapMaker().weakValues()); checkStrength(map, Strength.STRONG, Strength.WEAK); assertThat(map.entryHelper) .isInstanceOf(MapMakerInternalMap.StrongKeyWeakValueEntry.Helper.class); }
public void testCatchingAsync_getThrowsRuntimeException() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingRuntimeException(new MyRuntimeException()); // We'd catch only MyRuntimeException.class here, but then the test won't compile under GWT. ListenableFuture<Object> output = catchingAsync(input, Throwable.class, asyncIdentity(), directExecutor()); assertThat(getDone(output)).isInstanceOf(MyRuntimeException.class); }
public void testCatching_getThrowsRuntimeException() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingRuntimeException(new MyRuntimeException()); // We'd catch only MyRuntimeException.class here, but then the test won't compile under GWT. ListenableFuture<Object> output = catching(input, Throwable.class, identity(), directExecutor()); assertThat(getDone(output)).isInstanceOf(MyRuntimeException.class); }
@Test public void immutableValueGraph() { MutableValueGraph<String, Integer> mutableValueGraph = ValueGraphBuilder.directed().build(); mutableValueGraph.addNode("A"); ImmutableValueGraph<String, Integer> immutableValueGraph = ImmutableValueGraph.copyOf(mutableValueGraph); assertThat(immutableValueGraph.asGraph()).isInstanceOf(ImmutableGraph.class); assertThat(immutableValueGraph).isNotInstanceOf(MutableValueGraph.class); assertThat(immutableValueGraph).isEqualTo(mutableValueGraph); mutableValueGraph.addNode("B"); assertThat(immutableValueGraph).isNotEqualTo(mutableValueGraph); }
@Test public void immutableNetwork() { MutableNetwork<String, Integer> mutableNetwork = NetworkBuilder.directed().build(); mutableNetwork.addNode("A"); ImmutableNetwork<String, Integer> immutableNetwork = ImmutableNetwork.copyOf(mutableNetwork); assertThat(immutableNetwork.asGraph()).isInstanceOf(ImmutableGraph.class); assertThat(immutableNetwork).isNotInstanceOf(MutableNetwork.class); assertThat(immutableNetwork).isEqualTo(mutableNetwork); mutableNetwork.addNode("B"); assertThat(immutableNetwork).isNotEqualTo(mutableNetwork); }