1/*
2 * Copyright (C) 2009 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.util.concurrent;
18
19import junit.framework.TestCase;
20
21/**
22 * Tests for {@link ForwardingListenableFuture}.
23 *
24 * @author Shardul Deo
25 */
26public class ForwardingListenableFutureTest extends TestCase {
27
28  private SettableFuture<String> delegate;
29  private ListenableFuture<String> forwardingFuture;
30
31  private ListenableFutureTester tester;
32
33  @Override
34  protected void setUp() throws Exception {
35    super.setUp();
36
37    delegate = SettableFuture.create();
38    forwardingFuture = new ForwardingListenableFuture<String>() {
39      @Override
40      protected ListenableFuture<String> delegate() {
41        return delegate;
42      }
43    };
44    tester = new ListenableFutureTester(forwardingFuture);
45    tester.setUp();
46  }
47
48  @Override
49  protected void tearDown() throws Exception {
50    tester.tearDown();
51    super.tearDown();
52  }
53
54  public void testCompletedFuture() throws Exception {
55    delegate.set("foo");
56    tester.testCompletedFuture("foo");
57  }
58
59  public void testCancelledFuture() throws Exception {
60    delegate.cancel(true); // parameter is ignored
61    tester.testCancelledFuture();
62  }
63
64  public void testFailedFuture() throws Exception {
65    delegate.setException(new Exception("failed"));
66    tester.testFailedFuture("failed");
67  }
68}
69