Last active
August 4, 2016 18:11
-
-
Save heitorcolangelo/bba121850ae849540a48471ea2c4dceb to your computer and use it in GitHub Desktop.
MainActivityTest - configuring mirror
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
public class MainActivityTest { | |
private MockWebServer server; | |
@Rule | |
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false); | |
@Before | |
public void setUp() throws Exception { | |
server = new MockWebServer(); | |
server.start(); | |
setupServerUrl(); | |
} | |
@After | |
public void tearDown() throws IOException { | |
server.shutdown(); | |
} | |
private void setupServerUrl() { | |
String url = server.url("/").toString(); | |
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); | |
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); | |
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); | |
final UsersApi usersApi = UsersApi.getInstance(); | |
final Api api = new Retrofit.Builder() | |
.baseUrl(url) | |
.addConverterFactory(GsonConverterFactory.create(UsersApi.GSON)) | |
.client(client) | |
.build() | |
.create(Api.class); | |
setField(usersApi, "api", api); | |
} | |
private void setField(Object target, String fieldName, Object value) { | |
new Mirror() | |
.on(target) | |
.set() | |
.field(fieldName) | |
.withValue(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment