1 /*
2  * Copyright (C) 2015 Square, Inc.
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 package com.squareup.okhttp.internal.http;
17 
18 import org.junit.Test;
19 
20 import java.io.IOException;
21 
22 import static org.junit.Assert.assertSame;
23 
24 public class RouteExceptionTest {
25 
getConnectionIOException_single()26   @Test public void getConnectionIOException_single() {
27     IOException firstException = new IOException();
28     RouteException re = new RouteException(firstException);
29     assertSame(firstException, re.getLastConnectException());
30   }
31 
getConnectionIOException_multiple()32   @Test public void getConnectionIOException_multiple() {
33     IOException firstException = new IOException();
34     IOException secondException = new IOException();
35     IOException thirdException = new IOException();
36     RouteException re = new RouteException(firstException);
37     re.addConnectException(secondException);
38     re.addConnectException(thirdException);
39 
40     IOException connectionIOException = re.getLastConnectException();
41     assertSame(thirdException, connectionIOException);
42     Throwable[] thirdSuppressedExceptions = thirdException.getSuppressed();
43     assertSame(secondException, thirdSuppressedExceptions[0]);
44 
45     Throwable[] secondSuppressedException = secondException.getSuppressed();
46     assertSame(firstException, secondSuppressedException[0]);
47   }
48 }
49