本文整理汇总了Java中retrofit2.mock.BehaviorDelegate类的典型用法代码示例。如果您正苦于以下问题:Java BehaviorDelegate类的具体用法?Java BehaviorDelegate怎么用?Java BehaviorDelegate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BehaviorDelegate类属于retrofit2.mock包,在下文中一共展示了BehaviorDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
@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);
}
示例2: provideBusService
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public static BusService provideBusService(Context context){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
if (BuildConfig.DEBUG) {
interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
} else {
interceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
}
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BusService.BASE_URL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
NetworkBehavior behavior = NetworkBehavior.create();
MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
.networkBehavior(behavior)
.build();
behavior.failureException();
BehaviorDelegate<BusService> delegate = mockRetrofit.create(BusService.class);
return new MockBusService(context,delegate);
}
示例3: create
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
@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);
}
};
}
示例4: testFailedQuoteRetrieval
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
@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());
}
示例5: MockGitHub
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
MockGitHub(BehaviorDelegate<GitHub> delegate) {
this.delegate = delegate;
ownerRepoContributors = new LinkedHashMap<>();
// Seed some mock data.
addContributor("square", "retrofit", "John Doe", 12);
addContributor("square", "retrofit", "Bob Smith", 2);
addContributor("square", "retrofit", "Big Bird", 40);
addContributor("square", "picasso", "Proposition Joe", 39);
addContributor("square", "picasso", "Keiser Soze", 152);
}
示例6: main
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public static void main(String... args) throws IOException {
// Create a very simple Retrofit adapter which points the GitHub API.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(SimpleService.API_URL)
.build();
// Create a MockRetrofit object with a NetworkBehavior which manages the fake behavior of calls.
NetworkBehavior behavior = NetworkBehavior.create();
MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
.networkBehavior(behavior)
.build();
BehaviorDelegate<GitHub> delegate = mockRetrofit.create(GitHub.class);
MockGitHub gitHub = new MockGitHub(delegate);
// Query for some contributors for a few repositories.
printContributors(gitHub, "square", "retrofit");
printContributors(gitHub, "square", "picasso");
// Using the mock-only methods, add some additional data.
System.out.println("Adding more mock data...\n");
gitHub.addContributor("square", "retrofit", "Foo Bar", 61);
gitHub.addContributor("square", "picasso", "Kit Kat", 53);
// Reduce the delay to make the next calls complete faster.
behavior.setDelay(500, TimeUnit.MILLISECONDS);
// Query for the contributors again so we can see the mock data that was added.
printContributors(gitHub, "square", "retrofit");
printContributors(gitHub, "square", "picasso");
}
示例7: setUp
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
@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);
}
示例8: MockMessageRepository
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public MockMessageRepository(Retrofit retrofit, MockRetrofit mockRetrofit,
NetworkBehavior networkBehavior) {
this.networkBehavior = networkBehavior;
final BehaviorDelegate<MessageApiService> delegate = mockRetrofit.create(MessageApiService.class);
mockMessageApiService = new MockMessageApiService(delegate);
}
示例9: setup
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
@Before
public void setup() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(LyftPublicApi.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<LyftPublicApi> lyftApidelegate = mockRetrofit.create(LyftPublicApi.class);
lyftPublicApi = spy(new MockLyftPublicApi(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());
}
示例10: InbucketMockService
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public InbucketMockService(BehaviorDelegate<InbucketService> delegate){
this.delegate = delegate;
data = new LinkedHashMap<>();
Message message = new Message();
message.mailbox = "test";
message.id = "20131016T164638-0001";
message.from = "[email protected]";
message.subject = "Test HTML";
message.date = "2013-10-16T16:46:38.646370568-07:00";
message.size = 705;
Map<String,List<String>> header = new LinkedHashMap<>();
header.put("Content-Type", Collections.singletonList("multipart/alternative; boundary=\"----=_MIME_BOUNDARY_000_62717\""));
header.put("Date",Collections.singletonList("Wed, 16 Oct 2013 16:46:38 -0700"));
header.put("From",Collections.singletonList("[email protected]"));
header.put("Mime-Version",Collections.singletonList("1.0"));
header.put("Subject",Collections.singletonList("Test HTML"));
header.put("To", Collections.singletonList("[email protected]"));
message.header = header;
message.body = new Body();
message.body.text = "This is a test mailing.\r\n\r\nThis should be clickable: http://google.com/\r\n";
message.body.html = "<html>\n<body>\n<p>This is a test mailing <b>in HTML</b></p>\n\n<p>This should be clickable: [...]";
Attachment attachment = new Attachment();
attachment.filename = "favicon.png";
attachment.contentType="image/png";
attachment.downloadLink="http://localhost:9000/mailbox/dattach/swaks/20131016T164638-0001/0/favicon.png";
attachment.viewLink="http://localhost:9000/mailbox/vattach/swaks/20131016T164638-0001/0/favicon.png";
attachment.md5 = "a72a7565b6b6587ac15fc35746307d0e";
message.attachments = Collections.singletonList(attachment);
addMessage(message);
message.id = "20131016T164638-0002";
message.subject = "Swaks HTML2";
addMessage(message);
}
示例11: InbucketTestClient
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public InbucketTestClient(String baseUrl, int networkFailureProcentage) {
super(baseUrl);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(JacksonConverterFactory.create())
.build();
NetworkBehavior behavior = NetworkBehavior.create();
behavior.setFailurePercent(networkFailureProcentage);
MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
.networkBehavior(behavior)
.build();
BehaviorDelegate<InbucketService> delegate = mockRetrofit.create(InbucketService.class);
service = new InbucketMockService(delegate);
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.build();
mockRetrofit = new MockRetrofit.Builder(retrofit)
.networkBehavior(behavior)
.build();
delegate = mockRetrofit.create(InbucketService.class);
simpleService = new InbucketMockService(delegate);
}
示例12: MockGitHub
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public MockGitHub(BehaviorDelegate<GitHub> delegate) {
this.delegate = delegate;
ownerRepoContributors = new LinkedHashMap<>();
// Seed some mock data.
addContributor("square", "retrofit", "John Doe", 12);
addContributor("square", "retrofit", "Bob Smith", 2);
addContributor("square", "retrofit", "Big Bird", 40);
addContributor("square", "picasso", "Proposition Joe", 39);
addContributor("square", "picasso", "Keiser Soze", 152);
}
示例13: testRandomQuoteRetrieval
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
@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());
}
示例14: ApiRestMock
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public ApiRestMock(BehaviorDelegate<ApiService> behaviorDelegate) {
this.behaviorDelegate = behaviorDelegate;
}
示例15: ExploitServiceMock
import retrofit2.mock.BehaviorDelegate; //导入依赖的package包/类
public ExploitServiceMock(BehaviorDelegate<ExploitService> delegate) {
this.delegate = delegate;
}