Skip to content

Commit

Permalink
Adding OkHttp
Browse files Browse the repository at this point in the history
  • Loading branch information
pyricau committed Sep 19, 2013
1 parent f05360a commit fc9f45a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<robolectric.version>2.0</robolectric.version>
<otto.version>1.3.4</otto.version>
<retrofit.version>1.2.2</retrofit.version>
<okhttp.version>1.2.1</okhttp.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -96,6 +97,11 @@
<artifactId>retrofit</artifactId>
<version>${retrofit.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 2 additions & 0 deletions shipfaster.iml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
<orderEntry type="library" name="Maven: com.squareup:otto:1.3.4" level="project" />
<orderEntry type="library" name="Maven: com.squareup.retrofit:retrofit:1.2.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.2.4" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp:okhttp:1.2.1" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp:okhttp-protocols:1.2.1" level="project" />
</component>
</module>

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ShipFasterModule(ShipFasterApplication application) {
}

@Provides RestAdapter provideRestAdapter() {
return new RestAdapter.Builder().setServer("https://google.com").build();
return new RestAdapter.Builder().setServer("https://squareup.com").build();
}

@Provides AuthClient provideAuthService(RestAdapter restAdapter) {
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/com/squareup/shipfaster/okhttp/OkHttpTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.squareup.shipfaster.okhttp;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import retrofit.RestAdapter;
import retrofit.client.Client;
import retrofit.client.OkClient;

import static org.fest.assertions.api.Assertions.assertThat;

@RunWith(RobolectricTestRunner.class)
public class OkHttpTest {

/**
* This test relies on the internals of RetroFit. It's not really needed, but it demonstrates
* that RetroFit uses OkHttp when it's in the classpath.
*/
@Test public void retrofit_uses_okhttp() throws Exception {
Field clientProviderField = RestAdapter.class.getDeclaredField("clientProvider");
clientProviderField.setAccessible(true);
Method get = Client.Provider.class.getDeclaredMethod("get");

RestAdapter adapter = new RestAdapter.Builder().setServer("https://squareup.com").build();
Object clientProvider = clientProviderField.get(adapter);
Object client = get.invoke(clientProvider);

assertThat(client).isInstanceOf(OkClient.class);
}
}

0 comments on commit fc9f45a

Please sign in to comment.