This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| some_view.setOnClickListener(object : View.OnClickListener { | |
| override fun onClick(view: View) { | |
| println("clicked!") | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val parent = node.getParent() ?: return null | |
| val name = node.getName() ?: throw IllegalArgumentException("...") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (x is String){ | |
| println(x) | |
| } | |
| // can be replaced with | |
| (x as? String)?.let { println(x) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| school?.students?.let { doSomething(it.get(“billy”)) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val school : School = null | |
| if (school != null && school.students != null){ | |
| doSomething(school.students.get(“billy”)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package rx.plugins; | |
| public class RxJavaTestPlugins extends RxJavaPlugins { | |
| RxJavaTestPlugins() { | |
| super(); | |
| } | |
| public static void resetPlugins(){ | |
| getInstance().reset(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestApplication extends BaseApplication implements TestLifecycleApplication { | |
| @Override | |
| public void onCreate() { | |
| setupRxSchedulers(); | |
| super.onCreate(); | |
| } | |
| private void setupRxSchedulers() { | |
| RxJavaTestPlugins.resetPlugins(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testUsingTestSchedulers() throws Exception { | |
| TestScheduler scheduler = new TestScheduler(); | |
| TestSubscriber<Long> testSubscriber = new TestSubscriber<>(); | |
| Observable.interval(1, TimeUnit.SECONDS, scheduler).take(5).observeOn(scheduler).subscribeOn(scheduler).subscribe(testSubscriber); | |
| testSubscriber.assertNoValues(); | |
| scheduler.advanceTimeBy(2, TimeUnit.SECONDS); | |
| testSubscriber.assertReceivedOnNext(Arrays.asList(0L, 1L)); | |
| scheduler.advanceTimeBy(10, TimeUnit.SECONDS); | |
| testSubscriber.assertCompleted(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void testUsingTestSubscriber() throws Exception { | |
| TestSubscriber<Integer> testSubscriber = new TestSubscriber<>(); | |
| Observable.just(1).subscribe(testSubscriber); | |
| testSubscriber.assertNoErrors(); | |
| testSubscriber.assertReceivedOnNext(Arrays.asList(1)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| List<T> myList = myObservable.toList().toBlocking().single() | |
| assertThat(myList.isEmpty()).is(false) |