Search in sources :

Example 1 with RetrofitBuilder

use of com.jakdor.labday.common.network.RetrofitBuilder in project LabDayApp by jakdor.

the class ProjectRepositoryIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    targetContext = ApplicationProvider.getApplicationContext();
    testContext = InstrumentationRegistry.getInstrumentation().getContext();
    SoLoader.init(targetContext, false);
    localDbHandler = new LocalDbHandler(Instrumentation.newApplication(TestApp.class, targetContext));
    projectRepository = new ProjectRepository(new NetworkManager(new RetrofitBuilder()), localDbHandler, new RxSchedulersFacade());
}
Also used : LocalDbHandler(com.jakdor.labday.common.localdb.LocalDbHandler) ProjectRepository(com.jakdor.labday.common.repository.ProjectRepository) RxSchedulersFacade(com.jakdor.labday.rx.RxSchedulersFacade) NetworkManager(com.jakdor.labday.common.repository.NetworkManager) RetrofitBuilder(com.jakdor.labday.common.network.RetrofitBuilder) Before(org.junit.Before)

Example 2 with RetrofitBuilder

use of com.jakdor.labday.common.network.RetrofitBuilder in project LabDayApp by jakdor.

the class RetrofitBuilderTest method createServiceWithInterceptor.

/**
 * test RetrofitBuilder in isolation from AuthenticationInterceptor
 */
@Test
public void createServiceWithInterceptor() throws Exception {
    Request request = new Request.Builder().header("Authorization", dummyToken).get().url(dummyApiUrl).build();
    ResponseBody dummyResponse = new ResponseBody() {

        @Override
        public MediaType contentType() {
            return null;
        }

        @Override
        public long contentLength() {
            return 0;
        }

        @Override
        public BufferedSource source() {
            return null;
        }
    };
    when(authenticationInterceptor.intercept(any())).thenReturn(new Response.Builder().request(request).protocol(Protocol.HTTP_2).code(200).body(dummyResponse).message(message).build());
    LabService labService = retrofitBuilder.createService(dummyApiUrl, LabService.class, dummyToken);
    TestObserver<AppData> testObserver = labService.getAppData().test();
    testObserver.assertSubscribed();
    testObserver.onComplete();
    InOrder order = inOrder(authenticationInterceptor);
    order.verify(authenticationInterceptor, calls(1)).setAuthToken(dummyToken);
    order.verify(authenticationInterceptor, calls(1)).intercept(any());
}
Also used : Response(okhttp3.Response) LabService(com.jakdor.labday.common.network.LabService) InOrder(org.mockito.InOrder) AppData(com.jakdor.labday.common.model.AppData) RetrofitBuilder(com.jakdor.labday.common.network.RetrofitBuilder) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 3 with RetrofitBuilder

use of com.jakdor.labday.common.network.RetrofitBuilder in project LabDayApp by jakdor.

the class NetworkManagerIntegrationTest method setUp.

/**
 * Setup local Mock REST API server for instrumentation tests
 */
@Before
public void setUp() throws Exception {
    testContext = InstrumentationRegistry.getInstrumentation().getContext();
    networkManager = new NetworkManager(new RetrofitBuilder());
}
Also used : NetworkManager(com.jakdor.labday.common.repository.NetworkManager) RetrofitBuilder(com.jakdor.labday.common.network.RetrofitBuilder) Before(org.junit.Before)

Aggregations

RetrofitBuilder (com.jakdor.labday.common.network.RetrofitBuilder)3 NetworkManager (com.jakdor.labday.common.repository.NetworkManager)2 Before (org.junit.Before)2 LocalDbHandler (com.jakdor.labday.common.localdb.LocalDbHandler)1 AppData (com.jakdor.labday.common.model.AppData)1 LabService (com.jakdor.labday.common.network.LabService)1 ProjectRepository (com.jakdor.labday.common.repository.ProjectRepository)1 RxSchedulersFacade (com.jakdor.labday.rx.RxSchedulersFacade)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 ResponseBody (okhttp3.ResponseBody)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1