-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Review: https://docs.google.com/document/d/1HvGIffjs3clWLzs0SNzLSKSzlzjIIesZOt6fhedo85Y/edit Also, make immediateCancelledFuture() available under GWT, since I use it in the new tests. To use cancellationExceptionWithCause() from it, I had to move that method out of the server-only AbstractFuture.java and into the shared Futures.java. This runs somewhat counter to my effort to make Futures.java smaller. Maybe we'll want a Util/Helpers class, though I'm not quite sure what else would go in it (executeListener? currently non-static maybePropagateCancellation?). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=116279071
- Loading branch information
Showing
7 changed files
with
194 additions
and
16 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
guava-gwt/test/com/google/common/util/concurrent/FuturesGetDoneTest_gwt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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 FuturesGetDoneTest_gwt extends com.google.gwt.junit.client.GWTTestCase { | ||
@Override public String getModuleName() { | ||
return "com.google.common.util.concurrent.testModule"; | ||
} | ||
public void testCancelled() throws Exception { | ||
com.google.common.util.concurrent.FuturesGetDoneTest testCase = new com.google.common.util.concurrent.FuturesGetDoneTest(); | ||
testCase.testCancelled(); | ||
} | ||
|
||
public void testFailed() throws Exception { | ||
com.google.common.util.concurrent.FuturesGetDoneTest testCase = new com.google.common.util.concurrent.FuturesGetDoneTest(); | ||
testCase.testFailed(); | ||
} | ||
|
||
public void testPending() throws Exception { | ||
com.google.common.util.concurrent.FuturesGetDoneTest testCase = new com.google.common.util.concurrent.FuturesGetDoneTest(); | ||
testCase.testPending(); | ||
} | ||
|
||
public void testSuccessful() throws Exception { | ||
com.google.common.util.concurrent.FuturesGetDoneTest testCase = new com.google.common.util.concurrent.FuturesGetDoneTest(); | ||
testCase.testSuccessful(); | ||
} | ||
|
||
public void testSuccessfulNull() throws Exception { | ||
com.google.common.util.concurrent.FuturesGetDoneTest testCase = new com.google.common.util.concurrent.FuturesGetDoneTest(); | ||
testCase.testSuccessfulNull(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
guava-tests/test/com/google/common/util/concurrent/FuturesGetDoneTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2016 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; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static com.google.common.util.concurrent.Futures.getDone; | ||
import static com.google.common.util.concurrent.Futures.immediateCancelledFuture; | ||
import static com.google.common.util.concurrent.Futures.immediateFailedFuture; | ||
import static com.google.common.util.concurrent.Futures.immediateFuture; | ||
|
||
import com.google.common.annotations.GwtCompatible; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Unit tests for {@link Futures#getDone}. | ||
*/ | ||
@GwtCompatible | ||
public class FuturesGetDoneTest extends TestCase { | ||
public void testSuccessful() throws ExecutionException { | ||
assertThat(getDone(immediateFuture("a"))).isEqualTo("a"); | ||
} | ||
|
||
public void testSuccessfulNull() throws ExecutionException { | ||
assertThat(getDone(immediateFuture((String) null))).isEqualTo(null); | ||
} | ||
|
||
public void testFailed() { | ||
Exception failureCause = new Exception(); | ||
try { | ||
getDone(immediateFailedFuture(failureCause)); | ||
fail(); | ||
} catch (ExecutionException expected) { | ||
assertThat(expected.getCause()).isEqualTo(failureCause); | ||
} | ||
} | ||
|
||
public void testCancelled() throws ExecutionException { | ||
try { | ||
getDone(immediateCancelledFuture()); | ||
fail(); | ||
} catch (CancellationException expected) { | ||
} | ||
} | ||
|
||
public void testPending() throws ExecutionException { | ||
try { | ||
getDone(SettableFuture.create()); | ||
fail(); | ||
} catch (IllegalStateException expected) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters