Home | History | Annotate | Download | only in okhttp
      1 /*
      2  * Copyright (C) 2014 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;
     17 
     18 import com.squareup.okhttp.internal.Util;
     19 import com.squareup.okhttp.internal.http.AuthenticatorAdapter;
     20 import com.squareup.okhttp.internal.http.RecordingProxySelector;
     21 import java.util.List;
     22 import javax.net.SocketFactory;
     23 import org.junit.Test;
     24 
     25 import static org.junit.Assert.assertEquals;
     26 import static org.junit.Assert.assertFalse;
     27 
     28 public final class AddressTest {
     29   private Dns dns = Dns.SYSTEM;
     30   private SocketFactory socketFactory = SocketFactory.getDefault();
     31   private Authenticator authenticator = AuthenticatorAdapter.INSTANCE;
     32   private List<Protocol> protocols = Util.immutableList(Protocol.HTTP_1_1);
     33   private List<ConnectionSpec> connectionSpecs = Util.immutableList(ConnectionSpec.MODERN_TLS);
     34   private RecordingProxySelector proxySelector = new RecordingProxySelector();
     35 
     36   @Test public void equalsAndHashcode() throws Exception {
     37     Address a = new Address("square.com", 80, dns, socketFactory, null, null, null,
     38         authenticator, null, protocols, connectionSpecs, proxySelector);
     39     Address b = new Address("square.com", 80, dns, socketFactory, null, null, null,
     40         authenticator, null, protocols, connectionSpecs, proxySelector);
     41     assertEquals(a, b);
     42     assertEquals(a.hashCode(), b.hashCode());
     43   }
     44 
     45   @Test public void differentProxySelectorsAreDifferent() throws Exception {
     46     Address a = new Address("square.com", 80, dns, socketFactory, null, null, null,
     47         authenticator, null, protocols, connectionSpecs, new RecordingProxySelector());
     48     Address b = new Address("square.com", 80, dns, socketFactory, null, null, null,
     49         authenticator, null, protocols, connectionSpecs, new RecordingProxySelector());
     50     assertFalse(a.equals(b));
     51   }
     52 }
     53