1 /*
2  * Copyright (C) 2008 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.common.util.concurrent;
16 
17 import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
18 
19 import com.google.common.annotations.GwtCompatible;
20 import java.util.concurrent.Future;
21 
22 /**
23  * Classes and futures used in {@link FuturesGetCheckedTest} and {@link FuturesGetUncheckedTest}.
24  */
25 @GwtCompatible
26 final class FuturesGetCheckedInputs {
27   static final Exception CHECKED_EXCEPTION = new Exception("mymessage");
28   static final Future<String> FAILED_FUTURE_CHECKED_EXCEPTION =
29       immediateFailedFuture(CHECKED_EXCEPTION);
30   static final RuntimeException UNCHECKED_EXCEPTION = new RuntimeException("mymessage");
31   static final Future<String> FAILED_FUTURE_UNCHECKED_EXCEPTION =
32       immediateFailedFuture(UNCHECKED_EXCEPTION);
33   static final RuntimeException RUNTIME_EXCEPTION = new RuntimeException();
34   static final OtherThrowable OTHER_THROWABLE = new OtherThrowable();
35   static final Future<String> FAILED_FUTURE_OTHER_THROWABLE =
36       immediateFailedFuture(OTHER_THROWABLE);
37   static final Error ERROR = new Error("mymessage");
38   static final Future<String> FAILED_FUTURE_ERROR = immediateFailedFuture(ERROR);
39   static final Future<String> RUNTIME_EXCEPTION_FUTURE =
40       UncheckedThrowingFuture.throwingRuntimeException(RUNTIME_EXCEPTION);
41   static final Future<String> ERROR_FUTURE = UncheckedThrowingFuture.throwingError(ERROR);
42 
43   public static final class TwoArgConstructorException extends Exception {
TwoArgConstructorException(String message, Throwable cause)44     public TwoArgConstructorException(String message, Throwable cause) {
45       super(message, cause);
46     }
47   }
48 
49   public static final class TwoArgConstructorRuntimeException extends RuntimeException {
TwoArgConstructorRuntimeException(String message, Throwable cause)50     public TwoArgConstructorRuntimeException(String message, Throwable cause) {
51       super(message, cause);
52     }
53   }
54 
55   public static final class ExceptionWithPrivateConstructor extends Exception {
ExceptionWithPrivateConstructor(String message, Throwable cause)56     private ExceptionWithPrivateConstructor(String message, Throwable cause) {
57       super(message, cause);
58     }
59   }
60 
61   @SuppressWarnings("unused") // we're testing that they're not used
62   public static final class ExceptionWithSomePrivateConstructors extends Exception {
ExceptionWithSomePrivateConstructors(String a)63     private ExceptionWithSomePrivateConstructors(String a) {}
64 
ExceptionWithSomePrivateConstructors(String a, String b)65     private ExceptionWithSomePrivateConstructors(String a, String b) {}
66 
ExceptionWithSomePrivateConstructors(String a, String b, String c)67     public ExceptionWithSomePrivateConstructors(String a, String b, String c) {}
68 
ExceptionWithSomePrivateConstructors(String a, String b, String c, String d)69     private ExceptionWithSomePrivateConstructors(String a, String b, String c, String d) {}
70 
ExceptionWithSomePrivateConstructors( String a, String b, String c, String d, String e)71     private ExceptionWithSomePrivateConstructors(
72         String a, String b, String c, String d, String e) {}
73   }
74 
75   public static final class ExceptionWithManyConstructors extends Exception {
76     boolean usedExpectedConstructor;
77 
ExceptionWithManyConstructors()78     public ExceptionWithManyConstructors() {}
79 
ExceptionWithManyConstructors(Integer i)80     public ExceptionWithManyConstructors(Integer i) {}
81 
ExceptionWithManyConstructors(Throwable a)82     public ExceptionWithManyConstructors(Throwable a) {}
83 
ExceptionWithManyConstructors(Throwable a, Throwable b)84     public ExceptionWithManyConstructors(Throwable a, Throwable b) {}
85 
ExceptionWithManyConstructors(String s, Throwable b)86     public ExceptionWithManyConstructors(String s, Throwable b) {
87       usedExpectedConstructor = true;
88     }
89 
ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c)90     public ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c) {}
91 
ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c, Throwable d)92     public ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c, Throwable d) {}
93 
ExceptionWithManyConstructors( Throwable a, Throwable b, Throwable c, Throwable d, Throwable e)94     public ExceptionWithManyConstructors(
95         Throwable a, Throwable b, Throwable c, Throwable d, Throwable e) {}
96 
ExceptionWithManyConstructors( Throwable a, Throwable b, Throwable c, Throwable d, Throwable e, String s, Integer i)97     public ExceptionWithManyConstructors(
98         Throwable a, Throwable b, Throwable c, Throwable d, Throwable e, String s, Integer i) {}
99   }
100 
101   public static final class ExceptionWithoutThrowableConstructor extends Exception {
ExceptionWithoutThrowableConstructor(String s)102     public ExceptionWithoutThrowableConstructor(String s) {
103       super(s);
104     }
105   }
106 
107   public static final class ExceptionWithWrongTypesConstructor extends Exception {
ExceptionWithWrongTypesConstructor(Integer i, String s)108     public ExceptionWithWrongTypesConstructor(Integer i, String s) {
109       super(s);
110     }
111   }
112 
113   static final class ExceptionWithGoodAndBadConstructor extends Exception {
ExceptionWithGoodAndBadConstructor(String message, Throwable cause)114     public ExceptionWithGoodAndBadConstructor(String message, Throwable cause) {
115       throw new RuntimeException("bad constructor");
116     }
117 
ExceptionWithGoodAndBadConstructor(Throwable cause)118     public ExceptionWithGoodAndBadConstructor(Throwable cause) {
119       super(cause);
120     }
121   }
122 
123   static final class ExceptionWithBadConstructor extends Exception {
ExceptionWithBadConstructor(String message, Throwable cause)124     public ExceptionWithBadConstructor(String message, Throwable cause) {
125       throw new RuntimeException("bad constructor");
126     }
127   }
128 
129   static final class OtherThrowable extends Throwable {}
130 
FuturesGetCheckedInputs()131   private FuturesGetCheckedInputs() {}
132 }
133