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 import javax.annotation.CheckForNull; 22 23 /** 24 * Classes and futures used in {@link FuturesGetCheckedTest} and {@link FuturesGetUncheckedTest}. 25 */ 26 @GwtCompatible 27 final class FuturesGetCheckedInputs { 28 static final Exception CHECKED_EXCEPTION = new Exception("mymessage"); 29 static final Future<String> FAILED_FUTURE_CHECKED_EXCEPTION = 30 immediateFailedFuture(CHECKED_EXCEPTION); 31 static final RuntimeException UNCHECKED_EXCEPTION = new RuntimeException("mymessage"); 32 static final Future<String> FAILED_FUTURE_UNCHECKED_EXCEPTION = 33 immediateFailedFuture(UNCHECKED_EXCEPTION); 34 static final RuntimeException RUNTIME_EXCEPTION = new RuntimeException(); 35 static final OtherThrowable OTHER_THROWABLE = new OtherThrowable(); 36 static final Future<String> FAILED_FUTURE_OTHER_THROWABLE = 37 immediateFailedFuture(OTHER_THROWABLE); 38 static final Error ERROR = new Error("mymessage"); 39 static final Future<String> FAILED_FUTURE_ERROR = immediateFailedFuture(ERROR); 40 static final Future<String> RUNTIME_EXCEPTION_FUTURE = 41 UncheckedThrowingFuture.throwingRuntimeException(RUNTIME_EXCEPTION); 42 static final Future<String> ERROR_FUTURE = UncheckedThrowingFuture.throwingError(ERROR); 43 44 public static final class TwoArgConstructorException extends Exception { TwoArgConstructorException(String message, Throwable cause)45 public TwoArgConstructorException(String message, Throwable cause) { 46 super(message, cause); 47 } 48 } 49 50 public static final class TwoArgConstructorRuntimeException extends RuntimeException { TwoArgConstructorRuntimeException(String message, Throwable cause)51 public TwoArgConstructorRuntimeException(String message, Throwable cause) { 52 super(message, cause); 53 } 54 } 55 56 public static final class ExceptionWithPrivateConstructor extends Exception { ExceptionWithPrivateConstructor(String message, Throwable cause)57 private ExceptionWithPrivateConstructor(String message, Throwable cause) { 58 super(message, cause); 59 } 60 } 61 62 public static final class ExceptionWithManyConstructorsButOnlyOneThrowable extends Exception { 63 @CheckForNull private Throwable antecedent; 64 ExceptionWithManyConstructorsButOnlyOneThrowable(String message, String a1)65 public ExceptionWithManyConstructorsButOnlyOneThrowable(String message, String a1) { 66 super(message); 67 } 68 ExceptionWithManyConstructorsButOnlyOneThrowable(String message, String a1, String a2)69 public ExceptionWithManyConstructorsButOnlyOneThrowable(String message, String a1, String a2) { 70 super(message); 71 } 72 ExceptionWithManyConstructorsButOnlyOneThrowable( String message, String a1, String a2, String a3)73 public ExceptionWithManyConstructorsButOnlyOneThrowable( 74 String message, String a1, String a2, String a3) { 75 super(message); 76 } 77 ExceptionWithManyConstructorsButOnlyOneThrowable(String message, Throwable antecedent)78 public ExceptionWithManyConstructorsButOnlyOneThrowable(String message, Throwable antecedent) { 79 super(message); 80 this.antecedent = antecedent; 81 } 82 ExceptionWithManyConstructorsButOnlyOneThrowable( String message, String a1, String a2, String a3, String a4)83 public ExceptionWithManyConstructorsButOnlyOneThrowable( 84 String message, String a1, String a2, String a3, String a4) { 85 super(message); 86 } 87 ExceptionWithManyConstructorsButOnlyOneThrowable( String message, String a1, String a2, String a3, String a4, String a5)88 public ExceptionWithManyConstructorsButOnlyOneThrowable( 89 String message, String a1, String a2, String a3, String a4, String a5) { 90 super(message); 91 } 92 ExceptionWithManyConstructorsButOnlyOneThrowable( String message, String a1, String a2, String a3, String a4, String a5, String a6)93 public ExceptionWithManyConstructorsButOnlyOneThrowable( 94 String message, String a1, String a2, String a3, String a4, String a5, String a6) { 95 super(message); 96 } 97 getAntecedent()98 public Throwable getAntecedent() { 99 return antecedent; 100 } 101 } 102 103 @SuppressWarnings("unused") // we're testing that they're not used 104 public static final class ExceptionWithSomePrivateConstructors extends Exception { ExceptionWithSomePrivateConstructors(String a)105 private ExceptionWithSomePrivateConstructors(String a) {} 106 ExceptionWithSomePrivateConstructors(String a, String b)107 private ExceptionWithSomePrivateConstructors(String a, String b) {} 108 ExceptionWithSomePrivateConstructors(String a, String b, String c)109 public ExceptionWithSomePrivateConstructors(String a, String b, String c) {} 110 ExceptionWithSomePrivateConstructors(String a, String b, String c, String d)111 private ExceptionWithSomePrivateConstructors(String a, String b, String c, String d) {} 112 ExceptionWithSomePrivateConstructors( String a, String b, String c, String d, String e)113 private ExceptionWithSomePrivateConstructors( 114 String a, String b, String c, String d, String e) {} 115 } 116 117 public static final class ExceptionWithManyConstructors extends Exception { 118 boolean usedExpectedConstructor; 119 ExceptionWithManyConstructors()120 public ExceptionWithManyConstructors() {} 121 ExceptionWithManyConstructors(Integer i)122 public ExceptionWithManyConstructors(Integer i) {} 123 ExceptionWithManyConstructors(Throwable a)124 public ExceptionWithManyConstructors(Throwable a) {} 125 ExceptionWithManyConstructors(Throwable a, Throwable b)126 public ExceptionWithManyConstructors(Throwable a, Throwable b) {} 127 ExceptionWithManyConstructors(String s, Throwable b)128 public ExceptionWithManyConstructors(String s, Throwable b) { 129 usedExpectedConstructor = true; 130 } 131 ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c)132 public ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c) {} 133 ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c, Throwable d)134 public ExceptionWithManyConstructors(Throwable a, Throwable b, Throwable c, Throwable d) {} 135 ExceptionWithManyConstructors( Throwable a, Throwable b, Throwable c, Throwable d, Throwable e)136 public ExceptionWithManyConstructors( 137 Throwable a, Throwable b, Throwable c, Throwable d, Throwable e) {} 138 ExceptionWithManyConstructors( Throwable a, Throwable b, Throwable c, Throwable d, Throwable e, String s, Integer i)139 public ExceptionWithManyConstructors( 140 Throwable a, Throwable b, Throwable c, Throwable d, Throwable e, String s, Integer i) {} 141 } 142 143 public static final class ExceptionWithoutThrowableConstructor extends Exception { ExceptionWithoutThrowableConstructor(String s)144 public ExceptionWithoutThrowableConstructor(String s) { 145 super(s); 146 } 147 } 148 149 public static final class ExceptionWithWrongTypesConstructor extends Exception { ExceptionWithWrongTypesConstructor(Integer i, String s)150 public ExceptionWithWrongTypesConstructor(Integer i, String s) { 151 super(s); 152 } 153 } 154 155 static final class ExceptionWithGoodAndBadConstructor extends Exception { ExceptionWithGoodAndBadConstructor(String message, Throwable cause)156 public ExceptionWithGoodAndBadConstructor(String message, Throwable cause) { 157 throw new RuntimeException("bad constructor"); 158 } 159 ExceptionWithGoodAndBadConstructor(Throwable cause)160 public ExceptionWithGoodAndBadConstructor(Throwable cause) { 161 super(cause); 162 } 163 } 164 165 static final class ExceptionWithBadConstructor extends Exception { ExceptionWithBadConstructor(String message, Throwable cause)166 public ExceptionWithBadConstructor(String message, Throwable cause) { 167 throw new RuntimeException("bad constructor"); 168 } 169 } 170 171 static final class OtherThrowable extends Throwable {} 172 FuturesGetCheckedInputs()173 private FuturesGetCheckedInputs() {} 174 } 175