2323import com .google .gcloud .ExceptionHandler .Interceptor ;
2424import com .google .gcloud .ExceptionHandler .Interceptor .RetryResult ;
2525
26+ import org .junit .rules .ExpectedException ;
27+ import org .junit .Rule ;
2628import org .junit .Test ;
2729
2830import java .io .FileNotFoundException ;
3638 */
3739public class ExceptionHandlerTest {
3840
41+ @ Rule
42+ public ExpectedException thrown = ExpectedException .none ();
43+
3944 @ Test
4045 public void testVerifyCaller () {
4146 class A implements Callable <Object > {
@@ -128,13 +133,13 @@ public void testShouldTry() {
128133 assertFalse (handler .shouldRetry (new RuntimeException ()));
129134 assertTrue (handler .shouldRetry (new NullPointerException ()));
130135
131- final AtomicReference <RetryResult > before = new AtomicReference <>(RetryResult .ABORT );
136+ final AtomicReference <RetryResult > before = new AtomicReference <>(RetryResult .NO_RETRY );
132137 @ SuppressWarnings ("serial" )
133138 Interceptor interceptor = new Interceptor () {
134139
135140 @ Override
136141 public RetryResult afterEval (Exception exception , RetryResult retryResult ) {
137- return retryResult == RetryResult .ABORT ? RetryResult .RETRY : RetryResult .ABORT ;
142+ return retryResult == RetryResult .NO_RETRY ? RetryResult .RETRY : RetryResult .NO_RETRY ;
138143 }
139144
140145 @ Override
@@ -158,7 +163,7 @@ public RetryResult beforeEval(Exception exception) {
158163 assertTrue (handler .shouldRetry (new RuntimeException ()));
159164 assertTrue (handler .shouldRetry (new NullPointerException ()));
160165
161- before .set (RetryResult .PROCEED );
166+ before .set (RetryResult .CONTINUE_EVALUATION );
162167 assertFalse (handler .shouldRetry (new IOException ()));
163168 assertTrue (handler .shouldRetry (new ClosedByInterruptException ()));
164169 assertTrue (handler .shouldRetry (new InterruptedException ()));
@@ -167,9 +172,9 @@ public RetryResult beforeEval(Exception exception) {
167172 }
168173
169174 @ Test
170- public void testNullRetryResult () {
175+ public void testNullRetryResultFromBeforeEval () {
171176 @ SuppressWarnings ("serial" )
172- Interceptor interceptor1 = new Interceptor () {
177+ Interceptor interceptor = new Interceptor () {
173178
174179 @ Override
175180 public RetryResult beforeEval (Exception exception ) {
@@ -178,17 +183,24 @@ public RetryResult beforeEval(Exception exception) {
178183
179184 @ Override
180185 public RetryResult afterEval (Exception exception , RetryResult retryResult ) {
181- return RetryResult .PROCEED ;
186+ return RetryResult .CONTINUE_EVALUATION ;
182187 }
183188
184189 };
185190
191+ ExceptionHandler handler = ExceptionHandler .builder ().interceptor (interceptor ).build ();
192+ thrown .expect (NullPointerException .class );
193+ handler .shouldRetry (new Exception ());
194+ }
195+
196+ @ Test
197+ public void testNullRetryResultFromAfterEval () {
186198 @ SuppressWarnings ("serial" )
187- Interceptor interceptor2 = new Interceptor () {
199+ Interceptor interceptor = new Interceptor () {
188200
189201 @ Override
190202 public RetryResult beforeEval (Exception exception ) {
191- return RetryResult .PROCEED ;
203+ return RetryResult .CONTINUE_EVALUATION ;
192204 }
193205
194206 @ Override
@@ -198,20 +210,8 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) {
198210
199211 };
200212
201- ExceptionHandler handler1 = ExceptionHandler .builder ().interceptor (interceptor1 ).build ();
202- try {
203- handler1 .shouldRetry (new Exception ());
204- fail ("Expected null pointer exception due to null RetryResult from beforeEval" );
205- } catch (NullPointerException e ) {
206- // expected
207- }
208-
209- ExceptionHandler handler2 = ExceptionHandler .builder ().interceptor (interceptor2 ).build ();
210- try {
211- handler2 .shouldRetry (new Exception ());
212- fail ("Expected null pointer exception due to null RetryResult from afterEval" );
213- } catch (NullPointerException e ) {
214- // expected
215- }
213+ ExceptionHandler handler = ExceptionHandler .builder ().interceptor (interceptor ).build ();
214+ thrown .expect (NullPointerException .class );
215+ handler .shouldRetry (new Exception ());
216216 }
217217}
0 commit comments