Java Code Examples for android.support.test.annotation.UiThreadTest

The following are top voted examples for showing how to use android.support.test.annotation.UiThreadTest. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: EventBusBasicTest.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void testRegisterAndPost() {
    // Use an activity to test real life performance
    TestActivity testActivity = new TestActivity();
    String event = "Hello";

    long start = System.currentTimeMillis();
    eventBus.register(testActivity);
    long time = System.currentTimeMillis() - start;
    Log.d(EventBus.TAG, "Registered in " + time + "ms");

    eventBus.post(event);

    assertEquals(event, testActivity.lastStringEvent);
}
 
Example 2
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void realmObject_emitChangesetOnSubscribe() {
    realm.beginTransaction();
    final AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();

    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = obj.asChangesetObservable().subscribe(new Consumer<ObjectChange<RealmObject>>() {
        @Override
        public void accept(ObjectChange<RealmObject> change) throws Exception {
            assertTrue(change.getObject() == obj);
            assertNull(change.getChangeset());
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.dispose();
}
 
Example 3
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void dynamicRealmObject_emitChangesetOnSubscribe() {
    DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    dynamicRealm.beginTransaction();
    final DynamicRealmObject obj = dynamicRealm.createObject(AllTypes.CLASS_NAME);
    dynamicRealm.commitTransaction();

    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = obj.asChangesetObservable().subscribe(new Consumer<ObjectChange<RealmObject>>() {
        @Override
        public void accept(ObjectChange<RealmObject> change) throws Exception {
            assertTrue(change.getObject() == obj);
            assertNull(change.getChangeset());
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.dispose();
    dynamicRealm.close();
}
 
Example 4
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void realmResults_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
    subscription = results.asFlowable().subscribe(new Consumer<RealmResults<AllTypes>>() {
        @Override
        @SuppressWarnings("ReferenceEquality")
        public void accept(RealmResults<AllTypes> rxResults) throws Exception {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.dispose();
}
 
Example 5
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void realmList_emittedChangesetOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    realm.beginTransaction();
    final RealmList<Dog> list = realm.createObject(AllTypes.class).getColumnRealmList();
    realm.commitTransaction();
    subscription = list.asChangesetObservable().subscribe(new Consumer<CollectionChange<RealmList<Dog>>>() {
        @Override
        public void accept(CollectionChange<RealmList<Dog>> change) throws Exception {
            assertEquals(list, change.getCollection());
            assertNull(change.getChangeset());
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.dispose();
}
 
Example 6
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void dynamicRealmResults_emittedOnSubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<DynamicRealmObject> results = dynamicRealm.where(AllTypes.CLASS_NAME).findAll();
    subscription = results.asFlowable().subscribe(new Consumer<RealmResults<DynamicRealmObject>>() {
        @Override
        @SuppressWarnings("ReferenceEquality")
        public void accept(RealmResults<DynamicRealmObject> rxResults) throws Exception {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    dynamicRealm.close();
    subscription.dispose();
}
 
Example 7
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void dynamicRealmResults_emittedChangesetOnSubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<DynamicRealmObject> results = dynamicRealm.where(AllTypes.CLASS_NAME).findAll();
    subscription = results.asChangesetObservable().subscribe(new Consumer<CollectionChange<RealmResults<DynamicRealmObject>>>() {
        @Override
        public void accept(CollectionChange<RealmResults<DynamicRealmObject>> change) throws Exception {
            assertEquals(results, change.getCollection());
            assertNull(change.getChangeset());
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    dynamicRealm.close();
    subscription.dispose();
}
 
Example 8
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void findAllAsync_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAllAsync();
    subscription = results.asFlowable().subscribe(new Consumer<RealmResults<AllTypes>>() {
        @Override
        @SuppressWarnings("ReferenceEquality")
        public void accept(RealmResults<AllTypes> rxResults) throws Exception {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.dispose();
}
 
Example 9
Project: RxDataBinding   File: RxObservableArrayListTest.java   Source Code and License 6 votes vote down vote up
@Test @UiThreadTest public void itemRangeInsertionEvents() {
  String value = "value";
  ObservableArrayListItemRangeInsertionEvent<String> next;

  RecordingObserver<ObservableArrayListItemRangeInsertionEvent<String>> o =
      new RecordingObserver<>();
  RxObservableArrayList.itemRangeInsertionEvents(observableArrayList).subscribe(o);
  o.assertNoMoreEvents();

  observableArrayList.add(value);
  next = o.takeNext();
  assertEquals(observableArrayList, next.observableArrayList());
  assertEquals(0, next.positionStart());
  assertEquals(1, next.itemCount());

  observableArrayList.addAll(Arrays.asList(value, value, value));
  next = o.takeNext();
  assertEquals(observableArrayList, next.observableArrayList());
  assertEquals(1, next.positionStart());
  assertEquals(3, next.itemCount());

  o.dispose();

  observableArrayList.add(value);
  o.assertNoMoreEvents();
}
 
Example 10
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void dynamicRealm_emittedOnSubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = dynamicRealm.asFlowable().subscribe(new Consumer<DynamicRealm>() {
        @Override
        public void accept(DynamicRealm rxRealm) throws Exception {
            assertTrue(rxRealm == dynamicRealm);
            subscribedNotified.set(true);
        }
    }, new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            throwable.printStackTrace();
            fail();
        }
    });

    assertTrue(subscribedNotified.get());
    dynamicRealm.close();
    subscription.dispose();
}
 
Example 11
Project: Spyglass   File: TestDimensionHandlerCombinations.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassCallsMethod_attributeMissing_defaultToNullPresent() {
	final AttributeSet attrs = fromXml(context, R.xml.dimension_handler_without_attr);

	final DimensionHandlerTestTargetBase target = new WithDefaultToNull(context, attrs);

	assertThat(target.getReceivedValue(), is(ReceivedValue.<Integer>of(null)));
}
 
Example 12
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void wrongGenericClassThrows() {
    realm.beginTransaction();
    final AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();

    Flowable<CyclicType> obs = obj.asFlowable();
    @SuppressWarnings("unused")
    Disposable subscription = obs.subscribe(new Consumer<CyclicType>() {
        @Override
        public void accept(CyclicType cyclicType) throws Exception {
            fail();
        }
    }, new Consumer<Throwable>() {
        @Override
        public void accept(Throwable ignored) throws Exception {
        }
    });
}
 
Example 13
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void dynamicRealm_closeInDoOnUnsubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());

    Flowable<DynamicRealm> observable = dynamicRealm.asFlowable()
            .doOnCancel(new Action() {
                @Override
                public void run() throws Exception {
                    dynamicRealm.close();
                }
            });

    subscription = observable.subscribe(new Consumer<DynamicRealm>() {
        @Override
        public void accept(DynamicRealm ignored) throws Exception {
        }
    });

    subscription.dispose();
    assertTrue(dynamicRealm.isClosed());
}
 
Example 14
Project: GitHub   File: RxJavaTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void dynamicRealmObject_closeInDoOnUnsubscribe() {
    realm.beginTransaction();
    realm.createObject(AllTypes.class);
    realm.commitTransaction();
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());

    Flowable<DynamicRealmObject> flowable = dynamicRealm.where(AllTypes.CLASS_NAME).findFirst().<DynamicRealmObject>asFlowable()
            .doOnCancel(new Action() {
                @Override
                public void run() throws Exception {
                    dynamicRealm.close();
                }
            });

    subscription = flowable.subscribe(new Consumer<DynamicRealmObject>() {
        @Override
        public void accept(DynamicRealmObject ignored) throws Exception {
        }
    });

    subscription.dispose();
    assertTrue(dynamicRealm.isClosed());
}
 
Example 15
Project: GitHub   File: NotificationsTest.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void removeChangeListener() throws InterruptedException, ExecutionException {
    final AtomicInteger counter = new AtomicInteger(0);
    RealmChangeListener<Realm> listener = new RealmChangeListener<Realm>() {
        @Override
        public void onChange(Realm object) {
            counter.incrementAndGet();
        }
    };

    realm = Realm.getInstance(realmConfig);
    realm.addChangeListener(listener);
    realm.removeChangeListener(listener);

    realm.beginTransaction();
    realm.createObject(AllTypes.class);
    realm.commitTransaction();

    assertEquals(0, counter.get());
}
 
Example 16
Project: GitHub   File: OrderedRealmCollectionIteratorTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void useCase_simpleIterator_modifyQueryResult_innerTransaction_looperThread() {
    if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST,
            CollectionClass.REALMRESULTS)) {
        return;
    }

    assertEquals(TEST_SIZE, collection.size());
    for (int i = 0; i < collection.size(); i++) {
        realm.beginTransaction();
        AllJavaTypes obj = collection.get(i);
        obj.setFieldLong(obj.getFieldLong() + TEST_SIZE);
        realm.commitTransaction();
    }

    // Verifies that all elements were modified.
    assertEquals(0, realm.where(AllJavaTypes.class).lessThan(AllJavaTypes.FIELD_LONG, TEST_SIZE).count());
}
 
Example 17
Project: GitHub   File: OrderedRealmCollectionIteratorTests.java   Source Code and License 6 votes vote down vote up
@Test
@UiThreadTest
public void useCase_simpleIterator_modifyQueryResult_outerTransaction_looperThread() {
    if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST,
            CollectionClass.REALMRESULTS)) {
        return;
    }

    assertEquals(TEST_SIZE, collection.size());
    realm.beginTransaction();
    for (int i = 0; i < collection.size(); i++) {
        AllJavaTypes obj = collection.get(i);
        obj.setFieldLong(obj.getFieldLong() + TEST_SIZE);
    }
    realm.commitTransaction();

    // Verifies that all elements were modified.
    assertEquals(0, realm.where(AllJavaTypes.class).lessThan(AllJavaTypes.FIELD_LONG, TEST_SIZE).count());
}
 
Example 18
Project: RxDataBinding   File: RxObservableShortTest.java   Source Code and License 6 votes vote down vote up
@Test @UiThreadTest public void propertyChangeEvents() {
  short value = -1;

  RecordingObserver<Short> o = new RecordingObserver<>();
  RxObservableShort.propertyChanges(observableShort).subscribe(o);
  o.assertNoMoreEvents();

  observableShort.set(value);
  assertEquals(value, o.takeNext().shortValue());

  value = 2;
  observableShort.set(value);
  assertEquals(value, o.takeNext().shortValue());

  o.dispose();

  value = -3;
  observableShort.set(value);
  o.assertNoMoreEvents();
}
 
Example 19
Project: RxDataBinding   File: RxObservableFieldTest.java   Source Code and License 6 votes vote down vote up
@Test @UiThreadTest public void propertyChangeEvents_Object() {
  final ObservableField<Object> observableField = new ObservableField<>();
  Object value;

  RecordingObserver<Object> o = new RecordingObserver<>();
  RxObservableField.propertyChanges(observableField).subscribe(o);
  o.assertNoMoreEvents();

  value = new Object();
  observableField.set(value);
  assertEquals(value, o.takeNext());

  value = new Object();
  observableField.set(value);
  assertEquals(value, o.takeNext());

  o.dispose();

  value = new Object();
  observableField.set(value);
  o.assertNoMoreEvents();
}
 
Example 20
Project: RxDataBinding   File: RxObservableParcelableTest.java   Source Code and License 6 votes vote down vote up
@Test @UiThreadTest public void propertyChangeEvents() {
  final ObservableParcelable<MyParcelable> observableField = new ObservableParcelable<>();
  MyParcelable value;

  RecordingObserver<MyParcelable> o = new RecordingObserver<>();
  RxObservableParcelable.propertyChanges(observableField).subscribe(o);
  o.assertNoMoreEvents();

  value = new MyParcelable(1, "a");
  observableField.set(value);
  assertEquals(value, o.takeNext());

  value = new MyParcelable(2, "b");
  observableField.set(value);
  assertEquals(value, o.takeNext());

  o.dispose();

  value = new MyParcelable(3, "c");
  observableField.set(value);
  o.assertNoMoreEvents();
}
 
Example 21
Project: meat-grinder   File: MainActivityTest.java   Source Code and License 6 votes vote down vote up
@UiThreadTest
@Test
public void testOnProcessFinishedAndOnUpdateResult() {
    mActivityRule.getActivity().onUpdateResult(null);
    mActivityRule.getActivity().onProcessFinished(null);
    ArrayList<CheckInfo> list = new ArrayList<>();
    TotalResult totalResult = new TotalResult(list, CH_STATE_UNCHECKED);
    activity.onProcessFinished(totalResult);
    totalResult = new TotalResult(list, CH_STATE_CHECKED_ROOT_NOT_DETECTED);
    activity.onProcessFinished(totalResult);
    totalResult = new TotalResult(list, CH_STATE_CHECKED_ERROR);
    activity.onProcessFinished(totalResult);
    totalResult = new TotalResult(list, CH_STATE_STILL_GOING);
    activity.onProcessFinished(totalResult);
    totalResult = new TotalResult(list, CH_STATE_CHECKED_ROOT_DETECTED);
    activity.onProcessFinished(totalResult);
    //noinspection WrongConstant
    totalResult = new TotalResult(list, Integer.MAX_VALUE);
    Exception exception = null;
    try {
        activity.onProcessFinished(totalResult);
    } catch (IllegalStateException e) {
        exception = e;
    }
    Assert.assertNotNull(exception);
}
 
Example 22
Project: RxDataBinding   File: RxObservableFieldTest.java   Source Code and License 6 votes vote down vote up
@Test @UiThreadTest public void propertyChangeEvents_String() {
  final ObservableField<String> observableField = new ObservableField<>();
  String value = "databinding";

  RecordingObserver<String> o = new RecordingObserver<>();
  RxObservableField.propertyChanges(observableField).subscribe(o);
  o.assertNoMoreEvents();

  observableField.set(value);
  assertEquals(value, o.takeNext());

  value += " is cool.";
  observableField.set(value);
  assertEquals(value, o.takeNext());

  o.dispose();

  value += " Yeah?";
  observableField.set(value);
  o.assertNoMoreEvents();
}
 
Example 23
Project: Spyglass   File: TestDimensionHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassPassesCorrectData_attributeMissing_defaultToDimensionPresent_usingDpUnits() {
	final AttributeSet attrs = fromXml(context, R.xml.dimension_handler_without_attr);

	final DimensionHandlerTestTargetBase target = new WithDefaultToDpDimension(context, attrs);

	final int expectedValue = (int) DimensionHelper.dpToPx(context, WithDefaultToDpDimension.DEFAULT_VALUE_DP);
	assertThat(target.getReceivedValue(), is(ReceivedValue.of(expectedValue)));
}
 
Example 24
Project: Spyglass   File: TestDimensionHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassPassesCorrectData_attributeMissing_defaultToDimensionResourcePresent_usingInUnits() {
	final AttributeSet attrs = fromXml(context, R.xml.dimension_handler_without_attr);

	final DimensionHandlerTestTargetBase target = new WithDefaultToInDimensionResource(context, attrs);

	final int expectedValue = (int) context.getResources().getDimension(R.dimen.DimensionForTestingIn);
	assertThat(target.getReceivedValue(), is(ReceivedValue.of(expectedValue)));
}
 
Example 25
Project: Spyglass   File: TestSpecificBooleanHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassNeverCallsMethod_attributeMissing() {
	final AttributeSet attrs = AttributeSetSupplier.fromXml(
			context,
			R.xml.specific_boolean_handler_without_attr);

	final SpecificBooleanHandlerTestTarget target = new SpecificBooleanHandlerTestTarget(context, attrs);

	assertThat(target.wasHandlerCalled(), is(false));
}
 
Example 26
Project: Spyglass   File: TestDimensionHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassPassesCorrectData_attributeMissing_defaultToDimensionResourcePresent_usingPtUnits() {
	final AttributeSet attrs = fromXml(context, R.xml.dimension_handler_without_attr);

	final DimensionHandlerTestTargetBase target = new WithDefaultToPtDimensionResource(context, attrs);

	final int expectedValue = (int) context.getResources().getDimension(R.dimen.DimensionForTestingPt);
	assertThat(target.getReceivedValue(), is(ReceivedValue.of(expectedValue)));
}
 
Example 27
Project: Spyglass   File: TestSpecificBooleanHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassCallsMethod_attributePresent_matchesSpecificBoolean() {
	final AttributeSet attrs = AttributeSetSupplier.fromXml(
			context,
			R.xml.specific_boolean_handler_with_attr_equals_true);

	final SpecificBooleanHandlerTestTarget target = new SpecificBooleanHandlerTestTarget(context, attrs);

	assertThat(target.wasHandlerCalled(), is(true));
}
 
Example 28
Project: Spyglass   File: TestIntegerHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassCallsMethod_attributeMissing_defaultToNullPresent() {
	final AttributeSet attrs = AttributeSetSupplier.fromXml(context, R.xml.integer_handler_withoutt_attr);

	final IntegerHandlerTestTargetBase target = new WithDefaultToNull(context, attrs);

	assertThat(target.getReceivedValue(), is(ReceivedValue.<Integer>of(null)));
}
 
Example 29
Project: GitHub   File: RxJavaTests.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void realmResults_emittedChangesetOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
    subscription = results.asChangesetObservable().subscribe(new Consumer<CollectionChange<RealmResults<AllTypes>>>() {
        @Override
        public void accept(CollectionChange<RealmResults<AllTypes>> change) throws Exception {
            assertEquals(results, change.getCollection());
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.dispose();
}
 
Example 30
Project: meat-grinder   File: MainActivityTest.java   Source Code and License 5 votes vote down vote up
@UiThreadTest
@Test
public void testOnOptionsItemSelected() {
    @SuppressWarnings("RestrictedApi")
    MenuBuilder bld = new MenuBuilder(activity);
    @SuppressWarnings("RestrictedApi")
    MenuItem item = bld.add("test");
    activity.onOptionsItemSelected(item);
}
 
Example 31
Project: GitHub   File: RxJavaTests.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void unsubscribe_sameThread() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = realm.asFlowable().subscribe(new Consumer<Realm>() {
        @Override
        public void accept(Realm rxRealm) throws Exception {
            assertTrue(rxRealm == realm);
            subscribedNotified.set(true);
        }
    });
    assertEquals(1, realm.sharedRealm.realmNotifier.getListenersListSize());
    subscription.dispose();
    assertEquals(0, realm.sharedRealm.realmNotifier.getListenersListSize());
}
 
Example 32
Project: Spyglass   File: TestEnumOrdinalHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassPassesCorrectData_attributePresent_attributeEqualsC() {
	final AttributeSet attrs = fromXml(context, R.xml.enum_ordinal_handler_with_attr_equals_c);

	final EnumOrdinalHandlerTestTargetBase target = new WithoutDefault(context, attrs);

	assertThat(target.getReceivedValue(), is(ReceivedValue.of(1)));
}
 
Example 33
Project: Spyglass   File: TestEnumOrdinalHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassPassesCorrectData_attributeMissing_defaultToIntegerResourcePresent() {
	final AttributeSet attrs = fromXml(context, R.xml.enum_ordinal_handler_without_attr);

	final EnumOrdinalHandlerTestTargetBase target = new WithDefaultToIntegerResource(context, attrs);

	final int expectedValue = context.getResources().getInteger(R.integer.IntegerForTesting);
	assertThat(target.getReceivedValue(), is(ReceivedValue.of(expectedValue)));
}
 
Example 34
Project: Spyglass   File: TestSpecificBooleanHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassNeverCallsMethod_attributePresent_doesNotMatchSpecificBoolean() {
	final AttributeSet attrs = AttributeSetSupplier.fromXml(
			context,
			R.xml.specific_boolean_handler_with_attr_equals_false);

	final SpecificBooleanHandlerTestTarget target = new SpecificBooleanHandlerTestTarget(context, attrs);

	assertThat(target.wasHandlerCalled(), is(false));
}
 
Example 35
Project: meat-grinder   File: MainActivityTest.java   Source Code and License 5 votes vote down vote up
@UiThreadTest
@Test
public void testResultItemHolder() {
    ResultItemHolder holder = new ResultItemHolder(
            LayoutInflater.from(activity).inflate(R.layout.item_check, null, false));


    ResultAdapter adapter = (ResultAdapter) ((RecyclerView) activity.findViewById(R.id.list)).getAdapter();
    int position = adapter.getItemCount()-1;
    CheckInfo item =  adapter.getItem(position);
    holder.onBind(item, position);
    holder.onBind(item, position);

}
 
Example 36
Project: Spyglass   File: TestDimensionHandlerCombinations.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSpyglassPassesCorrectData_attributePresent_attributeEquals10pt() {
	final AttributeSet attrs = fromXml(context, R.xml.dimension_handler_with_attr_equals_10pt);

	final DimensionHandlerTestTargetBase target = new WithoutDefault(context, attrs);

	final int expectedValue = (int) DimensionHelper.ptToPx(context, 10);
	assertThat(target.getReceivedValue(), is(ReceivedValue.of(expectedValue)));
}
 
Example 37
Project: GitHub   File: SessionTests.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void uploadAllLocalChanges_throwsOnUiThread() throws InterruptedException {
    Realm realm = Realm.getInstance(configuration);
    try {
        SyncManager.getSession(configuration).uploadAllLocalChanges();
        fail("Should throw an IllegalStateException on Ui Thread");
    } catch (IllegalStateException ignored) {
    } finally {
        realm.close();
    }
}
 
Example 38
Project: GitHub   File: SessionTests.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void downloadAllServerChanges_throwsOnUiThread() throws InterruptedException {
    Realm realm = Realm.getInstance(configuration);
    try {
        SyncManager.getSession(configuration).downloadAllServerChanges();
        fail("Should throw an IllegalStateException on Ui Thread");
    } catch (IllegalStateException ignored) {
    } finally {
        realm.close();
    }
}
 
Example 39
Project: Spyglass   File: TestInheritanceBehaviour.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSuperclassInstantiationTriggersSuperclassSpyglass() {
	final Superclass s = new Superclass(context);

	assertThat(s.getSuperclassReceivedValue(), is(ReceivedValue.of(Superclass.EXPECTED_VALUE)));
}
 
Example 40
Project: Spyglass   File: TestInheritanceBehaviour.java   Source Code and License 5 votes vote down vote up
@Test
@UiThreadTest
public void testSubclassInstantiationTriggersSuperclassSpyglass() {
	final Subclass s = new Subclass(context);

	assertThat(s.getSuperclassReceivedValue(), is(ReceivedValue.of(Superclass.EXPECTED_VALUE)));
}