Search in sources :

Example 1 with Bus

use of com.squareup.otto.Bus in project otto by square.

the class AnnotatedProducerFinderTest method multipleSubscriptionsCallsProviderEachTime.

@Test
public void multipleSubscriptionsCallsProviderEachTime() {
    Bus bus = new Bus(ThreadEnforcer.ANY);
    SimpleProducer producer = new SimpleProducer();
    bus.register(producer);
    bus.register(new Subscriber());
    assertThat(producer.produceCalled).isEqualTo(1);
    bus.register(new Subscriber());
    assertThat(producer.produceCalled).isEqualTo(2);
}
Also used : Bus(com.squareup.otto.Bus) Test(org.junit.Test)

Example 2 with Bus

use of com.squareup.otto.Bus in project nmid-headline by miao1007.

the class GlobalContext method onCreate.

@Override
public void onCreate() {
    FIR.init(this);
    super.onCreate();
    globalContext = this;
    bus = new Bus(ThreadEnforcer.MAIN);
    isDebug = DebugPref.isDebug(this);
    //start JPush service
    if (PushPref.isPushFeeds(this)) {
        JPushInterface.init(this);
        JPushInterface.setDebugMode(isDebug);
    }
    //sharesdk
    ShareSDK.initSDK(this);
    // Here you start using the ActiveAndroid library.
    ActiveAndroid.initialize(this);
}
Also used : Bus(com.squareup.otto.Bus)

Example 3 with Bus

use of com.squareup.otto.Bus in project scdl by passy.

the class BuyAdFreeActivityTest method shouldPropagateInventoryQuery.

@Test
public void shouldPropagateInventoryQuery() throws JSONException {
    final BuyAdFreeActivity activity = Robolectric.buildActivity(BuyAdFreeActivity.class).create().get();
    final IabResult result = new IabResult(IabHelper.BILLING_RESPONSE_RESULT_OK, "");
    final HashMap<String, Purchase> purchases = new HashMap<>();
    purchases.put(BuyAdFreeActivity.ADFREE_SKU, new AdfreePurchase());
    Inventory inv = new MyInventory(new HashMap<String, SkuDetails>(), purchases);
    PurchaseChangeSubscriber subscriber = new PurchaseChangeSubscriber();
    Bus bus = TestHelper.getInjector().getInstance(Bus.class);
    bus.register(subscriber);
    activity.onQueryInventoryFinished(result, inv);
    assertThat(subscriber.purchased, is(PaymentStatus.BOUGHT));
}
Also used : SkuDetails(com.android.vending.billing.SkuDetails) Bus(com.squareup.otto.Bus) Purchase(com.android.vending.billing.Purchase) HashMap(java.util.HashMap) IabResult(com.android.vending.billing.IabResult) BuyAdFreeActivity(net.rdrei.android.scdl2.ui.BuyAdFreeActivity) Inventory(com.android.vending.billing.Inventory) Test(org.junit.Test)

Example 4 with Bus

use of com.squareup.otto.Bus in project otto by square.

the class AnnotatedProducerFinderTest method simpleProducer.

@Test
public void simpleProducer() {
    Bus bus = new Bus(ThreadEnforcer.ANY);
    Subscriber subscriber = new Subscriber();
    SimpleProducer producer = new SimpleProducer();
    bus.register(producer);
    assertThat(producer.produceCalled).isEqualTo(0);
    bus.register(subscriber);
    assertThat(producer.produceCalled).isEqualTo(1);
    assertEquals(Arrays.asList(SimpleProducer.VALUE), subscriber.events);
}
Also used : Bus(com.squareup.otto.Bus) Test(org.junit.Test)

Example 5 with Bus

use of com.squareup.otto.Bus in project otto by square.

the class OutsideEventBusTest method anonymous.

/*
   * If you do this test from common.eventbus.BusTest, it doesn't actually test the behavior.
   * That is, even if exactly the same method works from inside the common.eventbus package tests,
   * it can fail here.
   */
@Test
public void anonymous() {
    final AtomicReference<String> holder = new AtomicReference<String>();
    final AtomicInteger deliveries = new AtomicInteger();
    Bus bus = new Bus(ThreadEnforcer.ANY);
    bus.register(new Object() {

        @Subscribe
        public void accept(String str) {
            holder.set(str);
            deliveries.incrementAndGet();
        }
    });
    String EVENT = "Hello!";
    bus.post(EVENT);
    assertEquals("Only one event should be delivered.", 1, deliveries.get());
    assertEquals("Correct string should be delivered.", EVENT, holder.get());
}
Also used : Bus(com.squareup.otto.Bus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscribe(com.squareup.otto.Subscribe) Test(org.junit.Test)

Aggregations

Bus (com.squareup.otto.Bus)6 Test (org.junit.Test)4 IabResult (com.android.vending.billing.IabResult)1 Inventory (com.android.vending.billing.Inventory)1 Purchase (com.android.vending.billing.Purchase)1 SkuDetails (com.android.vending.billing.SkuDetails)1 Subscribe (com.squareup.otto.Subscribe)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BuyAdFreeActivity (net.rdrei.android.scdl2.ui.BuyAdFreeActivity)1