Skip to content

Commit

Permalink
Make getUnchecked available under GWT.
Browse files Browse the repository at this point in the history
In service of the tests of forthcoming CL 177218820.

RELNOTES=`concurrent`: Made `Futures.getUnchecked` available under GWT.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177634486
  • Loading branch information
cpovirk committed Dec 1, 2017
1 parent 87dcd47 commit b1d9d99
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

import static com.google.common.util.concurrent.Futures.immediateFailedFuture;

import com.google.common.annotations.GwtCompatible;
import java.util.concurrent.Future;

/**
* Classes and futures used in {@link FuturesGetCheckedTest} and {@link FuturesGetUncheckedTest}.
*/
@GwtCompatible
final class FuturesGetCheckedInputs {
static final Exception CHECKED_EXCEPTION = new Exception("mymessage");
static final Future<String> FAILED_FUTURE_CHECKED_EXCEPTION =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@
import static com.google.common.util.concurrent.FuturesGetCheckedInputs.RUNTIME_EXCEPTION_FUTURE;
import static com.google.common.util.concurrent.FuturesGetCheckedInputs.UNCHECKED_EXCEPTION;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Future;
import junit.framework.TestCase;

/**
* Unit tests for {@link Futures#getUnchecked(Future)}.
*/
@GwtCompatible(emulated = true)
public class FuturesGetUncheckedTest extends TestCase {
public void testGetUnchecked_success() {
assertEquals("foo", getUnchecked(immediateFuture("foo")));
}

@GwtIncompatible // Thread.interrupt
public void testGetUnchecked_interrupted() {
Thread.currentThread().interrupt();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,6 @@ public static <V, X extends Exception> V getChecked(
* @since 10.0
*/
@CanIgnoreReturnValue
@GwtIncompatible // TODO
public static <V> V getUnchecked(Future<V> future) {
checkNotNull(future);
try {
Expand All @@ -1562,7 +1561,6 @@ public static <V> V getUnchecked(Future<V> future) {
}
}

@GwtIncompatible // TODO
private static void wrapAndThrowUnchecked(Throwable cause) {
if (cause instanceof Error) {
throw new ExecutionError((Error) cause);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2008 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.common.util.concurrent;
public class FuturesGetUncheckedTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.util.concurrent.testModule";
}
public void testGetUnchecked_Error() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_Error();
}

public void testGetUnchecked_ExecutionExceptionChecked() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_ExecutionExceptionChecked();
}

public void testGetUnchecked_ExecutionExceptionError() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_ExecutionExceptionError();
}

public void testGetUnchecked_ExecutionExceptionOtherThrowable() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_ExecutionExceptionOtherThrowable();
}

public void testGetUnchecked_ExecutionExceptionUnchecked() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_ExecutionExceptionUnchecked();
}

public void testGetUnchecked_RuntimeException() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_RuntimeException();
}

public void testGetUnchecked_cancelled() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_cancelled();
}

public void testGetUnchecked_success() throws Exception {
com.google.common.util.concurrent.FuturesGetUncheckedTest testCase = new com.google.common.util.concurrent.FuturesGetUncheckedTest();
testCase.testGetUnchecked_success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

import static com.google.common.util.concurrent.Futures.immediateFailedFuture;

import com.google.common.annotations.GwtCompatible;
import java.util.concurrent.Future;

/**
* Classes and futures used in {@link FuturesGetCheckedTest} and {@link FuturesGetUncheckedTest}.
*/
@GwtCompatible
final class FuturesGetCheckedInputs {
static final Exception CHECKED_EXCEPTION = new Exception("mymessage");
static final Future<String> FAILED_FUTURE_CHECKED_EXCEPTION =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@
import static com.google.common.util.concurrent.FuturesGetCheckedInputs.RUNTIME_EXCEPTION_FUTURE;
import static com.google.common.util.concurrent.FuturesGetCheckedInputs.UNCHECKED_EXCEPTION;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Future;
import junit.framework.TestCase;

/**
* Unit tests for {@link Futures#getUnchecked(Future)}.
*/
@GwtCompatible(emulated = true)
public class FuturesGetUncheckedTest extends TestCase {
public void testGetUnchecked_success() {
assertEquals("foo", getUnchecked(immediateFuture("foo")));
}

@GwtIncompatible // Thread.interrupt
public void testGetUnchecked_interrupted() {
Thread.currentThread().interrupt();
try {
Expand Down
2 changes: 0 additions & 2 deletions guava/src/com/google/common/util/concurrent/Futures.java
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,6 @@ public static <V, X extends Exception> V getChecked(
* @since 10.0
*/
@CanIgnoreReturnValue
@GwtIncompatible // TODO
public static <V> V getUnchecked(Future<V> future) {
checkNotNull(future);
try {
Expand All @@ -1562,7 +1561,6 @@ public static <V> V getUnchecked(Future<V> future) {
}
}

@GwtIncompatible // TODO
private static void wrapAndThrowUnchecked(Throwable cause) {
if (cause instanceof Error) {
throw new ExecutionError((Error) cause);
Expand Down

0 comments on commit b1d9d99

Please sign in to comment.