This repository was archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 412
Add Query to the cause of exception in QueryObservable #48
Merged
JakeWharton
merged 1 commit into
square:master
from
artem-zinnatullin:queryobservable-add-query-to-exception
Aug 31, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
sqlbrite/src/androidTest/java/com/squareup/sqlbrite/QueryObservableTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.squareup.sqlbrite; | ||
|
|
||
| import android.database.Cursor; | ||
| import android.database.MatrixCursor; | ||
| import android.support.test.runner.AndroidJUnit4; | ||
|
|
||
| import com.squareup.sqlbrite.SqlBrite.Query; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import rx.Observable; | ||
| import rx.functions.Func1; | ||
| import rx.observers.TestSubscriber; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
|
|
||
| @RunWith(AndroidJUnit4.class) | ||
| public final class QueryObservableTest { | ||
|
|
||
| @Test public void mapToListThrowsFromQueryRun() { | ||
| TestSubscriber<Object> testSubscriber = new TestSubscriber<>(); | ||
|
|
||
| new QueryObservable(Observable.<Query>just(new Query() { | ||
| @Override public Cursor run() { | ||
| throw new IllegalStateException("test exception"); | ||
| } | ||
| })).mapToList(new Func1<Cursor, Object>() { | ||
| @Override public Object call(Cursor cursor) { | ||
| throw new AssertionError("Must not be called"); | ||
| } | ||
| }).subscribe(testSubscriber); | ||
|
|
||
| testSubscriber.awaitTerminalEvent(); | ||
| testSubscriber.assertNoValues(); | ||
| assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); | ||
|
|
||
| IllegalStateException expected = (IllegalStateException) testSubscriber.getOnErrorEvents().get(0); | ||
| assertThat(expected).hasMessage("test exception"); | ||
| } | ||
|
|
||
| @Test public void mapToListThrowsFromMapFunction() { | ||
| TestSubscriber<Object> testSubscriber = new TestSubscriber<>(); | ||
|
|
||
| new QueryObservable(Observable.<Query>just(new Query() { | ||
| @Override public Cursor run() { | ||
| MatrixCursor cursor = new MatrixCursor(new String[]{"col1"}); | ||
| cursor.addRow(new Object[]{"value1"}); | ||
| return cursor; | ||
| } | ||
| })).mapToList(new Func1<Cursor, Object>() { | ||
| @Override public Object call(Cursor cursor) { | ||
| throw new IllegalStateException("test exception"); | ||
| } | ||
| }).subscribe(testSubscriber); | ||
|
|
||
| testSubscriber.awaitTerminalEvent(); | ||
| testSubscriber.assertNoValues(); | ||
| assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); | ||
|
|
||
| IllegalStateException expected = (IllegalStateException) testSubscriber.getOnErrorEvents().get(0); | ||
| assertThat(expected).hasMessage("test exception"); | ||
| } | ||
| } |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add a test which will check that
query.toString()is part of the stacktrace, but it'll require copy-paste from apache commons or I can add it as test dependency, because retrieving full stacktrace is not so trivial.