Java Code Examples for rx.schedulers.Schedulers#immediate()

The following examples show how to use rx.schedulers.Schedulers#immediate() . 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: AppCoinsInfoPresenterTest.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Before public void setupAppCoinsInfoPresenter() {
  MockitoAnnotations.initMocks(this);

  lifecycleEvent = PublishSubject.create();
  coinbaseClickEvent = PublishSubject.create();
  installClickEvent = PublishSubject.create();
  walletClickEvent = PublishSubject.create();

  presenter =
      new AppCoinsInfoPresenter(view, navigator, installManager, crashReporter, packageName,
          Schedulers.immediate(), externalNavigator);

  when(view.getLifecycleEvent()).thenReturn(lifecycleEvent);
  when(view.installButtonClick()).thenReturn(installClickEvent);
  when(view.appCoinsWalletLinkClick()).thenReturn(walletClickEvent);
}
 
Example 2
Source File: HomeContainerPresenterTest.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Before public void setupHomePresenter() {
  MockitoAnnotations.initMocks(this);
  lifecycleEvent = PublishSubject.create();

  presenter = new HomeContainerPresenter(view, Schedulers.immediate(), aptoideAccountManager,
      homeContainerNavigator, homeNavigator, homeAnalytics, home, chipManager);
  when(view.getLifecycleEvent()).thenReturn(lifecycleEvent);
  when(view.toolbarUserClick()).thenReturn(Observable.just(null));
  when(aptoideAccountManager.accountStatus()).thenReturn(Observable.just(account));
}
 
Example 3
Source File: AppViewManagerTest.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Test public void loadAppViewModelTest() {
  List<String> bdsFlags = new ArrayList<>();
  Malware malware = new Malware();
  malware.setRank(Malware.Rank.CRITICAL);
  AppModel appModel =
      new AppModel(11, "aptoide", new cm.aptoide.pt.dataprovider.model.v7.store.Store(), "", true,
          malware, new AppFlags("", Collections.emptyList()), Collections.<String>emptyList(),
          Collections.<String>emptyList(), Collections.<String>emptyList(), 121312312,
          "md5dajskdjas", "mypath", "myAltPath", 12311, "9.0.0", "cm.aptoide.pt", 12311,
          100210312, new AppRating(0, 100, Collections.emptyList()), 1231231,
          new AppRating(0, 100, Collections.emptyList()),
          new AppDeveloper("Felipao", "[email protected]", "privacy", "website"), "graphic",
          "icon", new AppMedia("description", Collections.<String>emptyList(), "news",
          Collections.emptyList(), Collections.emptyList()), "modified", "app added", null,
          "weburls", true, "aptoide", AppViewFragment.OpenType.OPEN_ONLY, 0, null,
          "editorsChoice", "origin", false, "marketName", false, false, bdsFlags, "", "", false,
          null, null);
  AppViewModel exampleAppViewModel = new AppViewModel(appModel, null, null, null);

  appViewManager =
      new AppViewManager(appViewModelManager, installManager, downloadFactory, appCenter,
          reviewsManager, adsManager, flagManager, storeUtilsProxy, aptoideAccountManager,
          moPubAdsManager, downloadStateParser, appViewAnalytics, notificationAnalytics,
          installAnalytics, limit, Schedulers.immediate(), "anyString", appCoinsManager,
          promotionsManager, migrationManager, localNotificationSyncManager,
          appcPromotionNotificationStringProvider);

  when(appViewModelManager.getAppViewModel()).thenReturn(Single.just(exampleAppViewModel));

  AppViewModel appViewModel = appViewManager.getAppViewModel()
      .toBlocking()
      .value();

  //Then the correct AppViewModelManager method should be called
  verify(appViewModelManager).getAppViewModel();

  //And a AppViewModel should be the same
  Assert.assertNotNull(appViewModel);
  Assert.assertEquals(appViewModel, exampleAppViewModel);
}
 
Example 4
Source File: SchedulersLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenScheduledWorker_whenScheduleAnAction_thenResultAction() throws InterruptedException {
    System.out.println("scheduling");
    Scheduler scheduler = Schedulers.immediate();
    Scheduler.Worker worker = scheduler.createWorker();
    worker.schedule(() -> result += "action");

    assertTrue(result.equals("action"));
}
 
Example 5
Source File: MyStoresPresenterTest.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Before public void setupMyStoresPresenter() {
  MockitoAnnotations.initMocks(this);

  lifecycleEvent = PublishSubject.create();
  navigationEvent = PublishSubject.create();
  imageClickEvent = PublishSubject.create();
  accountStatusEvent = PublishSubject.create();
  presenter = new MyStoresPresenter(view, Schedulers.immediate(), aptoideAccountManager,
      myStoresNavigator);

  when(view.getLifecycleEvent()).thenReturn(lifecycleEvent);
  when(view.imageClick()).thenReturn(imageClickEvent);
  when(myStoresNavigator.bottomNavigationEvent()).thenReturn(navigationEvent);
  when(aptoideAccountManager.accountStatus()).thenReturn(accountStatusEvent);
}
 
Example 6
Source File: AppViewManagerTest.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Before public void setupAppViewManagerTest() {
  MockitoAnnotations.initMocks(this);
  downloadStateParser = new DownloadStateParser();
  AppRating appRating = new AppRating(1, 1, Collections.emptyList());
  appViewManager =
      new AppViewManager(appViewModelManager, installManager, downloadFactory, appCenter,
          reviewsManager, adsManager, flagManager, storeUtilsProxy, aptoideAccountManager,
          moPubAdsManager, downloadStateParser, appViewAnalytics, notificationAnalytics,
          installAnalytics, limit, Schedulers.immediate(), "anyString", appCoinsManager,
          promotionsManager, migrationManager, localNotificationSyncManager,
          appcPromotionNotificationStringProvider);
}
 
Example 7
Source File: MoreBundlePresenterTest.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Before public void setupHomePresenter() {
  MockitoAnnotations.initMocks(this);

  lifecycleEvent = PublishSubject.create();
  appClickEvent = PublishSubject.create();
  adClickEvent = PublishSubject.create();
  moreClickEvent = PublishSubject.create();
  bottomReachedEvent = PublishSubject.create();
  pullToRefreshEvent = PublishSubject.create();
  retryClickedEvent = PublishSubject.create();
  bundleScrolledEvent = PublishSubject.create();
  bundleEvent = new BundleEvent("title", "action");

  presenter =
      new MoreBundlePresenter(view, moreBundleManager, Schedulers.immediate(), crashReporter,
          homeNavigator, new AdMapper(), bundleEvent, homeAnalytics, chipManager);
  aptoide =
      new Application("Aptoide", "http://via.placeholder.com/350x150", 0, 1000, "cm.aptoide.pt",
          300, "", false);
  FakeBundleDataSource fakeBundleDataSource = new FakeBundleDataSource();
  bundlesModel = new HomeBundlesModel(fakeBundleDataSource.getFakeBundles(), false, 0, true);
  localTopAppsBundle = bundlesModel.getList()
      .get(0);

  when(view.getLifecycleEvent()).thenReturn(lifecycleEvent);
  when(view.appClicked()).thenReturn(appClickEvent);
  when(view.adClicked()).thenReturn(adClickEvent);
  when(view.moreClicked()).thenReturn(moreClickEvent);
  when(view.reachesBottom()).thenReturn(bottomReachedEvent);
  when(view.refreshes()).thenReturn(pullToRefreshEvent);
  when(view.retryClicked()).thenReturn(retryClickedEvent);
  when(view.bundleScrolled()).thenReturn(bundleScrolledEvent);
}
 
Example 8
Source File: AppViewManagerTest.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Test public void loadAdsFromAppViewTest() {
  List<String> bdsFlags = new ArrayList<>();
  Malware malware = new Malware();
  malware.setRank(Malware.Rank.CRITICAL);
  //Cache App (Test preparation)
  AppModel appModel =
      new AppModel(11, "aptoide", new cm.aptoide.pt.dataprovider.model.v7.store.Store(), "", true,
          malware, new AppFlags("", Collections.emptyList()), Collections.<String>emptyList(),
          Collections.<String>emptyList(), Collections.<String>emptyList(), 121312312,
          "md5dajskdjas", "mypath", "myAltPath", 12311, "9.0.0", "cm.aptoide.pt", 12311,
          100210312, new AppRating(0, 100, Collections.emptyList()), 1231231,
          new AppRating(0, 100, Collections.emptyList()),
          new AppDeveloper("Felipao", "[email protected]", "privacy", "website"), "graphic",
          "icon", new AppMedia("description", Collections.<String>emptyList(), "news",
          Collections.emptyList(), Collections.emptyList()), "modified", "app added", null,
          "weburls", true, "aptoide", AppViewFragment.OpenType.OPEN_ONLY, 0, null,
          "editorsChoice", "origin", false, "marketName", false, false, bdsFlags, "", "", false,
          null, null);

  MinimalAd minimalAd =
      new MinimalAd("anyString", (long) 1, "", "", "", (long) 1, (long) 1, "", "", "", "", 1, 1,
          (long) 1, false, -1, -1, "", "");

  appViewManager =
      new AppViewManager(appViewModelManager, installManager, downloadFactory, appCenter,
          reviewsManager, adsManager, flagManager, storeUtilsProxy, aptoideAccountManager,
          moPubAdsManager, downloadStateParser, appViewAnalytics, notificationAnalytics,
          installAnalytics, limit, Schedulers.immediate(), "anyString", appCoinsManager,
          promotionsManager, migrationManager, localNotificationSyncManager,
          appcPromotionNotificationStringProvider);

  when(appViewModelManager.getAppModel()).thenReturn(Single.just(appModel));
  //Test loadAdsFromAppView
  //When the presenters asks for an Ad
  when(adsManager.loadAds("cm.aptoide.pt", null)).thenReturn(Single.just(minimalAd));

  //Then the Ad from the SearchAdResult should be the same as the one in the request
  appViewManager.loadAdsFromAppView()
      .map(SearchAdResult::getAdId)
      .test()
      .assertValue(minimalAd.getAdId());

  //And it should request the adsManager an Ad
  verify(adsManager).loadAds("cm.aptoide.pt", null);
}
 
Example 9
Source File: AppViewManagerTest.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Test public void downloadAppTest() {
  List<String> bdsFlags = new ArrayList<>();
  Malware malware = new Malware();
  malware.setRank(Malware.Rank.CRITICAL);
  //Cache App (Test preparation)
  AppModel appModel =
      new AppModel(11, "aptoide", new cm.aptoide.pt.dataprovider.model.v7.store.Store(), "", true,
          malware, new AppFlags("", Collections.emptyList()), Collections.<String>emptyList(),
          Collections.<String>emptyList(), Collections.<String>emptyList(), 121312312,
          "md5dajskdjas", "mypath", "myAltPath", 12311, "9.0.0", "cm.aptoide.pt", 12311,
          100210312, new AppRating(0, 100, Collections.emptyList()), 1231231,
          new AppRating(0, 100, Collections.emptyList()),
          new AppDeveloper("Felipao", "[email protected]", "privacy", "website"), "graphic",
          "icon", new AppMedia("description", Collections.<String>emptyList(), "news",
          Collections.emptyList(), Collections.emptyList()), "modified", "app added", null,
          "weburls", true, "aptoide", AppViewFragment.OpenType.OPEN_ONLY, 0, null,
          "editorsChoice", "origin", false, "marketName", false, false, bdsFlags, "", "", false,
          null, null);

  appViewManager =
      new AppViewManager(appViewModelManager, installManager, downloadFactory, appCenter,
          reviewsManager, adsManager, flagManager, storeUtilsProxy, aptoideAccountManager,
          moPubAdsManager, downloadStateParser, appViewAnalytics, notificationAnalytics,
          installAnalytics, limit, Schedulers.immediate(), "anyString", appCoinsManager,
          promotionsManager, migrationManager, localNotificationSyncManager,
          appcPromotionNotificationStringProvider);

  when(appViewModelManager.getAppModel()).thenReturn(Single.just(appModel));

  when(moPubAdsManager.shouldShowAds()).thenReturn(Single.just(true));
  when(moPubAdsManager.getAdsVisibilityStatus()).thenReturn(
      Single.just(WalletAdsOfferManager.OfferResponseStatus.ADS_SHOW));

  appViewManager.getAppModel()
      .subscribe();

  //DownloadApp Test

  //When the presenter asks to download an App
  int action = downloadStateParser.parseDownloadAction(DownloadModel.Action.INSTALL);
  when(downloadFactory.create(action, appModel.getAppName(), appModel.getPackageName(),
      appModel.getMd5(), appModel.getIcon(), appModel.getVersionName(), appModel.getVersionCode(),
      appModel.getPath(), appModel.getPathAlt(), appModel.getObb(), false, appModel.getSize(),
      null, null, appModel.getMalware()
          .getRank()
          .toString(), appModel.getStore()
          .getName())).thenReturn(download);
  when(installManager.install(download)).thenReturn(Completable.complete());
  when(notificationAnalytics.getCampaignId("packageName", (long) 1)).thenReturn(2);
  when(notificationAnalytics.getAbTestingGroup("packageName", (long) 1)).thenReturn("aString");
  when(download.getPackageName()).thenReturn("packageName");
  when(download.getVersionCode()).thenReturn(1);
  when(download.getAction()).thenReturn(3);
  when(download.getStoreName()).thenReturn("storeName");

  //Then the AppViewManager should return a Complete when the download starts
  appViewManager.downloadApp(DownloadModel.Action.INSTALL, 2, "", "aString",
      WalletAdsOfferManager.OfferResponseStatus.ADS_HIDE, false)
      .test()
      .assertCompleted();

  //And it should ask the installManager to start the download
  verify(installManager).install(download);
  //And it should set the necessary analytics
  verify(appViewAnalytics).setupDownloadEvents(download, 0, null, DownloadModel.Action.INSTALL,
      AnalyticsManager.Action.CLICK, "", "aString",
      WalletAdsOfferManager.OfferResponseStatus.ADS_HIDE, "storeName", false);
  verify(installAnalytics).installStarted("packageName", 1, AnalyticsManager.Action.INSTALL,
      AppContext.APPVIEW, downloadStateParser.getOrigin(download.getAction()), 0, null, false,
      false, false, "ADS_HIDE", "", "storeName", false);
}
 
Example 10
Source File: EditorialListPresenterTest.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Before public void setupHomePresenter() {
  MockitoAnnotations.initMocks(this);

  lifecycleEvent = PublishSubject.create();
  bottomReachedEvent = PublishSubject.create();
  retryClickedEvent = PublishSubject.create();
  accountStatusEvent = PublishSubject.create();
  imageClickEvent = PublishSubject.create();
  cardClickEvent = PublishSubject.create();
  impressionEvent = PublishSubject.create();
  refreshEvent = PublishSubject.create();
  reactionButtonClickEvent = PublishSubject.create();
  reactionButtonLongPressEvent = PublishSubject.create();
  reactionClickEvent = PublishSubject.create();
  snackLoginEvent = PublishSubject.create();

  presenter = new EditorialListPresenter(view, editorialListManager, accountManager,
      editorialListNavigator, editorialListAnalytics, crashReporter, Schedulers.immediate(),
      userFeedbackAnalytics);
  CurationCard curationCard =
      new CurationCard("1", "sub", "icon", "title", "1000", GROUP_ID, "2018-11-29 17:14:56", "");
  List<CurationCard> curationCardList = Collections.singletonList(curationCard);
  successEditorialViewModel = new EditorialListViewModel(curationCardList, 0, 0);
  loadingEditorialViewModel = new EditorialListViewModel(true);
  genericErrorEditorialViewModel =
      new EditorialListViewModel(EditorialListViewModel.Error.GENERIC);
  networkErrorEditorialViewModel =
      new EditorialListViewModel(EditorialListViewModel.Error.NETWORK);

  when(view.getLifecycleEvent()).thenReturn(lifecycleEvent);
  when(view.reachesBottom()).thenReturn(bottomReachedEvent);
  when(view.retryClicked()).thenReturn(retryClickedEvent);
  when(view.editorialCardClicked()).thenReturn(cardClickEvent);
  when(accountManager.accountStatus()).thenReturn(accountStatusEvent);
  when(view.imageClick()).thenReturn(imageClickEvent);
  when(view.refreshes()).thenReturn(refreshEvent);
  when(view.visibleCards()).thenReturn(impressionEvent);
  when(view.reactionsButtonClicked()).thenReturn(reactionButtonClickEvent);
  when(view.reactionButtonLongPress()).thenReturn(reactionButtonLongPressEvent);
  when(view.reactionClicked()).thenReturn(reactionClickEvent);
  when(view.snackLogInClick()).thenReturn(snackLoginEvent);
}
 
Example 11
Source File: RxSchedulersOverrideRule.java    From ribot-app-android with Apache License 2.0 4 votes vote down vote up
@Override
public Scheduler getIOScheduler() {
    return Schedulers.immediate();
}
 
Example 12
Source File: RxSchedulersOverrideRule.java    From FriendlyDemo with Apache License 2.0 4 votes vote down vote up
@Override
public Scheduler getNewThreadScheduler() {
    return Schedulers.immediate();
}
 
Example 13
Source File: RxJavaResetRule.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public Scheduler getComputationScheduler() {
    return Schedulers.immediate();
}
 
Example 14
Source File: RxJavaResetRule.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public Scheduler getNewThreadScheduler() {
    return Schedulers.immediate();
}
 
Example 15
Source File: TestActivityModule.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @Named(DataModule.IO_THREAD)
public Scheduler provideIoThreadScheduler() {
    return Schedulers.immediate();
}
 
Example 16
Source File: RxSchedulersTestRule.java    From AndroidSchool with Apache License 2.0 4 votes vote down vote up
@Override
public Scheduler call(Scheduler scheduler) {
    return Schedulers.immediate();
}
 
Example 17
Source File: DefaultAppScaleManagerTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void checkV3LiveStreamTargetUpdates() throws Exception {
    String jobIdOne = UUID.randomUUID().toString();
    String jobIdTwo = UUID.randomUUID().toString();

    InMemoryPolicyStore policyStore = new InMemoryPolicyStore();
    V3JobOperations v3JobOperations = mockV3Operations(jobIdOne, jobIdTwo);
    AppScaleClientWithScalingPolicyConstraints appScalingClient = new AppScaleClientWithScalingPolicyConstraints();
    DefaultAppScaleManager appScaleManager = new DefaultAppScaleManager(policyStore,
            new AutoScalingPolicyTests.MockAlarmClient(),
            appScalingClient,
            v3JobOperations,
            new DefaultRegistry(),
            AutoScalingPolicyTests.mockAppScaleManagerConfiguration(),
            Schedulers.immediate(),
            mock(TitusRuntime.class));

    List<String> refIds = submitTwoJobs(appScaleManager, jobIdOne, jobIdTwo, policyStore);
    Assertions.assertThat(refIds.size()).isEqualTo(2);

    CountDownLatch latch = new CountDownLatch(1);
    Observable<String> jobIdTargetUpdates = appScaleManager.v3LiveStreamTargetUpdates();

    List<String> targetsUpdated = new ArrayList<>();
    jobIdTargetUpdates.subscribe(targetUpdated -> {
                log.info("Got ScalableTarget to be updated {}", targetUpdated);
                Assertions.assertThat(targetUpdated).isEqualTo(jobIdTwo);
                targetsUpdated.add(targetUpdated);
                latch.countDown();
            },
            e -> log.error("Error in v2 live stream for scalable target update", e),
            () -> log.info("Completed"));

    latch.await(60, TimeUnit.SECONDS);

    AutoScalingPolicyTests.waitForCondition(() -> {
        JobScalingConstraints jpc = appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo);
        return jpc != null && jpc.getMinCapacity() == 5 && jpc.getMaxCapacity() == 15;
    });

    Assertions.assertThat(targetsUpdated.size()).isEqualTo(1);
    Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdOne).getMinCapacity()).isEqualTo(1);
    Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdOne).getMaxCapacity()).isEqualTo(10);
    Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo).getMinCapacity()).isEqualTo(5);
    Assertions.assertThat(appScalingClient.getJobScalingPolicyConstraintsForJob(jobIdTwo).getMaxCapacity()).isEqualTo(15);
}
 
Example 18
Source File: ModelTestModule.java    From android-step-by-step with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
@Named(Const.UI_THREAD)
Scheduler provideSchedulerUI() {
    return Schedulers.immediate();
}
 
Example 19
Source File: RxSchedulersOverrideRule.java    From programming with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Scheduler getIOScheduler(){
    return Schedulers.immediate();
}
 
Example 20
Source File: TestActivityModule.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton @Named(DataModule.MAIN_THREAD)
public Scheduler provideMainThreadScheduler() {
    return Schedulers.immediate();
}