retrofit2.mock.BehaviorDelegate Java Examples

The following examples show how to use retrofit2.mock.BehaviorDelegate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuoteOfTheDayMockAdapterTest.java    From android-retrofit-test-examples with MIT License 6 votes vote down vote up
@SmallTest
public void testFailedQuoteRetrieval() throws Exception {
    BehaviorDelegate<QuoteOfTheDayRestService> delegate = mockRetrofit.create(QuoteOfTheDayRestService.class);
    MockFailedQODService mockQodService = new MockFailedQODService(delegate);

    //Actual Test
    Call<QuoteOfTheDayResponse> quote = mockQodService.getQuoteOfTheDay();
    Response<QuoteOfTheDayResponse> quoteOfTheDayResponse = quote.execute();
    Assert.assertFalse(quoteOfTheDayResponse.isSuccessful());

    Converter<ResponseBody, QuoteOfTheDayErrorResponse> errorConverter = retrofit.responseBodyConverter(QuoteOfTheDayErrorResponse.class, new Annotation[0]);
    QuoteOfTheDayErrorResponse error = errorConverter.convert(quoteOfTheDayResponse.errorBody());

    //Asserting response
    Assert.assertEquals(404, quoteOfTheDayResponse.code());
    Assert.assertEquals("Quote Not Found", error.getError().getMessage());

}
 
Example #2
Source File: LoginOrchestratorTest.java    From quill with MIT License 6 votes vote down vote up
@Override
public ApiProvider create(String blogUrl) {
    final Retrofit retrofit = GhostApiUtils.getRetrofit(blogUrl, Helpers.getProdHttpClient());
    return new ApiProvider() {
        @Override
        public Retrofit getRetrofit() {
            return retrofit;
        }

        @Override
        public GhostApiService getGhostApi() {
            MockRetrofit mockRetrofit = Helpers.getMockRetrofit(retrofit, mNetworkBehavior);
            BehaviorDelegate<GhostApiService> delegate = mockRetrofit.create(GhostApiService.class);
            return new MockGhostApiService(delegate, mUseGhostAuth);
        }
    };
}
 
Example #3
Source File: ExploitServiceTest.java    From jshodan with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl("https://exploits.shodan.io/")
            .build();

    MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(networkBehavior).build();

    BehaviorDelegate<ExploitService> delegate = mockRetrofit.create(ExploitService.class);
    apiRestMock = new ExploitServiceMock(delegate);
}
 
Example #4
Source File: ApiServiceTest.java    From jshodan with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl("https://api.shodan.io/")
            .build();

    MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(networkBehavior).build();

    BehaviorDelegate<ApiService> delegate = mockRetrofit.create(ApiService.class);
    apiRestMock = new ApiRestMock(delegate);
}
 
Example #5
Source File: QuoteOfTheDayMockAdapterTest.java    From android-retrofit-test-examples with MIT License 5 votes vote down vote up
@SmallTest
public void testRandomQuoteRetrieval() throws Exception {
    BehaviorDelegate<QuoteOfTheDayRestService> delegate = mockRetrofit.create(QuoteOfTheDayRestService.class);
    QuoteOfTheDayRestService mockQodService = new MockQuoteOfTheDayService(delegate);


    //Actual Test
    Call<QuoteOfTheDayResponse> quote = mockQodService.getQuoteOfTheDay();
    Response<QuoteOfTheDayResponse> quoteOfTheDayResponse = quote.execute();

    //Asserting response
    Assert.assertTrue(quoteOfTheDayResponse.isSuccessful());
    Assert.assertEquals("Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.", quoteOfTheDayResponse.body().getContents().getQuotes().get(0).getQuote());

}
 
Example #6
Source File: LyftButtonCallManagerTest.java    From lyft-android-sdk with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(LyftApi.API_ROOT)
            .build();

    NetworkBehavior behavior = NetworkBehavior.create();
    behavior.setDelay(1, TimeUnit.MILLISECONDS);
    behavior.setVariancePercent(0);
    behavior.setFailurePercent(0);
    MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(behavior)
            .build();
    BehaviorDelegate<LyftApi> lyftApidelegate = mockRetrofit.create(LyftApi.class);
    lyftPublicApi = spy(new MockLyftApi(lyftApidelegate));

    BehaviorDelegate<GoogleApi> googleApiDelegate = mockRetrofit.create(GoogleApi.class);
    googleApi = spy(new MockGoogleApi(googleApiDelegate));
    HashMap<String, GoogleLatLng> addressToLatLngMap = new HashMap<>();
    addressToLatLngMap.put(PICKUP_ADDR, new GoogleLatLng(PICKUP_LAT, PICKUP_LNG));
    addressToLatLngMap.put(DROPOFF_ADDR, new GoogleLatLng(DROPOFF_LAT, DROPOFF_LNG));
    googleApi.setAddressToLatLngMap(addressToLatLngMap);

    mockCallback = mock(LyftButton.ResultLoadedCallback.class);
    callManager = new LyftButtonCallManager("clientId", lyftPublicApi, googleApi, new MockExecutorService());
}
 
Example #7
Source File: ApiRestMock.java    From jshodan with MIT License 4 votes vote down vote up
public ApiRestMock(BehaviorDelegate<ApiService> behaviorDelegate) {
    this.behaviorDelegate = behaviorDelegate;
}
 
Example #8
Source File: MockQuoteOfTheDayService.java    From android-retrofit-test-examples with MIT License 4 votes vote down vote up
public MockQuoteOfTheDayService(BehaviorDelegate<QuoteOfTheDayRestService> service) {
    this.delegate = service;
}
 
Example #9
Source File: MockGhostApiService.java    From quill with MIT License 4 votes vote down vote up
public MockGhostApiService(BehaviorDelegate<GhostApiService> delegate,
                           boolean useGhostAuth) {
    mDelegate = delegate;
    mUseGhostAuth = useGhostAuth;
}
 
Example #10
Source File: MockLyftApi.java    From lyft-android-sdk with Apache License 2.0 4 votes vote down vote up
public MockLyftApi(BehaviorDelegate<LyftApi> delegate) {
    this.delegate = delegate;
}
 
Example #11
Source File: MockGoogleApi.java    From lyft-android-sdk with Apache License 2.0 4 votes vote down vote up
public MockGoogleApi(BehaviorDelegate<GoogleApi> delegate) {
    this.delegate = delegate;
}
 
Example #12
Source File: ApiModule.java    From AndroidBlueprints with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
MessageApi provideMessageApi(MockRetrofit mockRetrofit) {
    BehaviorDelegate<MessageApi> delegate = mockRetrofit.create(MessageApi.class);
    return new OfflineMessageApi(delegate);
}
 
Example #13
Source File: ApiModule.java    From AndroidBlueprints with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
UserApi provideUserApi(MockRetrofit mockRetrofit) {
    BehaviorDelegate<UserApi> delegate = mockRetrofit.create(UserApi.class);
    return new OfflineUserApi(delegate);
}
 
Example #14
Source File: OfflineMessageApi.java    From AndroidBlueprints with Apache License 2.0 4 votes vote down vote up
public OfflineMessageApi(BehaviorDelegate<MessageApi> delegate) {
    this.delegate = delegate;
}
 
Example #15
Source File: OfflineUserApi.java    From AndroidBlueprints with Apache License 2.0 4 votes vote down vote up
@Inject
public OfflineUserApi(BehaviorDelegate<UserApi> delegate) {
    this.delegate = delegate;
}
 
Example #16
Source File: ExploitServiceMock.java    From jshodan with MIT License 4 votes vote down vote up
public ExploitServiceMock(BehaviorDelegate<ExploitService> delegate) {
    this.delegate = delegate;
}
 
Example #17
Source File: MockFailedQODService.java    From android-retrofit-test-examples with MIT License 2 votes vote down vote up
public MockFailedQODService(BehaviorDelegate<QuoteOfTheDayRestService> restServiceBehaviorDelegate) {
    this.delegate = restServiceBehaviorDelegate;

}