本文整理汇总了Java中io.reactivex.observers.TestObserver.assertSubscribed方法的典型用法代码示例。如果您正苦于以下问题:Java TestObserver.assertSubscribed方法的具体用法?Java TestObserver.assertSubscribed怎么用?Java TestObserver.assertSubscribed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.observers.TestObserver
的用法示例。
在下文中一共展示了TestObserver.assertSubscribed方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loginTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* {@link NetworkManager} integration test: login request to, local REST API server mock
*/
@Test
public void loginTest() throws Exception{
networkManager.configAuth(dummyApiUrl, dummyLogin, dummyPassword);
Gson gson = new Gson();
AccessToken expectedAccessToken
= gson.fromJson(readAssetFile(testContext, "api/login.json"), AccessToken.class);
TestObserver<AccessToken> testObserver = new CustomTestObserver<>(expectedAccessToken);
networkManager.getAccessToken().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例2: getLastUpdate
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* {@link NetworkManager} integration test: get last_update id from local REST API mock server
*/
@Test
public void getLastUpdate() throws Exception {
networkManager.configAuth(dummyApiUrl);
String expectedLastUpdate
= new String(readAssetFile(testContext, "api/last_update.json").getBytes());
TestObserver<String> testObserver = new CustomTestObserver<>(expectedLastUpdate);
networkManager.getLastUpdate().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例3: getAppDataTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* {@link NetworkManager} integration test: get AppData from local REST API mock server,
* compere parsed response to AppData parsed directly from .json file
*/
@Test
public void getAppDataTest() throws Exception {
networkManager.configAuth(dummyApiUrl);
Gson gson = new Gson();
AppData appData = gson.fromJson(
readAssetFile(testContext, "api/app_data.json"), AppData.class);
TestObserver<AppData> testObserver = new CustomTestObserver<>(appData);
networkManager.getAppData().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例4: getAppDataTokenTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* {@link NetworkManager} integration test: same as getAppDataTest() but with token Authorization
*/
@Test
public void getAppDataTokenTest() throws Exception {
networkManager.configAuth(dummyApiUrl, dummyToken);
Gson gson = new Gson();
AppData appData = gson.fromJson(
readAssetFile(testContext, "api/app_data.json"), AppData.class);
TestObserver<AppData> testObserver = new CustomTestObserver<>(appData);
networkManager.getAppData().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例5: loginTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* Tests login API call
*/
@Test
public void loginTest() throws Exception {
LabService labService = retrofitBuilder.createService(
dummyApiUrl, LabService.class, dummyLogin, dummyPassword);
Gson gson = new Gson();
AccessToken accessToken = gson.fromJson(readFile(loginAccessTokenPath), AccessToken.class);
TestObserver<AccessToken> testObserver = new CustomTestObserver<>(accessToken);
labService.getAccessToken().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例6: appDataLoginTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* Tests response from AppData API call with login&password authorization
*/
@Test
public void appDataLoginTest() throws Exception {
Gson gson = new Gson();
AppData appData = gson.fromJson(readFile(appDataJsonPath), AppData.class);
LabService labService = retrofitBuilder.createService(
dummyApiUrl, LabService.class, dummyLogin, dummyPassword);
TestObserver<AppData> testObserver = new CustomTestObserver<>(appData);
labService.getAppData().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例7: usingTestObserver
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
@Test
public void usingTestObserver() {
//An Observable with 5 one-second emissions
Observable<Long> source = Observable.interval(1,
TimeUnit.SECONDS)
.take(5);
//Declare TestObserver
TestObserver<Long> testObserver = new TestObserver<>();
//Assert no subscription has occurred yet
testObserver.assertNotSubscribed();
//Subscribe TestObserver to source
source.subscribe(testObserver);
//Assert TestObserver is subscribed
testObserver.assertSubscribed();
//Block and wait for Observable to terminate
testObserver.awaitTerminalEvent();
//Assert TestObserver called onComplete()
testObserver.assertComplete();
//Assert there were no errors
testObserver.assertNoErrors();
//Assert 5 values were received
testObserver.assertValueCount(5);
//Assert the received emissions were 0, 1, 2, 3, 4
testObserver.assertValues(0L, 1L, 2L, 3L, 4L);
}
示例8: createServiceWithInterceptor
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* 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() {
@Nullable
@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 = new TestObserver<>();
labService.getAppData().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.onComplete();
InOrder order = inOrder(authenticationInterceptor);
order.verify(authenticationInterceptor, calls(1)).setAuthToken(dummyToken);
order.verify(authenticationInterceptor, calls(1)).intercept(any());
}
示例9: lastUpdateTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* Tests API response to last_update call
*/
@Test
public void lastUpdateTest() throws Exception {
LabService labService = retrofitBuilder.createService(dummyApiUrl, LabService.class);
String expectedLastUpdate = readFile(lastUpdateJsonPath);
TestObserver<String> testObserver = new CustomTestObserver<>(expectedLastUpdate);
labService.getLastUpdate().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}
示例10: appDataTokenTest
import io.reactivex.observers.TestObserver; //导入方法依赖的package包/类
/**
* Tests response from AppData API call with token authorization
*/
@Test
public void appDataTokenTest() throws Exception {
Gson gson = new Gson();
AppData appData = gson.fromJson(readFile(appDataJsonPath), AppData.class);
LabService labService = retrofitBuilder.createService(dummyApiUrl, LabService.class, dummyToken);
TestObserver<AppData> testObserver = new CustomTestObserver<>(appData);
labService.getAppData().subscribe(testObserver);
testObserver.assertSubscribed();
testObserver.assertValueCount(1);
testObserver.assertNoErrors();
testObserver.onComplete();
}