use of okhttp3.mockwebserver.MockWebServer in project Just-Another-Android-App by athkalia.
the class NetworkModule method provideOkHttpClient.
@Provides
@Singleton
public static OkHttpClient provideOkHttpClient(PropertiesManager propertiesManager, HttpLoggingInterceptor httpLoggingInterceptor, List<Interceptor> networkInterceptors, BaseUrlInterceptor baseUrlInterceptor) {
final OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();
// Logs network calls for debug builds
okHttpBuilder.addInterceptor(httpLoggingInterceptor);
// Adds authentication headers when required in network calls
okHttpBuilder.addInterceptor(new AuthenticationInterceptor(propertiesManager));
// Helps with changing base url of network calls in espresso tests to the MockWebServer base url.
okHttpBuilder.addInterceptor(baseUrlInterceptor);
// For release builds nothing is added, the list is empty. For debug builds Stetho interceptor is added.
for (Interceptor networkInterceptor : networkInterceptors) {
okHttpBuilder.addNetworkInterceptor(networkInterceptor);
}
return okHttpBuilder.build();
}
use of okhttp3.mockwebserver.MockWebServer in project Just-Another-Android-App by athkalia.
the class MockWebServerHelper method initMockWebServer.
public MockWebServer initMockWebServer() throws IOException {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.start();
setBaseUrlToMockWebServer(mockWebServer);
return mockWebServer;
}
use of okhttp3.mockwebserver.MockWebServer in project qualitymatters by artem-zinnatullin.
the class MockWebServerRule method apply.
@Override
@NonNull
public Statement apply(@NonNull Statement base, @NonNull Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final NeedsMockWebServer needsMockWebServer = description.getAnnotation(NeedsMockWebServer.class);
if (needsMockWebServer != null) {
final MockWebServer mockWebServer = new MockWebServer();
mockWebServer.start();
TestUtils.app().applicationComponent().changeableBaseUrl().setBaseUrl(mockWebServer.url("").toString());
if (!needsMockWebServer.setupMethod().isEmpty()) {
final Method setupMethod = testClassInstance.getClass().getDeclaredMethod(needsMockWebServer.setupMethod(), MockWebServer.class);
setupMethod.invoke(testClassInstance, mockWebServer);
}
// Try to evaluate the test and anyway shutdown the MockWebServer.
try {
base.evaluate();
} finally {
mockWebServer.shutdown();
}
} else {
// No need to setup a MockWebServer, just evaluate the test.
base.evaluate();
}
}
};
}
use of okhttp3.mockwebserver.MockWebServer in project qualitymatters by artem-zinnatullin.
the class QualityMattersRestApiIntegrationTest method beforeEachTest.
@Before
public void beforeEachTest() throws IOException {
mockWebServer = new MockWebServer();
mockWebServer.start();
// Change base url to the mocked
QualityMattersIntegrationRobolectricTestRunner.qualityMattersApp().applicationComponent().changeableBaseUrl().setBaseUrl(mockWebServer.url("").toString());
qualityMattersRestApi = QualityMattersIntegrationRobolectricTestRunner.qualityMattersApp().applicationComponent().qualityMattersApi();
}
use of okhttp3.mockwebserver.MockWebServer in project glide by bumptech.
the class HttpUrlFetcherServerTest method setUp.
@Before
public void setUp() throws IOException {
MockitoAnnotations.initMocks(this);
defaultFollowRedirects = HttpURLConnection.getFollowRedirects();
HttpURLConnection.setFollowRedirects(false);
mockWebServer = new MockWebServer();
mockWebServer.start();
streamCaptor = ArgumentCaptor.forClass(InputStream.class);
}
Aggregations